Important Annotations for Developing SOAP Web Services

While creating a web service bottom up, we can configure the SEI and SIB to act as a web service using annotations. In case of bottom up web service, the binding properties in a WSDL can be specified using these annotations.

 

Summary of common annotations used to create web services

 

@WebService annotation 

  • May be used on:

    • SEI to denote that it is a Web Service interface

    • SIB that does NOT reference a SEI through the endpointInterface attribute.

    • SIB that reference a SEI through the endpointInterface attribute.

  • Attributes of the @WebService annotation are:

    • endpointInterface

      • The complete name of the SEI.

    • name

      • The name of the Web Service.

      • In WSDL 1.1, used as the name of the wsdl:portType.

    • portName

      • The port name of the Web Service.

      • In WSDL 1.1, used as the name of the wsdl:port.

    • serviceName

      • The service name of the Web Service

      • In WSDL 1.1, used as the name of the wsdl:service.

    • targetNamespace

      • If the @WebService.targetNamespace annotation is on a SEI, the targetNamespace is used for the namespace for the wsdl:portType and associated XML elements.

      • If the @WebService.targetNamespace annotation is on a SIB that does NOT reference a SEI through the endpointInterface attribute, 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 SIB that does reference a SEI through the endpointInterface attribute, the targetNamespace is used for only the wsdl:service and associated XML elements.

    • wsdlLocation

      • Relative or absolute URL to a pre-existing WSDL file.

      •  Indicate that the SIB is implementing a pre-defined WSDL contract.

      • A single WSDL file might contain multiple portTypes and multiple bindings.

        • The annotations on the SIB determine the specific portType and bindings that correspond to the Web Service. 

    • IMP! Following attribtes are not allowed on endpoint interfaces (SEI): serviceName, portName, endpointInterface.

 

@WebMethod annotation

  • The @WebMethod annotation (optional) is declared at the method level and is used to customize a method that is exposed as a web service operation.
  • When used within an implementation class it allows the developer to limit which methods are to be exposed as a web service, the name associated with the operation, and the SOAPAction binding.

  • Its attributes are

    • action 

      • the SOAPAction binding

    • exclude

      • true to mark a method as not exposed as a web method

    • operationName

      • name associated with the operation

  • When used in an interface (SEI), it is only used to control the name associated with the operation and the SOAPAction binding.

 

@SOAPBinding annotation

  • The @SOAPBinding annotation can be used to configure the soap binding style, encoding and parameter style;

    • using style, use and parameterStyle attributes:

      • Values for style can be Style.DOCUMENT (Default) or Style.RPC.

      • Values for use are Use.Literal (Default) or Use.Encoded.

      • Values for parameterStyle are ParameterStyle.BARE and ParameterStyle.WRAPPED (Default).

    • You can use the @SOAPBinding annotation on the SEI and any of its methods.

      • The settings of the method’s annotation takes precedence.

 

@Resource annotations

  • The Resource annotation marks a resource that is needed by the application.

  • This annotation may be applied to an application component class, or to fields or methods of the component class.

  • When the annotation is applied to a field or method, the container will inject an instance of the requested resource into the application component when the component is initialized.

  • If the annotation is applied to the component class, the annotation declares a resource that the application will look up at runtime.

  • Typically a WebServiceContext is injected into an endpoint implementation class using the Resource annotation. 

    • A WebServiceContext makes it possible for a web service endpoint implementation class to access message context and security information relative to a request being served.

 

Example: getting WebServiceContext object 

@WebService
public class MyService {
@Resource
WebServiceContext ctxt;
public String echo(String str) {
...
}

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!