JAX-WS规范

JAX-WS规范实现了java类与soap之间“沟通”的桥梁。在这里有两点需要注意的,第一:开发者对这种“沟通”是一无所知的,是自动进行的;第二:这里我使用到的是“沟通”一词而不是“转换”。java类可以理解成实体,就好像使用移动电话的人,而soap是通讯手段,可以理解成电信运营商。java类只管发送或者接受消息,而soap负责如何将java类发出的消息转发到其他java类上。

JAX-WS规范是一组XML web services的JAVA API。JAX-WS允许开发者可以选择RPC-oriented或者message-oriented 来实现自己的web services。
JAX-WS中,一个远程调用可以转换为一个基于XML的协议例如SOAP。在使用JAX-WS过程中,开发者不需要编写任何生成和处理SOAP消息的代码。JAX-WS的运行时实现会将这些API的调用转换成为SOAP消息。
在服务器端,用户只需要通过Java语言定义远程调用所需要实现的接口SEI (service endpoint interface),并提供相关的实现,通过调用JAX-WS的服务发布接口就可以将其发布为WebService接口。
在客户端,用户可以通过JAX-WS的API创建一个代理(用本地对象来替代远程的服务)来实现对于远程服务器端的调用。

另外,JAX-WS规范到底有什么特点了?

可以参考以下的译文:(来源J2EE5新特性的)

Java API for XML-Based Web Services (JAX-WS)

Q. What is the difference between JAX-RPC and JAX-WS?

A. One of the main differences between JAX-RPC and JAX-WS is the programming model. A JAX-WS-based service uses annotations, such as@WebService, to declare web service endpoints. Using these annotations obviates the need for deployment descriptors. With JAX-WS, you can have a web service deployed on a Java EE-compliant application server without a single deployment descriptor. JAX-WS also provides many additional features, such as asynchronous callback support. Refer to theJAX-WS specification for more information.

翻译:

JAX-RPC and JAX-WS的区别在于:

两者最主要的区别在编程模型。JAX-WS使用注释的办法,例如使用@WebService标签来声明服务端口。JAX-WS使用注释的办法避免为了部署应用而配置环境的麻烦。使用了JAX-WS,部署web service的时候,我们不需要每次都重新编写配置信息,只要是JAVA-EE所兼容的应用服务器都可以直接使用的。除此之外,JAX-WS还具有其他功能,例如异步的回调等。

Q. Does the Java EE 5 platform support JAX-WS?

A. Yes, the Java EE 5 platform supports JAX-WS-based services (in addition to JAX-RPC-based services) and makes these services portable throughJSR 109.

翻译:

Java EE 5 支持JAX-WS

Q. Can a JAX-WS-based service and a JAX-RPC-based service co-exist?

A. Yes.

翻译:

JAX-WS JAX-RPC 可以同时存在。

Q. How do I develop a simple JAX-WS-based service?

A. See this tip.

Q. Can a JAX-WS-based service that was developed and deployed on Java WSDP 2.0 be deployed and run on any Java EE 5-based platform?

A. No.

Q. Will a JAX-WS-based web service work with a JAX-RPC client and a JAX-RPC-based web service work with a JAX-WS client?

A. Yes.

翻译:

服务器端和客户端可以分别为JAX-WS或JAX-RPC

Q. Can I have a JAX-WS web service with deployment descriptors?

A. Yes. The same deployment descriptors, such as webservices.xml,web.xml, and ejb-jar.xml, can be used, just as they were with JAX-RPC-based services. If a deployment descriptor is specified, the values specified in the annotation attributes will be overridden by the corresponding values specified in the deployment descriptors.

翻译:

在JAX-RPC-based services中可以使用配置文件,例如webservices.xml, web.xmlejb-jar.xml。一旦使用了配置文件,配置文件中的值就会覆盖(override)注释中同样的变量的值。

Q. Can the deployment descriptor values be overridden?

A. No.

翻译:

配置文件中的值不会被覆盖(override)

Q. Do I have to specify all attributes for annotations?

A. No. Well-defined default values have been specified for all attributes of annotations.

翻译:

不需要指定注释中全部属性的值。因为这些值都默认预设好了。

 

最后,附上参考到两篇好文章:

基本了解:

http://jnn.iteye.com/blog/83103

JAX-WS或JAX-RPC的比较:

http://www.ibm.com/developerworks/cn/webservices/ws-tip-jaxwsrpc.html

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
JAX-WS是Java API for XML Web Services的缩写,它是Java EE平台的一部分,提供了一组API来开发基于SOAP协议的Web服务。在JAX-WS规范中,通过使用注解或者XML配置可以轻松地创建Web Service接口。 在JAX-WS中,可以使用@WebService注解来标识一个类或者接口是一个Web Service。在这个类或者接口中,可以定义一系列方法作为Web Service的操作。在方法中,可以使用@WebMethod注解来标识该方法是一个Web Service操作。例如: ``` @WebService public interface MyWebService { @WebMethod String sayHello(String name); } ``` 在这个例子中,定义了一个MyWebService接口,并且在接口中定义了一个sayHello方法,该方法接受一个字符串参数name,并且返回一个字符串结果。 对于请求消息,可以使用@XmlElement注解来指定请求消息体中的元素名称和类型。例如: ``` @WebService public interface MyWebService { @WebMethod String processRequest(@XmlElement(name="req", type=Request.class) Request request); } ``` 在这个例子中,定义了一个processRequest方法,该方法接受一个Request类型的参数,并且使用@XmlElement注解指定了请求消息体中的元素名称为"req",类型为Request。 需要注意的是,Request类需要使用@XmlRootElement注解来标识它是一个根元素。例如: ``` @XmlRootElement(name="Request") public class Request { // ... } ``` 这样,就可以使用JAX-WS规范创建一个Web Service接口,并且定义请求消息体中的元素名称和类型。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值