SOAP Binding: Difference between Document and RPC Style Web Services

20 Flares Twitter 1 Facebook 9 Google+ 8 LinkedIn 2 Email -- Filament.io 20 Flares ×

A Tutorial on RPC Vs Document Style WSDL SOAP binding with Example

When you create Web Services using SOAP protocol, you follow either Document or RPC SOAP messaging style. In this article, let us discuss about the difference between the Document and RPC style web services. We use sample example programs which is developed using JAX-WS API from Java.

Basics: Document Style Vs RPC Style

The Document style indicates that the SOAP body contains a XML document which can be validated against pre-defined XML schema document.
RPC indicates that the SOAP message body contains an XML representation of a method call and uses the names of the method and its parameters to generate XML structures that represent a method’s call stack. The document/literal approach is easier because it simply relies on XML Schema to describe exactly what the SOAP message looks like while transmission.

What is SOAP Encoding and Literal?

SOAP Encoding indicates how a data value should be encoded in an XML format. SOAP Encoding is an extension of the SOAP framework. SOAP encoding offers rules to convert any data value defined in SOAP data model into XML format.

What is Literal?

In simplest definition, literal it means that the data is serialized according to a schema

Learn by doing: Document Vs RPC Web Services and Artifacts Examples (WSDL,Schema, SEI).

Let us create some sample programs to see the difference between the RPC and Document style web services. In Java using JAX-WS it is very easy to create web services. You can read the below article, if you are not familiar with JAX-WS.

RPC /LITERAL SOAP Binding Example Web Service

First let us see how the RPC/LITERAL/WRAPPED style web service request and response structure.
The following is a sample Java SEI (Service Endpoint Interface) to create a RPC web service.

/**
 * @author Binu George
 * Globinch.com
 * Visit  http://www.globinch.com. All rights reserved.
 */
package com.my.ws;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.WebParam.Mode;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.ParameterStyle;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;

@WebService(name = "MyJaxWSHello", 
		targetNamespace = "http://globinch.com", 
		wsdlLocation = "http://globinch.com/ws/MyJaxWS?wsdl")
@SOAPBinding(style=Style.RPC, use=Use.LITERAL, parameterStyle=ParameterStyle.WRAPPED)		
public interface MyJaxWSSEI {

	  @WebMethod(operationName="getGreetingRequest")
	  @WebResult(targetNamespace="http://globinch.com/ws/types",
	     name="GreetingResponse")
	  public JXRes getJXWsRes(
	     @WebParam(targetNamespace="http://globinch.com/ws/types",
	               name="name",
	               mode=Mode.IN)
	               String name
	  );

}

The corresponding WSDL and XML schema definition is given below. You can the operation name still appears in the SOAP message. The type encoding info is not present since this is defined as LITERAL.

Schema Defintion



  
  
    
      
      
    
  

WSDL Document




  
    
      
    
  
  
    
  
  
    
  
  
    
      
      
    
  
  
    
    
      
      
        
      
      
        
      
    
  
  
    
      
    
  

SOAP Request Message

  

   
   
      
         Binu George
      
   

SOAP Response Message

 

   
      
         
            Hello
            Binu George
         
      
   

From the above you can see that the WSDL is not so complex. It is not very easy to validate the messages since there is no complete schema defined for it. This means the schema alone does not tell you what the message body Info set contains because some of the soap:body contents comes from WSDL definitions. Because of this , schema describing an RPC/literal message is not sufficient to validate that message.

From the above request and response you can see that the Soap:Body contains one element which has the name of the WSDL operation and the namespace specified on the soap:body element in the WSDL binding. Inside this element, there’s an element for each part of the message and its name is name of the part. Inside each part element are the contents of that part, as defined by the schema type that the part references in WSDL.

For example see the above response. The

has the name of the WSDL operation and the namespace specified on the soap:body element in the WSDL binding. Inside this you can see the part element “GreetingResponse” and its content is as per the defined schema.

Notes on RPC –ENCODED Style and JAX-WS

In JAX-WS RPC/encoded is not supported as a messaging mode. In JAX-WS the “encoded” encoding style isn’t supported and only the “literal” encoding style used.
If you use wsimport/wsgen on wsdl documents/SEI that has use=”encoded” attribute/SOAP binding you may get the following error,

