October 20, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Simplify Your Web Services Development with JSR 181

  • February 28, 2008
  • By Ayyappan Gandhirajan
  • Send Email »
  • More Articles »

Step 3 — Declare SOAP Binding

This @SOAPBinding annotation type is used to define the Web Service binding. The Web Service developer may assign proper values for message encoding and format. This annotation type has following important attributes:

  • Messaging Style
    • Encoding style for message that is transported in the wire
    • Possible values: RPC or DOCUMENT
    • Default: DOCUMENT
  • Messaging Use
    • Formatting style for message that is transported in the wire
    • Possible values: ENCODED or LITERAL
    • Default: LITERAL
  • Parameter Style
    • Decides whether operation name needs to be part of the SOAP body
    • Possible values: BARE or WRAPPED
    • Default: WRAPPED

Listing 3 shows the code implementation along with @SOAPBinding annotation type:

Listing 3: Define SOAP Binding

package service;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@WebService( name = "ZipCodeFinder",
            serviceName="ZipCodeFinder",
            targetNamespace = "http://sampleweb.com/services")

@SOAPBinding( style = SOAPBinding.Style.DOCUMENT,
            use = SOAPBinding.Use.LITERAL,
            parameterStyle = SOAPBinding.ParameterStyle.WRAPPED )
            
public class ZipCodeFinderService {
      public String getZipCode( String city, String state ) {
            return "08817";
      }      
}

Step 4 — Optional Transport Declaration

You can use an optional WebLogic annotation type (not a standard) to refine the Web Service further. The @WLHttpTransport annotation type helps you change the context and service URI of the Web Service. The important attributes are:

  • Context Path — The context path of the Web Service URL
  • Service URI — Information next to context path in the Web Service URL

Listing 4 shows the implementation of the optional transport declaration:

Listing 4: Defining optional transport

package service;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import weblogic.jws.WLHttpTransport;

@WebService( name = "ZipCodeFinder",
            serviceName="ZipCodeFinder",
            targetNamespace = "http://sampleweb.com/services")

@SOAPBinding( style = SOAPBinding.Style.DOCUMENT,
            use = SOAPBinding.Use.LITERAL,
            parameterStyle = SOAPBinding.ParameterStyle.WRAPPED )

@WLHttpTransport( contextPath = "ZipCodeServices", 
            serviceUri = "ZipCodeFinderService" )
            
public class ZipCodeFinderService {
      public String getZipCode( String city, String state ) {
            return "08817";
      }      
}

Step 5 — Declare Web Method

This section will help you how to expose selectively the operations in the POJO class. For some scenario, you might want only to expose business operations and bar data operations in the Java class. In that scenario, you may find @WebMethod annotation type useful.

The @WebMethod has the following attributes:

  • Operation name — Name of the Java method that needs to be exposed as operation
  • Action — SOAP action

Listing 5 shows the implementation of the Web method:

Listing 5: Define WebMethod

package service;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import weblogic.jws.WLHttpTransport;

@WebService( name = "ZipCodeFinder",
            serviceName="ZipCodeFinder",
            targetNamespace = "http://sampleweb.com/services")

@SOAPBinding( style = SOAPBinding.Style.DOCUMENT,
            use = SOAPBinding.Use.LITERAL,
            parameterStyle = SOAPBinding.ParameterStyle.WRAPPED )

@WLHttpTransport( contextPath = "ZipCodeServices", 
            serviceUri = "ZipCodeFinderService" )

@WebMethod( operationName = "getZipCode" )            
public class ZipCodeFinderService {
      public String getZipCode( String city, String state ) {
            return "08817";
      }      
}

Tags: Web services



Page 2 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel