java Javax.jws 和 javax.xml.ws 有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16212246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is difference Javax.jws and javax.xml.ws
提问by Relational and Re-engineering
I am new to Java and trying to jump into WebServices. I found two examples somewhere and I am confused with the available options.
我是 Java 新手,正在尝试使用 WebServices。我在某处找到了两个示例,但对可用选项感到困惑。
Firstly, javax.jws.WebService
with annotation seem to work fine, but there is loads of material on javax.xml.ws
. It seems javax.jws
is newer and there is not much material available about it.
首先,javax.jws.WebService
带注释似乎工作正常,但javax.xml.ws
. 它似乎javax.jws
较新,并且可用的材料不多。
What is the difference between these two approaches?
这两种方法有什么区别?
回答by Paul Vargas
Web Services Metadata Annotations (JSR 181)
Web 服务元数据注释 (JSR 181)
Using annotations from the JSR 181 specification (java.jws.xxx
), you can annotate a Web service implementation class or a Web service interface.
使用 JSR 181 规范 ( ) 中的注释,您可以注释 Web 服务实现类或 Web 服务接口。java.jws.xxx
e.g. from Deploy JAX-WS Web Services On Tomcat
例如来自在 Tomcat 上部署 JAX-WS Web 服务
package com.mkyong.ws;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloWorld{
@WebMethod String getHelloWorldAsString();
}
JAX-WS 2.0 Annotations (JSR 224)
JAX-WS 2.0 注释 (JSR 224)
The JSR 224 specification defines annotations for JAX-WS 2.0 (javax.xml.ws.xxx
).
JSR 224 规范定义了 JAX-WS 2.0 ( ) 的注释。javax.xml.ws.xxx
e.g. from Using SOAP Faults and Exceptions in Java JAX-WS
例如来自在 Java JAX-WS 中使用 SOAP 错误和异常
@WebFault(name="CheckVerifyFault",
targetNamespace="http://www.example.com")
public class CheckVerifyFault extends Exception {
/**
* Java type that goes as soapenv:Fault detail element.
*/
private CheckFaultBean faultInfo;
public CheckVerifyFault(String message, CheckFaultBean faultInfo) {
super(message);
this.faultInfo = faultInfo;
}
public CheckVerifyFault(String message, CheckFaultBean faultInfo,
Throwable cause) {
super(message, cause);
this.faultInfo = faultInfo;
}
public CheckFaultBean getFaultInfo() {
return faultInfo;
}
}
Peer Reynderssays:
My guess would be that BEA wanted something NOW to put into Weblogic to compete with the equivalent feature in .NET. (see, developing Web services in WebLogic is just "as easy"). Also the annotations specified in JAX-WS 2.0 (JSR-224)
seemto provide you with more control. However JSR-224 does explicitly support/include JSR-181 (JSR-224: 7.10 Annotations Defined by JSR-181).
我的猜测是 BEA 现在想要将某些东西放入 Weblogic 中以与 .NET 中的等效功能竞争。(请参阅,在 WebLogic 中开发 Web 服务“同样简单”)。此外,JAX-WS 2.0 (JSR-224) 中指定的注释
似乎为您提供了更多控制权。但是 JSR-224 明确支持/包含 JSR-181(JSR-224:7.10 注释由 JSR-181 定义)。
For a more complete discussion about, see JSR 181: a Java Simplification Request
有关更完整的讨论,请参阅JSR 181:Java 简化请求
See also:
也可以看看:
回答by Paulo Merson
These two package namespaces do notdefine different approaches.
这两个包命名空间没有定义不同的方法。
- If you're creating services based on the Web, there are two options: SOAP services (AKA Web services) or REST services (AKA RESTful services).
- If implementing SOAP services in Java, the way to go is to use the JAX-WS framework. The framework provides tools, such as wsimport and wsgen, and of course an API.
- The JAX-WS API includes annotations, classes and interfaces for implementing the code of a SOAP service itself and the code of a service consumer (the client).
- Altogether these elements of the JAX-WS API use both
javax.xml.ws
andjavax.jws
package namespaces. - Just follow the tutorials or examples to create the services using JAX-WS. Don't worry about which packages do the API elements come from.
- But remember to avoid vendor specific API elements. You're more likely to run into these vendor specific elements when using WS-* standards (e.g., WS-Security) beyond WSDL and SOAP.
- 如果您正在创建基于 Web 的服务,则有两种选择:SOAP 服务(AKA Web 服务)或 REST 服务(AKA RESTful 服务)。
- 如果在 Java 中实现 SOAP 服务,要走的路是使用 JAX-WS 框架。该框架提供了工具,例如 wsimport 和 wsgen,当然还有一个 API。
- JAX-WS API 包括注释、类和接口,用于实现 SOAP 服务本身的代码和服务使用者(客户端)的代码。
- JAX-WS API 的这些元素总共使用
javax.xml.ws
和javax.jws
包名称空间。 - 只需按照教程或示例使用 JAX-WS 创建服务。不用担心 API 元素来自哪些包。
- 但请记住避免供应商特定的 API 元素。在使用 WSDL 和 SOAP 之外的 WS-* 标准(例如,WS-Security)时,您更有可能遇到这些特定于供应商的元素。