Search code examples
web-servicessoapwsdljax-ws

SOAP message using namespaces


We are designing a Web application which is invoked by an external system. We are going to receive a Web service from an external system which looks like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tis="http://schemas.tis.com/1.2/" xmlns:der="http://schemas.tis.com/DataProvisioning/">
   <soapenv:Header>
      <tis:SessionId>99999999</tis:SessionId>
   </soapenv:Header>
 <soapenv:Body>
  <tis:Create>
     <tis:MOType>SPPM@http://schemas.tis.com/DataProvisioning/</tis:MOType>
     <tis:MOId>
           <der:codex>12345677</der:msisdn>
     </tis:MOId>

     <tis:MOAttributes>
        <der:createSPDD ProfileID="1"  Action="createData">

           <der:TechProduct Action="add" BarCode="15">
            <der:Arguments ArgName="arg1" ArgType="string" ArgValue="1"></der:Arguments>
            <der:Arguments ArgName="arg3" ArgType="string" ArgValue="2"></der:Arguments>
           </der:TechProduct>
           <der:TechProduct Action="delete" BarCode="21">
            <der:Arguments ArgName="arg1" ArgType="string" ArgValue="1"></der:Arguments>
            <der:Arguments ArgName="arg3" ArgType="string" ArgValue="2"></der:Arguments>
           </der:TechProduct>
        </der:createSPDD>
     </tis:MOAttributes>
  </tis:Create>

As you can see this SOAP Envelope we will receive contains namespaces in it. Up to now my Web services applications have been coded using JAX-WS and bottom-up approach (just adding @WebService and @WebMethod annotation to classes). What is the correct way to design a Web service that needs to receive a message based on namespaces ? Should I design first the WSDL ? I cannot see how to collect attributes which are in the Header or Body such as MoType or MoId. Any help ?
Thanks a lot


Solution

  • From your question it is tough to understand whether you want to expose a web service or you want to consume one. If you want to expose a web service with this structure and namespace you can choose bottom-up or top-down approach. Using top-down approach you will create

    1. WSDL (here clearly you can mention the namespace for the service related details)
    2. Schema (define the namespace for request and response elements)
    3. Generate the Java classes from the WSDL and Schema.
    4. Write the implementation for the Web Service interface.

    If at all you want to consume the service then no need to write any WSDL. Get the WSDL and Schema(if any) from the service provider, Generate the Java classes from the WSDL and Schema received. You dont have worry about reading the values based on namespaces, the jaxws framework will do it for you.

    Google the steps to consume a jaxws service.