Tuesday, 8 December 2015

Original WSDL is not published in SOAP METRO Web Service

http://www.gpsprogramys.co.in/com.gps.quiz/programService?wsdl
Note : When I was putting WSDL inside webapp folder wsdl/ then original WSDL was not published


Solution :
Please keep WSDL and XSD inside the WEB-INF folder shown as below....



http://www.gpsprogramys.co.in/com.gps.quiz/programService?wsdl

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"xmlns:tns="http://www.service.gps.com/model" name="ProgramsService" targetNamespace="http://www.service.gps.com/model">
<wsdl:types>
<xsd:schema>
<xsd:import namespace="http://www.service.gps.com/model" schemaLocation="http://localhost:5050/com.gps.quiz/programService?xsd=1"/>
</xsd:schema>
</wsdl:types>
<!--
class AddProgramRequest{ addProgramRequest addProgramInput; }
-->
<wsdl:message name="AddProgramRequest">
<wsdl:part name="addProgramInput" element="tns:addProgramRequest"/>
</wsdl:message>
<wsdl:message name="AddProgramResponse">
<wsdl:part name="return" element="tns:addProgramResponse"/>
</wsdl:message>
<wsdl:message name="FindProgramsRequest">
<wsdl:part name="FindProgramsInput" element="tns:findProgramsRequest"/>
</wsdl:message>
<wsdl:message name="FindProgramsResponse">
<wsdl:part name="return" element="tns:findProgramsResponse"/>
</wsdl:message>
<wsdl:portType name="ProgramService">
<wsdl:operation name="addProgram">
<wsdl:input message="tns:AddProgramRequest"/>
<wsdl:output message="tns:AddProgramResponse"/>
</wsdl:operation>
<wsdl:operation name="findPrograms">
<wsdl:input message="tns:FindProgramsRequest"/>
<wsdl:output message="tns:FindProgramsResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ProgramServiceBinding" type="tns:ProgramService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="addProgram">
<wsdl:documentation>protocol and style used to invoke this method</wsdl:documentation>
<!-- it is showing intension of the web service -->
<soap:operation soapAction="http://www.service.gps.com/model/addProgram"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="findPrograms">
<wsdl:documentation>protocol and style used to invoke this method</wsdl:documentation>
<!-- it is showing intension of the web service -->
<soap:operation soapAction="http://www.service.gps.com/model/findPrograms"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ProgramSoapService">
<wsdl:port name="ProgramServicePort" binding="tns:ProgramServiceBinding">
<soap:address location="http://localhost:5050/com.gps.quiz/programService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>



Thursday, 22 October 2015

XSD (XML Schema Definition)

An XML Schema describes the structure of an XML document.

The purpose of an XML Schema is to define the legal building blocks of an XML document, just like a DTD.
An XML Schema:
  • defines elements that can appear in a document
  • defines attributes that can appear in a document
  • defines which elements are child elements
  • defines the order of child elements
  • defines the number of child elements
  • defines whether an element is empty or can include text
  • defines data types for elements and attributes
  • defines default and fixed values for elements and attributes

dog.xsd


<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.consultants.com/it"
xmlns:tns="http://www.consultants.com/it" elementFormDefault="qualified">
<element name="cdogs" type="tns:Dogs"/>
<element name="dogs" type="tns:Dogs"/>
<complexType name="Dogs">
<sequence>
<element name="dog" type="tns:Dog" maxOccurs="5" minOccurs="0"/>
</sequence>
</complexType>
<complexType name="Dog">
<sequence>
    <element name="name" type="string" maxOccurs="1" minOccurs="1"/>
     <element name="age" type="int" maxOccurs="1" minOccurs="1"/>
</sequence>
<attribute  name="color" type="string"  use="required"/>
 <attribute  name="mobile" type="string"  use="required"/>
</complexType>
</schema>









dog.xml

