Web Services Metadata Annotations (JSR 181)

Using annotations from the JSR 181 specification, you can annotate a Web service implementation class or a Web service interface. Then you can generate a Web service with a wizard or by publishing the application to a server.

Note: The Java™ class that contains each annotation in the JSR 181 standard is named javax.jws.xxx, where xxx is the name of the annotation after the '@' character. For example, the Java class name that corresponds to @WebService is javax.jws.webservice.

Name: Description: Properties: Definitions:
@WebService This annotation marks either a Java class or a service endpoint interface (SEI) as implementing a Web service interface.

Important:

This annotation is applicable for a client or server SEI; or for a service endpoint implementation class for a JavaBeans™ endpoint.

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.

If the annotation references an SEI through the endpointInterface attribute, then the SEI must also have the @WebService annotation.

By default, all public methods in a class that specifies the @WebService annotation are exposed in the Web service.

  • Annotation target: Type

  • Properties:

    - name

    The name of the wsdl:portType. The name property maps to an SEI or a Java implementation class. The default value is the unqualified name of the Java interface or class. (String)

    - 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)

    - serviceName

    Specifies the service name of the Web service: wsdl:service. This property is not allowed on endpoint interfaces. The default value is the simple name of the Java class + Service. (String)

    - endpointInterface

    Specifies the qualified name of the service endpoint interface that defines the services' abstract Web service contract. If specified, the service endpoint interface is used to determine the abstract WSDL contract. (String)

    - portName

    The wsdl:portName. The portName property is the name of the endpoint port. The default value is WebService.name +Port . (String)

    - wsdlLocation

    Specifies the Web address of the WSDL document that defines the Web service. The Web address is either relative or absolute. (String)

@Retention(value = RetentionPolicy.RUNTIME)
@Target({TYPE})
public @interface WebService{
	String name() default “”;
	String targetNamespace() default “”;
	String serviceName() default “”’;
	String wsdlLocation() default “”;
	String endpointInterface() default “”;
	String portName() default “”;
};
@WebMethod 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:

    - operationName

    Specifies the name of the wsdl:operation that matches this method. The default value is the name of the Java method. (String)

    - action

    Defines the action for this operation. For SOAP bindings, this value determines the value of the SOAPAction header. (String)

    - exclude

    Specifies whether to exclude a method from the Web service. This property can be used only with an implementation class. Used to stop an inherited method from being exposed as part of this web service. If this element is specified, other elements must not be specified for the @WebMethod. This property is not allowed on endpoint interfaces.

    The default value is false. (Boolean)

@Retention(value = RetentionPolicy.RUNTIME)
@Target({TYPE})
public @interface WebMethod{
	String operationName() default “”;
	String action() default “”;
	boolean exclude() default false;
};
@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.

@Retention(value = RetentionPolicy.RUNTIME)
@Target({TYPE})
public @interface OneWay{
};
@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:

    - name

    If the operation is remote procedure call (RPC) style and the partName attribute is not specified, then this is the name of the wsdl:part attribute that represents the parameter. If the operation is document style or the parameter maps to a header, then name is the local name of the XML element that represents the parameter. This attribute is required if the operation is document style, the parameter style is BARE, and the mode is OUT or INOUT. If the partName attribute is specified, then the name attribute is ignored. (String)

    - partName

    Defines the name of wsdl:part attribute that represents this parameter. Use this only if the operation is RPC style, or the operation is document style and the parameter style is BARE. (String)

    - targetNamespace

    Specifies the XML namespace of the XML element for the parameter. It applies only for document bindings when the attribute maps to an XML element. The default value is the targetNamespace for the Web service. (String)

    - mode

    The value represents the direction the parameter flows for this method. Valid values are IN, INOUT, and OUT. (String)

    - header

    Specifies whether the parameter is in a message header rather than a message body. The default value is false. (Boolean)

@Retention(value = RetentionPolicy.RUNTIME)
@Target({PARAMETER})
public @interface WebParam{
	public enum Mode{
		IN,
		OUT,
		INOUT
	};
	String name() default “”;
	String partName() default "";
	String targetNamespace() default “”;
	Mode mode() default Mode.IN
	boolean header() default false;
};
@WebResult 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:

    - name

    Specifies the name of the return value as it is listed in the WSDL file and found in messages on the wire. For RPC bindings, this is the name of the wsdl:part attribute that represents the return value. For document bindings, the name parameter is the local name of the XML element that represents the return value. The default value is return for RPC and DOCUMENT/WRAPPED bindings. The default value is the method name + Response for DOCUMENT/BARE bindings. (String)

    - targetNamespace

    Specifies the XML namespace for the return value. Use this annotation only for document bindings when the return value maps to an XML element. The default value is the targetNamespace for the Web service. (String)

    - header

    Specifies whether the result is carried in a header. The default value is false. (String)

    - partName

    Specifies the part name for the result with RPC or DOCUMENT/BARE operations. The default value is @WebResult.name. (Boolean)

@Retention(value = RetentionPolicy.RUNTIME)
@Target({METHOD})
public @interface WebResult{
	String name() default “return”;
	String targetNamespace default() “”;
	boolean header() default false;	
	String partName() default "";
};
@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:

    - file

    Specifies the location of the handler chain file. The file location is either an absolute java.net.URL in external form or a relative path from the source or class file. (String)

    - name

    Specifies the name of the handler chain in the configuration file. (String)

@Retention(value = RetentionPolicy.RUNTIME)
@Target({TYPE})
public @interface HandlerChain{
	String file();
	String name();
};
@SOAPBinding 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 the style property has the value DOCUMENT. If the method-level annotation is not specified, the @SOAPBinding behavior from the type is used.

  • Annotation target: Type or Method

  • Properties:

    - style

    Defines encoding style for messages sent to and from the Web service. The valid values are DOCUMENT and RPC. The default value is DOCUMENT. (String)

    - use

    Defines the encoding used for messages sent to and from the Web service. The default value is LITERAL. ENCODED is not a supported value. (String)

    - parameterStyle

    Determines whether the method's parameters represent the entire message body, or if the parameters are elements wrapped inside a top-level element named after the operation. Valid values are WRAPPED or BARE. You can only use the BARE value with DOCUMENT style bindings. The default value is WRAPPED. (String)

@Retention(value = RetentionPolicy.RUNTIME)
@Target({TYPE})
public @interface SOAPBinding{
	public enum Style{
		DOCUMENT,
		RPC
	};
	public enum Use{
		LITERAL,
	};
	public enum ParameterStyle{
		BARE,
		WRAPPED
	};
	Style style() default Style.DOCUMENT
	Use use() default Use.LITERAL
	ParameterStyle parameterStyle() default ParameterStyle.WRAPPED;
};

 

Related reference

Rules for methods in classes annotated with @WebService

Related information

JSR 181: Web Services Metadata for the Java Platform