Java Login


Hello guys, is for Java and J2EE developers, all examples are simple and easy to understand 

It is developed and maintained by Vaibhav Sharma. The views expressed on this website are his own and do not necessarily reflect the views of his former, current or future employers. I am professional Web development. I work for an IT company as Senior Consultant. Primary I write about spring, hibernate and web-services. I am trying to present here new technologies.

     << Previous
Next >>     

Web Service Schema Type and Binding

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.

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.
Literal encoding means that the Body contents conform to a specific XML Schema. SOAP encoding uses a set of rules based on the XML Schema datatypes to encode the data, but the message doesn't conform to a particular schema.

SOAP encoding is particularly useful is you're passing cyclic object graphs. For example, if you have an element which is referenced repeatedly within the object graph, when using SOAP encoding, you would specify the element once and then reference the element as needed. When using literal encoding, you would have to repeat this element each time it's referenced. So obviously it sounds like a good idea to use SOAP encoding -- but, if you do, then you can't validate the message with an XML Schema, and you can't transform the message using XSLT.

The Document style indicates that the SOAP body contains a XML document which can be validated against pre-defined XML schema document. Document Just send the XML as is. There's also a variation called wrapped that is still specified as 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. RPC Add extra elements to simulate a method call. (Note that RPC is also a communication pattern.)

Here's an example of an RPC-style message:

<tns:matchNoteAndNote xmlns:tns="urn:outline.demo">
<in0 xsi:type="xsd:string">0000000000</in0>
<in1 xsi:type="xsd:string">000000000B</in1>

RPC relies on some rules. Observe that the root element is qualified with a namespace, but the two child elements use unqualified names. The root element is named after the operation: opName for a SOAP request, opNameResponse for a SOAP response. Each child is a parameter, or a return value named opNameReturn.
Now here's an example of a document-style message:

<out:getNoteResponse xmlns:out="urn:outline.demo">
<out:note key="000000000B">

Observe that all elements are defined within the same namespace. With a document-style Web service, you're free to define the XML however you wish because all the XML is explicitly specified.

Next, we examine how binding style is specified in the WSDL. There actually is a style attribute in the <soapbind:binding> element, which is the <wsdl:binding> element's first child. Also, each nonempty <wsdl:message> has one or more <wsdl:part> child elements, into which style factors.

<soap:binding style="document" transport=""/>

For document and RPC style use, you have to use style option in binding tag as per above example.

     << Previous
Next >>