“….. invalid SOAP Binding annotation. Rpc/encoded SOAPBinding is not supported”

Or

“ rpc/encoded wsdls are not supported in JAXWS 2.0.  “

You can use JAX-RPC or Apache Axis V1 , f you want to send SOAP encoded messages or create RPC/encoded style WSDL.

Document/Literal SOAP Binding Web service

Let us now change the style to Document and see the generated schema files and WSDL files. There are two schema files generated and are included in the WSDLfile.

The SEI

/**
 * @author Binu George
 * Globinch.com
 * Visit  http://www.globinch.com. All rights reserved.
 */
package com.my.ws;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.WebParam.Mode;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.ParameterStyle;
import javax.jws.soap.SOAPBinding.Style;
import javax.jws.soap.SOAPBinding.Use;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;

@WebService(name = "MyJaxWSHello", 
		targetNamespace = "http://globinch.com", 
		wsdlLocation = "http://globinch.com/ws/MyJaxWS?wsdl")
@SOAPBinding(style=Style.DOCUMENT, use=Use.LITERAL, parameterStyle=ParameterStyle.BARE)		
public interface MyJaxWSSEI {

	  @WebMethod(operationName="getGreetingRequest")
	  /*@RequestWrapper(targetNamespace="http://globinch.com/ws/types",
	     className="java.lang.String")
	  @ResponseWrapper(targetNamespace="http://globinch.com/ws/types",
	     className="com.my.ws.JXRes")
	  @WebResult(targetNamespace="http://globinch.com/ws/types",
	     name="JXWsRes")*/
	    @WebResult(targetNamespace="http://globinch.com/ws/types",
	     name="GreetingResponse")
	  public JXRes getJXWsRes(
	     @WebParam(targetNamespace="http://globinch.com/ws/types",
	               name="name",
	               mode=Mode.IN)
	               String name
	  );

}

Schema defintion document1



  
  
  


Schema defintion document 2



  
  
    
      
      
    
  


The WSDL Document




  
    
      
    
    
      
    
  
  
    
  
  
    
  
  
    
      
      
    
  
  
    
    
      
      
        
      
      
        
      
    
  
  
    
      
    
  


You can see from the schema and wsdl files that all the elements are defined. The following request and response SOAP messages are following the schema definitions.

Sample SOAP Request


   
   
      Binu George
   


Sample SOAP Response


   
      
         Hello
         Binu George
      
   


In the above SOAP request and response messages, all the elements are defined in the XML schema definition files. But if you use the parameter style as WRAPPED you will see the operation name element in SOAP messages. Still the definition will be complaint to the XSD. Document style requires extra classes to run the application. You can use “wsgen” to generate all required Java artifacts including mapping classes, wsdl or xsd schema. Read more below

Incoming search terms:

20 Flares Twitter 1 Facebook 9 Google+ 8 LinkedIn 2 Email -- Filament.io 20 Flares ×

Related Posts

This Post Has 7 Comments

  1. Hi Binu,

    This Arun. I’ve been working in Web Service for last one yr.
    I’ve gone through your article and it’s really interesting and the way it’s represented is awesome.

    I’ve few questions and doubt ,if you can help then it will be great..!!

    Questions:
    1> I’ve given a WSDL file where the fault information is not present.
    When I got some error,it’s coming as a soap fault. I want to know where it is defined and how to handle this?

    2> When the fault information is available in the WSDL file?

    I’d appreciate your valuable help .

    Thanks,
    Arun

  2. Hi Binu,

    I was trying to work on the sample demo and was thinking where to get the JXRes file as seen in one of your method signatures:
    public JXRes getJXWsRes

    Is JXRes part of the javax.jws package? because I don’t seem to see this class in there.

    Thanks,
    Jed

  3. Could you please explain why your auto generated wsdl import the xsd schemata as relative resource? my auto generated wsdl always looks like this

    Is there a way to configure the application server runtime wsdl generation to skip the absolut path generation?

    Greetings,
    Sascha

  4. Sorry, the comment field skipped my code:

    schemaLocation=”http://localhost:8080/Service/VehilcleService.V2?xsd=1″

    Greetings,
    Sascha

Leave a Reply

Your email address will not be published. Required fields are marked *

Paged comment generated by AJAX Comment Page
© 2024 Globinch Java Forum - Theme by WPEnjoy · Powered by WordPress