`

JAX-WS annotation

 
阅读更多
Source link: http://java.globinch.com/enterprise-java/web-services/jax-ws/java-jax-ws-tutorial-develop-web-services-clients-consumers


In bottom-up approach we create the service end point interface (SEI) first. You define the methods in SEI that you expose as services. SEI typically is a standard Java interface. This is going to be the “wsdl:portType “ element in your WSDL document. The methods defined in SEI will become the “wsdl:operation” elements in the “wsdl:portType element” in WSDL. You need to annotate the SEI interface with required JAX-WS annotations.

Let us have a closer look at the different annotations provided by the JAX-WS API and how and when we use them.

The @WebService annotations

The “@WebService” should be placed on an interface and a class that is intended to be used as a service. It has the following attributes.

      name: Specifies the name of the service interface and iss mapped to the name attribute of the wsdl:portType element in a WSDL contract document.
      targetNamespace: Specifies the target namespace under which the service is defined.(Default value is package name).
      serviceName: Specifies the name of the published service. This property is mapped to the name attribute of the wsdl:service element in WSDL document. (Default value is name of SEI implementation class. This attribute is used in implementation class).
      wsdlLocation: Specifies the URI at which the service’s WSDL contract is stored. (Default value is the URI at which the service is deployed).
      endpointInterface: Specifies the full name of the SEI that the implementation class implements.(This attribute is used in implementation class).
      portName: The name of the endpoint at which the service is published and is mapped to the name attribute of the wsdl:port element in WSDL contract document.(Default value is the append Port to the name of the service’s implementation class. This is used in implementation class).

The service implementation class is annotated with @webservice and can include additional attributes such as endpointInterface, portName , serviceName etc.

The @SOAPBinding annotation

By default the JAX-WS runtime engine uses the wrapped doc/literal SOAP binding if you don’t specify any. To specify the required SOAP binding you can use the @SOAPBinding annotation. You can add @SOAPBinding annotation to the SEI and its methods. The latter takes precedence if you use both.
You can read more about SOAP Binding styles. The following are the attributes of @SOAPBinding annotation.

    style: The values can be either DOCUMENT or RPC
     use: The values can be LITERAL or ENCODED
     parameterStyle: The value can be BARE or WRAPPED.

The @WebMethod annotation

You need to add the @WebMethod annotation provides the information that is normally represented in the wsdl:operation element in WSDL. This indicates the operation to which the method is associated.

     operationName: Indicates the value of the associated wsdl:operation element’s name. (Default value is the name of the method).
     action: This attribute specifies the value of the soapAction attribute of the soap:operation element for the method in WSDL. (Default value is an empty string).
     exclude: Specifies whether the method should be excluded from the service interface.(Default is false. But it is recommended that the SEI ideally should contain only the required methods which are required to be published).

The @RequestWrapper and @ResponseWrapper annotations

These annotations are placed on the methods in service endpoint interface. The @RequestWrapper specifies the Java class that implements the wrapper bean for the method parameters that are included in the request message sent in a remote invocation and the @ResponseWrapper specifies the Java class that implements the wrapper bean for the method parameters that are included in the response message sent in a remote invocation.
These annotations have localName, targetNamespace and className attributes and only className is mandatory.

The @WebFault annotation

The @WebFault annotation is used to map the Java exception to a wsdl:fault element. @WebFault is placed on exceptions that are thrown by your SEI. This has the the attributes name, targetNamespace and faultName attributes

The @Oneway annotation

The @Oneway annotation is placed on the methods in the SEI that will not require a response from the service. The runtime does not wait for a response and will not reserve any resource to process a response.

The @WebParam annotation

The @WebParam annotation allows you to specify the direction of the parameter, if the parameter will be placed in the SOAP header, and other properties of the generated wsdl:part. This annotation is placed on the parameters on the methods defined in the SEI. This annotation has the following attributes.

     name: Specifies the name of the parameter as it appears in the WSDL. For RPC bindings, this is name of the wsdl:part representing the parameter. For document bindings, this is the local name of the XML element representing the parameter.
     targetNamespace: Indicates the namespace for the parameter(Defaults is to use the service’s namespace).
     mode: Indicates the direction of the web parameter. Values can be Mode.IN (default) ,Mode.OUT or Mode.INOUT
    head: This indicates if the parameter is passed as part of the SOAP header. Values can be Mode.IN (default) ,Mode.OUT or Mode.INOUT
    partName: Indicates the value of the name attribute of the wsdl:part element for the parameter when the binding is document.

The @WebResult annotation

The @WebResult annotation allows you to specify the properties of the generated wsdl:part that is generated for the method’s return value. This annotation is placed on the methods defined in the SEI. This annotations has name, targetNamespace, header and partName attributes in which header specifies if the return value is passed as part of the SOAP header.
分享到:
评论

相关推荐

    JAX-WS 2.2 RI所有相关jar包

    JAX-WS 2.2 RI 所包含的JAR包集合,包含25个JAR包,列表如下: FastInoset.jar gmbal-api-only.jar ha-api.jar javax.annotation.jar javax.mail_1.4.jar jaxb-api.jar jaxb-impl.jar jaxb-xjc.jar jaxws-api...

    JAX-WS 2.2 完整jar包

    JAX-WS 2.2 RI 所包含的JAR包集合,包含25个JAR包,列表如下: FastInoset.jar gmbal-api-only.jar ha-api.jar javax.annotation.jar javax.mail_1.4.jar jaxb-api.jar jaxb-impl.jar jaxb-xjc.jar jaxws-api...

    JAX-WS的lib、src和docs

    4.Annotation Processing Tool(APT)是JAX-WS重要的组成部分,由于JAX-WS2.0规范用到很多元数据,所以需要APT来处理众多的Annotations.在%JDK_HOME%/bin下有两个命令wsgen和wsimport,就是用到APT和Compiler API来处理...

    jax-ws-2.2.rar

    在Tomcat上发布webservice所需要的jar包,总共25个:FastInfoset.jar/gmbal-api-only.jar/ha-api.jar/javax.annotation.jar/javax.mail_1.4.jar/jaxb-api.jar/jaxb-impl.jar/jaxb-xjc.jar/jaxws-api.jar/jaxws-rt....

    JAX-WS 2.2 RI 所包含的JAR包集合

    JAX-WS 2.2 RI 所包含的JAR包集合,包含21个JAR包,列表如下: FastInoset.jar gmbal-api-only.jar ha-api.jar javax.annotation.jar jaxb-api.jar jaxb-impl.jar jaxb-xjc.jar jaxws-api.jar jaxws-rt.jar ...

    JAX-WS 2.2相关jar包下载

    javax.annotation.jar javax.mail_1.4.jar jaxb-api.jar jaxb-impl.jar jaxb-xjc.jar jaxws-api.jar jaxws-rt.jar jaxws-rt-javadoc.jar jaxws-tools.jar jaxws-tools-javadoc.jar jsr173_api.jar jsr181-api.jar ...

    jaxws-api-工具

    5. **javax.annotation-api-1.2-b03.jar**:此库包含了Java的注解API,如`@WebService`、`@WebMethod`、`@WebResult`等,这些都是在JAX-WS中声明Web服务和操作的关键注解。通过这些注解,开发者可以轻松地在Java类上...

    jaxws java webservice需要的jar包

    5. **javax.annotation-api.jar**:包含了Java注解API,如`@WebService`, `@WebMethod`, `@WebResult`等,这些都是JAX-WS中定义Web服务和方法的重要注解。 6. **metro-config.jar** 和 **metro-utils.jar**:这部分...

    apache-cxf-3.1.1

    Frontends:CXF 支持多种“Frontend”编程模型,CXF 实现了JAX-WS API (遵循 JAX-WS 2.0 TCK 版本),它也包含一个“simple frontend”允许客户端和 EndPoint 的创建,而不需要 Annotation 注解。CXF 既支持 WSDL...

    CXF的学习笔记

    Frontends:CXF 支持多种“Frontend”编程模型,CXF 实现了 JAX-WS API (遵循 JAX-WS 2.0 TCK 版本),它也包含一个“simple frontend”允许客户端和 EndPoint 的创建,而不需要 Annotation 注解。CXF 既支持 WSDL ...

    使用Eclipse开发基于SpringBoot+JAX-RS的Restful服务.docx

    import org.springframework.context.annotation.ComponentScan; @SpringBootApplication @ComponentScan(basePackages = {"com.yourpackage"}) public class Application { public static void main(String[] ...

    jaxrs-ri2.23.1.zip

    9. **javax.annotation-api.jar** - 提供了Java注解API,如`@Path`, `@GET`, `@POST`等,这些都是构建RESTful服务的关键元素。 10. **jakarta.ws.rs-api.jar** - JAX-RS标准API,定义了RESTful服务的编程模型和接口...

    rad下集成开发web+services.doc

    - JAX-WS的新特性有:Annotation支持,用于快速将POJO转换为Web服务;异步编程模型,允许异步调用Web服务;以及MTOM,优化SOAP传输二进制数据的效率。 2. **Web服务开发概述**: - **Web服务向导**在RAD中扮演...

    webservice客服端所需最少jar包

    - `.metro-jax-ws-ri.jar`: 包含JAX-WS的实现。 - `stax-api.jar`, `woodstox-core-asl.jar`, `jackson-jaxrs.jar`等:STAX解析器和其他依赖项,用于处理XML流。 3. **JAXB绑定框架**: 用于将Java对象与XML文档...

    rad下集成开发web services.doc

    本文将详细介绍使用JAX-WS在RAD中进行Web服务开发的关键概念和步骤。 ### 1. JAX-WS简介 JAX-WS是Java平台上的Web服务标准,它取代了早期的JAX-RPC,提供了更简洁和高效的API。JAX-WS的核心特性包括: - **Java ...

    Java远程通信技术——Axis实战.doc

    随着技术发展,JAX-RPC演变为JAX-WS,引入了Java 5的Annotation特性,支持异步回调和面向消息模式,增强了Web服务的功能和灵活性。 **二、Axis 1.x实例** Axis 1.x版本是最早的Axis实现,主要用于创建、发布和消费...

    Java6上开发WebService的实例

    在Java 6中开发Web服务(WebService)是通过利用Java API for XML Web Services (JAX-WS)实现的。JAX-WS是Java平台标准版(Java SE)和企业版(Java EE)的一部分,用于创建面向服务的架构(SOA)中的Web服务。本...

    jar_files.zip内含jaxws-api-2.3.1.jar等jar包

    5. **javax.annotation-api-1.3.2.jar**:这个库包含了Java标准注解(Annotations),如`@Nullable`、`@NonNull`等,它们用于在代码中提供元数据,帮助编译器和工具进行静态分析,提高代码质量和可靠性。1.3.2版本...

Global site tag (gtag.js) - Google Analytics