JAX-WS 2.0 Annotations
@WebService
This annotation marks either a Java class or a service endpoint interface (SEI) as implementing a Web service interface.
// 该注释声明这个类或者是服务终端接口实现了联网服务接口//
This annotation is applicable for a client or server SEI;
// 可以用在客户端或者服务器的服务终端接口
or for a service endpoint implementation class for a JavaBeans endpoint.
//或者是一个JavaBean的服务终端的实现类
Three of the properties of the annotation can be used only with a service endpoint implementation class for a JavaBeans endpoint.
These properties are serviceName, portName, and endpointInterface.
//该注释的三个属性(serviceName , portName, endpointInterface) 只能用于一个javaBean终端的服务终端实现类
@WebService(endpointInterface = “com.ws.WService0001”) // 这里声明后的属性指出接口是com.ws.WService0001 虽然bean 已经 implements WService0001 但是因为规定和方便生成WSDL 这里要写明
/**
* 这里是一个JavaBean
*/
public class WSBean0001 implements WService0001 {
@Override
public String getTimeAsString() { return new Date().toString(); }
@Override
public long getTimeAsElapsed() { return new Date().getTime(); }
}
/**
这个是SEI
*/
@WebService (这个注释指出这是一个WS)
@SOAPBinding(style = Style.RPC) (SOAP的一些定义,目前不用关心)
public interface WService0001 {
@WebMethod()String getTimeAsString();
@WebMethod()long getTimeAsElapsed();
}
If the annotation references an SEI through theendpointInterfaceattribute, then the SEI must also have the @WebService annotation.
//如果注释通过(endpointInterface 属性)指向了一个SEI, 那么这个SEI必须带有@WebService (参考上例)
By default, all public methods in a class that specifies the @WebService annotation are exposed in the Web service.
//正常情况下 该类所有public方法都会曝露出来
Annotation target: Type 注释目标 : 类的类型
Properties: 属性
name
The name of thewsdl:portType. Thenameproperty maps to an SEI or a Java implementation class. The default value is the unqualified name of the Java interface or class. (String)
name 标签 WSDL:PortType的名称
*
<wsdl:documentation .... />?
<wsdl:port name="nmtoken" binding="qname"> *
<wsdl:documentation .... /> ?
<-- extensibility element -->
</wsdl:port>
<-- extensibility element -->
targetNamespace(目标命名空间)
Specifies the XML namespace of the WSDL and XML elements that are generated from the Web service.
If the @WebService.targetNamespace annotation is on a service endpoint interface, the targetNamespace is used for the namespace for the wsdl:portType (and associated XML elements).
If the @WebService.targetNamespace annotation is on a service implementation bean that does not reference a service endpoint interface (through the endpointInterface annotation element), the targetNamespace is used for both the wsdl:portType and the wsdl:service (and associated XML elements).
If the @WebService.targetNamespace annotation is on a service implementation bean that does reference a service endpoint interface (through the endpointInterface annotation element), the targetNamespace is used for only the wsdl:service (and associated XML elements).
The default value is the namespace mapped from the package name that contains the Web service. (String)
This annotation denotes a method that is a Web service operation.
You can apply this annotation to public methods in a client or server Service Endpoint Interface (SEI), or in a service endpoint implementation class for a JavaBeans endpoint.
Important:
The @WebMethod annotation is only supported on classes that have the @WebService annotation.
Annotation target: Method
Properties:
@Oneway
This annotation denotes a method as a one-way operation for a Web service. It has an input message but no output message. This annotation can be used only on methods that have no return value.
You can apply this annotation to public methods in a client or server Service Endpoint Interface (SEI), or in a service endpoint implementation class for a JavaBeans endpoint.
Annotation target: Method
There are no properties on the OneWay annotation.
@WebParam
This annotation customizes the mapping of an individual parameter to a Web service message part and XML element.
You can apply this annotation to public methods in a client or server Service Endpoint Interface (SEI), or in a service endpoint implementation class for a JavaBeans endpoint.
Annotation target: Parameter
Properties:
This annotation customizes how a return value maps to a WSDL part or XML element.
You can apply this annotation to public methods in a client or server Service Endpoint Interface (SEI), or in a service endpoint implementation class for a JavaBeans endpoint.
Annotation target: Method
Properties:
@HandlerChain
This annotation associates the Web service to an externally-defined handler chain. You can use this annotation if the handler configuration must be shared across multiple Web services, and embedding handler configuration in the application source is inefficient.
Apply this annotation to a client or server Service Endpoint Interface (SEI), or to a service endpoint implementation class for a JavaBeans endpoint.
Annotation target: Type
Properties:
This annotation specifies the mapping of the Web service onto the SOAP message protocol.
You can apply this annotation to a type or public methods in a client or server Service Endpoint Interface (SEI), or in a service endpoint implementation class for a Java beans endpoint.
The method-level annotation is limited by what it can specify. Use the annotation only if thestyleproperty has the valueDOCUMENT. If the method-level annotation is not specified, the @SOAPBinding behavior from the type is used.
Annotation target: Type or Method
Properties:
@BindingType
This annotation specifies which binding to use when publishing an endpoint of this type. If the annotation is not specified, the default value is SOAP11_HTTP_BINDING.
You can apply this annotation to a JavaBeans implementation class for a service endpoint that is based on the Service Endpoint Interface or the Provider interface.
Important:
Use the @BindingType annotation on the JavaBeans endpoint implementation class to enable Message Transmission Optimization Mechanism (MTOM), by specifying eitherSOAP11_HTTP_MTOM_BINDINGorSOAP12_HTTP_MTOM_BINDINGas the value for the annotation.
Annotation target: Type
Properties:
This annotation supplies the JAXB generated request wrapper bean, the element name, and the namespace for serialization and deserialization with the request wrapper bean that is used at runtime.
When starting with a Java object, this element is used to resolve overloading conflicts in document literal mode. Only theclassNameattribute is required in this case.
This annotation can be applied to methods in a client or server Service Endpoint Interface (SEI), or in a service endpoint implementation class for a JavaBeans endpoint.
Annotation target: Method
Properties:
This annotation supplies the JAXB-generated response wrapper bean, the element name, and the namespace for serialization and deserialization with the response wrapper bean that is used at runtime.
When starting with a Java object, use this element to resolve overloading conflicts while in document literal mode. Only theclassNameattribute is required in this case.
You can apply this annotation to methods in a client or server Service Endpoint Interface (SEI), or in a service endpoint implementation class for a Java beans endpoint.
Annotation target: Method
Properties:
This annotation specifies whether a service provider must have access to an entire message protocol or just to the message payload.
Important:
The @ServiceMode annotation is only supported on classes that have the @WebServiceProvider annotation.
Annotation target: Type
Properties:
@Resource
This annotation marks a WebServiceContext resource that the application needs.
Apply this annotation to a service endpoint implementation class for a JavaBeans endpoint or a Provider endpoint. The container will inject an instance of the WebServiceContext resource into the endpoint implementation when it is initialized.
Annotation target: Field or Method
Properties:
@PostConstruct
This annotation marks a method that must be executed after dependency injection is performed on the class.
Apply this annotation to a JAX-WS application handler, a service endpoint implementation class for a JavaBeans endpoint or a Provider endpoint.
Annotation target: Method
@PreDestroy
This annotation marks a method that must be executed when the instance is in the process of being removed by the container.
Apply this annotation to a JAX-WS application handler, a service endpoint implementation class for a JavaBeans endpoint or a Provider endpoint.