Thursday, 22 October 2015

Difference Between Style and Use in Soap web service

<wsdl:binding name="ConsultantWebServiceBinding" type="tns:ConsultantWebService">
<wsdl:documentation>
http://schemas.xmlsoap.org/soap/http- this fix for http protocol
</wsdl:documentation>
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="uploadConsultant">
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="tConsultantFaultMessageException">
<soap:fault name="tConsultantFaultMessageException"/>
</wsdl:fault>
</wsdl:operation>

</wsdl:binding>

SOAP - is protocol which define the structure of message in soap web service 
that is called soap message.

<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:findWeatherByCity xmlns:ns2="http://service.web.soap.com/">
<arg0>delhi</arg0>
</ns2:findWeatherByCity>
</S:Body>

</S:Envelope>

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:findWeatherByCityResponse
xmlns:ns2="http://service.web.soap.com/">
<return>
<city>delhi</city>
<description>weather will be cold today..............</description>
<pincode>100012</pincode>
<temp>22*C</temp>
</return>
</ns2:findWeatherByCityResponse>
</S:Body>

</S:Envelope>

use - literal/encoded

Note: Message format inside the soap body is define by style and use

JAX-RPC 1.0 - JAX-RPC 1.1-> JAX-WS 2.x  (All are soap web service specification)


In JAX-WS 2.x 
Web service by default
style= document
use=literal


style can take two value = document and rpc.....

document  ->

The Document style indicates that the SOAP body contains a XML document which can be 

validated against pre-defined XML schema document.



 Style =document

consultants.xsd

<element name="consultantRequest" type="tns:Consultant"/>


<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:it="http://www.consultants.com/it">
   <soapenv:Header/>
   <soapenv:Body>
      <it:consultantRequest eid="333">
         <it:name>nagendra</it:name>
         <!--1 to 2 repetitions:-->
         <it:email>nky@gmail.com</it:email>
         <it:mobile>
            <it:color>white</it:color>
            <it:price>123</it:price>
            <it:vendor>nokia</it:vendor>
         </it:mobile>
         <it:age>34</it:age>
         <!--Optional:-->
         <it:address>J@2</it:address>
         <!--Optional:-->
         <it:gender>Male</it:gender>
         <it:designation>software engineer</it:designation>
         <!--Optional:-->
         <it:photo>cid:280514180644</it:photo>
      </it:consultantRequest>
   </soapenv:Body>

</soapenv:Envelope>


When style=rpc
your WSDL will look like this

<wsdl:binding name="ConsultantWebServiceBinding" type="tns:ConsultantWebService">
<wsdl:documentation>
http://schemas.xmlsoap.org/soap/http- this fix for http protocol
</wsdl:documentation>
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="uploadConsultant">
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="tConsultantFaultMessageException">
<soap:fault name="tConsultantFaultMessageException"/>
</wsdl:fault>
</wsdl:operation>

<wsdl:operation name="findAllConsultants">
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>

</wsdl:binding>


Now see the soap message

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:it="http://www.consultants.com/it">
   <soapenv:Header/>
   <soapenv:Body>
      <it:uploadConsultant>
         <pconsultant eid="122">
            <it:name>nagendra</it:name>
            <!--1 to 2 repetitions:-->
            <it:email>nagen@gmail.com</it:email>
            <it:mobile>
               <it:color>red</it:color>
               <it:price>122</it:price>
               <it:vendor>samsung</it:vendor>
            </it:mobile>
            <it:age>23</it:age>
            <!--Optional:-->
            <it:address>delhi</it:address>
            <!--Optional:-->
            <it:gender>male</it:gender>
            <it:designation>software engineer</it:designation>
            <!--Optional:-->
            <it:photo>cid:1079579450526</it:photo>
         </pconsultant>
      </it:uploadConsultant>
   </soapenv:Body>

</soapenv:Envelope>

WS-I - Web Service Interoperability compliance  

----------------------------------------------------------------------------------------------------------
RPC is not WS-I - Web Service Interoperability compliance
RPC/literal 
RPC/encode (Not supported by JAX-WS 2.x)

DOCUEMNT is  WS-I - Web Service Interoperability compliance
Docuement/literal (Default)
Docuement/encode (Not supported by JAX-WS 2.x)


WSDL for RPC....
<!-- consultantRequest pconsultant; -->
<wsdl:message name="wconsultantRequest">
<wsdl:part name="pconsultant" type="tns:Consultant" />
</wsdl:message>
<wsdl:message name="wconsultantResponse">
<wsdl:part name="presponse" type="xsd:string" />
</wsdl:message>

<wsdl:message name="wvoidRequest">
<wsdl:part name="voidInput" type="tns:voidInput" />
</wsdl:message>

<wsdl:message name="wallConsultantsResponse">
<wsdl:part name="presponse" type="tns:AllConsultants" />

</wsdl:message>




No comments:

Post a Comment