<?xml version="1.0" encoding="UTF-8"?>
<dogs xmlns="http://www.consultants.com/it" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.consultants.com/it dogs.xsd">
   <dog color="red" mobile="939393939">
    <name>name</name>
  <age>11</age>
   </dog>
   
   <dog color="pink"  mobile="93939393">
    <name>name</name>
  <age>22</age>
   </dog>
   
   
   <dog color="blue"  mobile="939393939">
    <name>name</name>
  <age>33</age>
   </dog>
   
   
   <dog color="pink" mobile="939393939">
    <name>name</name>
  <age>44</age>
   </dog>
   
   <dog color="yellow" mobile="939393939">
    <name>name</name>
  <age>55</age>
   </dog>
  
</dogs>


WSDL format for document style

consultants.xsd

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.consultants.com/it"
xmlns:tns="http://www.consultants.com/it" elementFormDefault="qualified">

<include schemaLocation="mobile.xsd"/>
    <!-- instantiating the complex element -->
    <!-- 
    this is global elements 
    global elements  are those elements which acts root element for XML instance doc............
    public String uploadConsutant(Consultant consultantRequest)
    -->
    <element name="consultantRequest" type="tns:Consultant"/>
    <element name="sresponse" type="string"/>
     
      <!-- 
      public AllConsultants" findAllConsultants()
       -->
     <element name="voidinput" type="tns:voidInput"/>
     <element name="AllConsultantsResponse" type="tns:AllConsultants"/>
     
     <element name="ConsultantFaultMessage" type="tns:ConsultantFaultMessage"/>
    
    <complexType name="voidInput">
           <sequence>
           </sequence>
    </complexType>
       
      <!-- This is only definition -->  
    <complexType name="AllConsultants">
    <sequence>
    <element name="consultant" type="tns:Consultant" minOccurs="0" maxOccurs="unbounded">
    <annotation>
<documentation>Consultant recored can be zero or more than zero</documentation>
</annotation>
</element>
    </sequence>
    </complexType>
    

    <!-- Defining complex element -->
<complexType name="Consultant">
<sequence>
<element name="name" type="string" maxOccurs="1" minOccurs="1"/>
   <element name="email" type="string" maxOccurs="2" minOccurs="1"/>
element name="mobile" type="tns:Mobile" maxOccurs="1" minOccurs="1"/>
 <element name="age" type="int" maxOccurs="1" minOccurs="1"/>
     <element name="address" type="string" maxOccurs="1" minOccurs="0"/>
    <element name="gender" type="tns:Gender" maxOccurs="1" minOccurs="0"/>
    <element name="designation" type="string" maxOccurs="1" minOccurs="1" default="software engineer"/>
     <element name="photo" type="base64Binary" maxOccurs="1" minOccurs="0"/>
</sequence>
<attribute name="eid" type="string" use="optional"/>
</complexType>

employee-consultants.wsdl

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.consultants.com/it" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="synergisticit-consultants"
targetNamespace="http://www.consultants.com/it">
<wsdl:types>
<xsd:schema>
<xsd:import namespace="http://www.consultants.com/it"
schemaLocation="consultants.xsd" />
</xsd:schema>
</wsdl:types>
<!-- consultantRequest pconsultant; -->
<wsdl:message name="wconsultantRequest">
<wsdl:part name="pconsultant" element="tns:consultantRequest" />
</wsdl:message>
<wsdl:message name="wconsultantResponse">
<wsdl:part name="presponse" element="tns:sresponse" />
</wsdl:message>

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

<wsdl:message name="wallConsultantsResponse">
<wsdl:part name="presponse" element="tns:AllConsultantsResponse" />
</wsdl:message>


   <wsdl:message name="ConsultantFaultMessageException">
<wsdl:part name="tempFault" element="tns:ConsultantFaultMessage" />
</wsdl:message>


<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 format for rpc style

