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

Quick Notes Finder Tags

Activities (1) advance java (1) agile (3) App Servers (6) archived notes (2) Arrays (1) Best Practices (12) Best Practices (Design) (3) Best Practices (Java) (7) Best Practices (Java EE) (1) BigData (3) Chars & Encodings (6) coding problems (2) Collections (15) contests (3) Core Java (All) (52) course plan (2) Database (12) Design patterns (8) dev tools (3) downloads (2) eclipse (9) Essentials (1) examples (14) Exceptions (4) exercises (6) Getting Started (18) Groovy (2) hadoop (4) hibernate (77) hibernate interview questions (6) History (1) Hot book (4) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (4) java ee exercises (1) java ee interview questions (2) Java Elements (16) Java Environment (1) Java Features (4) java interview points (4) java interview questions (4) javajee initiatives (1) javajee thoughts (3) Java Performance (6) Java Programmer 1 (4) Java Programmer 2 (2) Javascript Frameworks (1) Java SE Professional (1) JSP (1) linked list (3) maven (1) Multithreading (16) NFR (1) No SQL (1) Object Oriented (9) OCPJP (4) OCPWCD (1) OOAD (3) Operators (4) Overloading (2) Overriding (2) Overviews (1) policies (1) programming (1) Quizzes (17) references (2) resources (1) restful web service (3) Searching (1) security (10) Servlets (8) Servlets and JSP (31) Sorting (1) source code management (1) spring (4) spring boot (1) Spring Examples (1) Spring Features (1) spring jpa (1) Stack (1) Streams & IO (3) Strings (11) SW Developer Tools (2) testing (1) user interface (1) vxml (8) web services (1) Web Technologies (1) Web Technology Books (1) youtube (1)