XSD content :-

  <!-- This is only definition -->
    <complexType name="AllConsultants">
    <sequence>
    <element name="consultant" type="tns:Consultant" minOccurs="0" maxOccurs="unbounded">
    <annotation>
<documentation>Consultant recored can be zero or more than zero</documentation>
</annotation>
</element>
    </sequence>
    </complexType>
   

    <!-- Defining complex element -->
<complexType name="Consultant">
<sequence>
            <element name="name" type="string" maxOccurs="1" minOccurs="1"/>
             <element name="email" type="string" maxOccurs="2" minOccurs="1"/>
    <element name="mobile" type="tns:Mobile" maxOccurs="1" minOccurs="1"/>
    <element name="age" type="int" maxOccurs="1" minOccurs="1"/>
     <element name="address" type="string" maxOccurs="1" minOccurs="0"/>
     <element name="gender" type="tns:Gender" maxOccurs="1" minOccurs="0"/>
    <element name="designation" type="string" maxOccurs="1" minOccurs="1"  default="software engineer"/>
     <element name="photo" type="base64Binary" maxOccurs="1" minOccurs="0"/>
</sequence>
<attribute name="eid" type="string" use="optional"/>
</complexType>


WSDL (employee-consultants.wsdl)

<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.consultants.com/it" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="synergisticit-consultants"
targetNamespace="http://www.consultants.com/it">
<wsdl:types>
<xsd:schema>
<xsd:import namespace="http://www.consultants.com/it"
schemaLocation="consultants.xsd" />
</xsd:schema>
</wsdl:types>
<!-- 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>







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>




What different files are generated by wsimport Command in Soap Web Service


wsimport -keep -verbose  <WSDL>  -Xnocompile

-keep -  > keep java files............
-verbose -> display the files on the console
-Xnocompile -> we do not need classes 

1. ALL JAXB classes(POJO,ObjectFactory,package-info) against your XSD.
  JAXB- Java API for XML Binding

   XML Binding - means conversion of java object into xml and xml into java object

2. Service Endpoint Interface (SEI)
    Interface against PortType define inside WSDL.
    This will  be used to expose the web service to the consumer and consumer can access       the web service using this interface.
    
    This service end point interface will  be used to define/implement the provider in case
    of top down web service.
    


 @WebService(name = "ConsultantWebService", targetNamespace = "http://www.consultants.com/it")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
@XmlSeeAlso({
    ObjectFactory.class
})
public interface ConsultantWebService {


    /**
     * 
     * @param pconsultant
     * @return
     *     returns java.lang.String
     * @throws ConsultantFaultMessageException
     */
    @WebMethod
    @WebResult(name = "sresponse", targetNamespace = "http://www.consultants.com/it", partName = "presponse")
    public String uploadConsultant(
        @WebParam(name = "consultantRequest", targetNamespace = "http://www.consultants.com/it", partName = "pconsultant")
        Consultant pconsultant)
        throws ConsultantFaultMessageException
    ;

}
    

3.  a class with  service name define inside the WSDL

see below WSDL content

<wsdl:service name="ConsultantWebServiceService">
      <wsdl:port name="ConsultantWebServicePort" binding="tns:ConsultantWebServiceBinding">
<soap:address location="http://localhost:5050/soap-mobile-app/consultantProvider"/>            
      </wsdl:port>

</wsdl:service>


ConsultantWebServiceService.class

@WebServiceClient(name = "ConsultantWebServiceService", targetNamespace = "http://www.consultants.com/it", 
wsdlLocation = "file:/D:/NEW_WORKSPACE/workspace_java/soap-mobile-app/src/main/webapp/WEB-INF/wsdl/synergisticit-consultants.wsdl")
public class ConsultantWebServiceService
    extends Service

{

}

This is used by  consumer to consume the web service.....

ConsultantWebServiceService consultantWebServiceService
=new ConsultantWebServiceService();

ConsultantWebService consultantWebService=consultantWebServiceService.getConsultantWebServicePort();