uCosminexus Application Server, Web Service Development Guide

[Contents][Glossary][Index][Back][Next]

35.3.1 Creating a WSDL file

Create a WSDL file and define the meta-information of the Web Service. Define the WSDL definitions within the range specified in the following specifications:

There are two methods for creating a WSDL file. a) Create a new WSDL file or b) Create a WSDL file by converting the Java source.

Organization of this subsection
(1) Creating a new WSDL file
(2) Creating a WSDL file by converting the Java source

(1) Creating a new WSDL file

Create a WSDL file (input.wsdl). The created WSDL file is stored in the c:\temp\jaxws\works\wsrm\server\WEB-INF\wsdl\ directory in the UTF-8 format.

The following is an example for creating a WSDL file for SOAP 1.1:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="TestJaxWsService"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
  xmlns:tns="http://example.com/sample"
  targetNamespace="http://example.com/sample">
  
  <wsdl:types>
    <xsd:schema targetNamespace="http://example.com/sample">
      <!-- wrapper element of the request message -->
      <xsd:element name="jaxWsTest1" type="tns:jaxWsTest1"/>
      
      <!-- wrapper element of the response message -->
      <xsd:element name="jaxWsTest1Response" type="tns:jaxWsTest1Response"/>
      
      <!-- wrapper element of the fault message -->
      <xsd:element name="UserDefinedFault" type="tns:UserDefinedFault"/>
      
      <!-- Type referenced by the wrapper element of the request message -->
      <xsd:complexType name="jaxWsTest1">
        <xsd:sequence>
          <xsd:element name="information" type="xsd:string"/>
          <xsd:element name="count" type="xsd:int"/>
        </xsd:sequence>
      </xsd:complexType>
      
 
      <!-- Type referenced by the wrapper element of the response message -->
      <xsd:complexType name="jaxWsTest1Response">
        <xsd:sequence>
          <xsd:element name="return" type="xsd:string"/>
        </xsd:sequence>
      </xsd:complexType>
      
      <!-- Type referenced by the wrapper element of the fault message -->
      <xsd:complexType name="UserDefinedFault">
        <xsd:sequence>
          <xsd:element name="additionalInfo" type="xsd:int"/>
          <xsd:element name="detail" type="xsd:string"/>
          <xsd:element name="message" type="xsd:string"/>
        </xsd:sequence>
      </xsd:complexType>
    </xsd:schema>
  </wsdl:types>
 
  <!-- Request message -->
  <wsdl:message name="jaxWsTest1Request">
    <wsdl:part name="inputParameters" element="tns:jaxWsTest1"/>
  </wsdl:message>
 
  <!-- Response message -->
  <wsdl:message name="jaxWsTest1Response">
    <wsdl:part name="outputParameters" element="tns:jaxWsTest1Response"/>
  </wsdl:message>
 
  <!-- Fault message -->
  <wsdl:message name="UserDefinedException">
    <wsdl:part name="fault" element="tns:UserDefinedFault"/>
  </wsdl:message>
 
  <!-- Port type -->
  <wsdl:portType name="TestJaxWs">
    <!-- Operation -->
    <wsdl:operation name="jaxWsTest1">
      <wsdl:input message="tns:jaxWsTest1Request"/>
      <wsdl:output message="tns:jaxWsTest1Response"/>
      <wsdl:fault name="UserDefinedFault" 
        message="tns:UserDefinedException"/>
    </wsdl:operation>
  </wsdl:portType>
 
<!-- Binding (SOAP 1.1/HTTP binding) -->
<wsdl:binding name="testJaxWsBinding" type="tns:TestJaxWs">
  <!-- document/literal/wrapped -->
  <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <!-- Operation -->
    <wsdl:operation name="jaxWsTest1">
      <soap:operation/>
      <wsdl:input>
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal"/>
      </wsdl:output>
      <wsdl:fault name="UserDefinedFault">
        <soap:fault name="UserDefinedFault" use="literal"/>
      </wsdl:fault>
    </wsdl:operation>
  </wsdl:binding>
 
  <!-- Service -->
  <wsdl:service name="TestJaxWsService">
    <!-- Port -->
    <wsdl:port name="testJaxWs" binding="tns:testJaxWsBinding">
      <soap:address location="http://webhost:8085/wsrm/TestJaxWsService"/>
    </wsdl:port>
  </wsdl:service>
 
</wsdl:definitions>
 

The following is an example for creating a WSDL file for SOAP 1.2:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="TestJaxWsService"
  xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
  xmlns:tns="http://example.com/sample"
  targetNamespace="http://example.com/sample">
  
  <wsdl:types>
    <xsd:schema targetNamespace="http://example.com/sample">
      <!-- wrapper element of the request message -->
      <xsd:element name="jaxWsTest1" type="tns:jaxWsTest1"/>
      
      <!-- wrapper element of the response message -->
      <xsd:element name="jaxWsTest1Response" type="tns:jaxWsTest1Response"/>
      
      <!-- wrapper element of the fault message -->
      <xsd:element name="UserDefinedFault" type="tns:UserDefinedFault"/>
      
      <!-- wrapper element of the fault message -->
      <xsd:complexType name="jaxWsTest1">
        <xsd:sequence>
          <xsd:element name="information" type="xsd:string"/>
          <xsd:element name="count" type="xsd:int"/>
        </xsd:sequence>
      </xsd:complexType>
      
      <!-- Type referenced by the wrapper element of the response message -->
      <xsd:complexType name="jaxWsTest1Response">
        <xsd:sequence>
          <xsd:element name="return" type="xsd:string"/>
        </xsd:sequence>
      </xsd:complexType>
      
      <!-- Type referenced by the wrapper element of the fault message -->
      <xsd:complexType name="UserDefinedFault">
        <xsd:sequence>
          <xsd:element name="additionalInfo" type="xsd:int"/>
          <xsd:element name="detail" type="xsd:string"/>
          <xsd:element name="message" type="xsd:string"/>
        </xsd:sequence>
      </xsd:complexType>
    </xsd:schema>
  </wsdl:types>
 
  <!-- Request message -->
  <wsdl:message name="jaxWsTest1Request">
    <wsdl:part name="inputParameters" element="tns:jaxWsTest1"/>
  </wsdl:message>
 
  <!-- Response message -->
  <wsdl:message name="jaxWsTest1Response">
    <wsdl:part name="outputParameters" element="tns:jaxWsTest1Response"/>
  </wsdl:message>
 
  <!-- Fault message -->
  <wsdl:message name="UserDefinedException">
    <wsdl:part name="fault" element="tns:UserDefinedFault"/>
  </wsdl:message>
 
  <!-- Port type -->
 
  <wsdl:portType name="TestJaxWs">
    <!-- Operation -->
    <wsdl:operation name="jaxWsTest1">
      <wsdl:input message="tns:jaxWsTest1Request"/>
      <wsdl:output message="tns:jaxWsTest1Response"/>
      <wsdl:fault name="UserDefinedFault" 
        message="tns:UserDefinedException"/>
    </wsdl:operation>
  </wsdl:portType>
 
<!-- Binding (SOAP 1.2/HTTP binding) -->
<wsdl:binding name="testJaxWsBinding" type="tns:TestJaxWs">
  <!-- document/literal/wrapped -->
  <soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <!-- Operation -->
    <wsdl:operation name="jaxWsTest1">
      <soap12:operation/>
      <wsdl:input>
        <soap12:body use="literal"/>
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal"/>
      </wsdl:output>
      <wsdl:fault name="UserDefinedFault">
        <soap12:fault name="UserDefinedFault" use="literal"/>
      </wsdl:fault>
    </wsdl:operation>
  </wsdl:binding>
 
  <!-- Service -->
  <wsdl:service name="TestJaxWsService">
    <!-- Port -->
    <wsdl:port name="testJaxWs" binding="tns:testJaxWsBinding">
      <soap12:address location="http://webhost:8085/wsrm/TestJaxWsService"/>
    </wsdl:port>
  </wsdl:service>
 
</wsdl:definitions>

(2) Creating a WSDL file by converting the Java source

Create a Web Service Implementation Class and an exception class to be temporarily implemented for the WSDL conversion, and execute the WSDL generation functionality of the cjwsgen command to create a WSDL file from the already compiled Java source. Annotate the created class by using the javax.jws.WebService annotation. When using SOAP 1.2, annotate with the javax.xml.ws.BindingType annotation in which SOAP 1.2 is specified additionally. You need not implement any method.

The source code for the temporarily implemented Web Service Implementation Class and TestJaxWsService.wsdl differs depending on whether you use SOAP 1.1 or SOAP 1.2.

The following is an example of the temporarily implemented Web Service Implementation Class when SOAP 1.1 is used.

package com.example.sample;
 
@javax.jws.WebService
public class TestJaxWsImpl {
 
    public String jaxWsTest1(String information, int count)
        throws UserDefinedException
    {
        // Need not be implemented
        return null;
    }
 
}

The following is an example of the temporarily implemented Web Service Implementation Class when SOAP 1.2 is used.

package com.example.sample;
 
@javax.jws.WebService
@javax.xml.ws.BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
public class TestJaxWsImpl {
 
    public String jaxWsTest1(String information, int count)
        throws UserDefinedException
    {
        // Need not be implemented
        return null;
    }
 
}

The following is an example of the temporarily implemented exception class:

 
package com.example.sample;
 
public class UserDefinedFault extends Exception{
    // Need not be implemented
    public int additionalInfo;
    public String detail;
    public String message;
}

Save and compile the created TestJaxWsImpl.java and UserDefinedFault.java in the c:\temp\jaxws\works\wsrm\server\temporary\src\com\example\sample\ directory in the UTF-8 format.

The following is an example of compilation:

> cd c:\temp\jaxws\works\wsrm\server\
> mkdir .\temporary
> mkdir .\temporary\classes
> javac -encoding UTF-8 -cp "%COSMINEXUS_HOME%\jaxws\lib\cjjaxws.jar;%COSMINEXUS_HOME%\CC\client\lib\j2ee-javax.jar" -d .\temporary\classes .\temporary\src\com\example\sample\TestJaxWsImpl.java .\temporary\src\com\example\sample\UserDefinedFault.java

On successful compilation, the TestJaxWsImpl.class and UserDefinedFault.class files are generated in the c:\temp\jaxws\works\wsrm\server\temporary\classes\com\example\sample\ directory. Use these class files and create a WSDL file by using the WSDL generation functionality of the cjwsgen command.

The following is an example for executing the cjwsgen command:

> cd c:\temp\jaxws\works\wsrm\server\
> mkdir .\WEB-INF\wsdl\
> "%COSMINEXUS_HOME%\jaxws\bin\cjwsgen.bat" -r .\WEB-INF\wsdl -d .\temporary\classes -cp .\temporary\classes com.example.sample.TestJaxWsImpl

On successful termination of the cjwsgen command, TestJaxWsService.wsdl and TestJaxWsService_schema1.xsd are generated in the c:\temp\jaxws\works\wsrm\WEB-INF\wsdl\ directory. Delete the classes from the c:\temp\jaxws\works\wsrm\temporary\classes\ directory.

You must partially modify the generated TestJaxWsService.wsdl and TestJaxWsService_schema1.xsd.

The following is an example for modifying TestJaxWsService.wsdl when SOAP 1.1 is used. The parts in Italics indicate modifications.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions targetNamespace="http://example.com/sample" name="TestJaxWsImplService" xmlns:tns="http://example.com/sample" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/">
  <types>
    <xsd:schema targetNamespace="http://example.com/sample">
      <xsd:include schemaLocation="TestJaxWsImplService_schema1.xsd"/>
    </xsd:schema>
  </types>
  <message name="jaxWsTest1">
    <part name="parameters" element="tns:jaxWsTest1"/>
  </message>
  <message name="jaxWsTest1Response">
    <part name="parameters" element="tns:jaxWsTest1Response"/>
  </message>
  <message name="UserDefinedFault">
    <part name="fault" element="tns:UserDefinedFault"/>
  </message>
  <portType name="TestJaxWs">
    <operation name="jaxWsTest1">
      <input message="tns:jaxWsTest1"/>
      <output message="tns:jaxWsTest1Response"/>
      <fault message="tns:UserDefinedFault" name="UserDefinedFault"/>
    </operation>
  </portType>
  <binding name="testJaxWsBinding" type="tns:TestJaxWs">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
    <operation name="jaxWsTest1">
      <soap:operation soapAction=""/>
      <input>
        <soap:body use="literal"/>
      </input>
      <output>
        <soap:body use="literal"/>
      </output>
      <fault name="UserDefinedFault">
        <soap:fault name="UserDefinedFault" use="literal"/>
      </fault>
    </operation>
  </binding>
  <service name="TestJaxWsService">
    <port name="testJaxWs" binding="tns:testJaxWsBinding">
      <soap:address location="http://webhost:8085/wsrm/TestJaxWsService"/>
    </port>
  </service>
</definitions>

The following is an example for modifying TestJaxWsService.wsdl when SOAP 1.2 is used. The parts in Italics indicate modifications.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions targetNamespace="http://example.com/sample" name="TestJaxWsImplService" xmlns:tns="http://example.com/sample" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns="http://schemas.xmlsoap.org/wsdl/">
  <types>
    <xsd:schema targetNamespace="http://example.com/sample">
      <xsd:include schemaLocation="TestJaxWsImplService_schema1.xsd"/>
    </xsd:schema>
  </types>
  <message name="jaxWsTest1">
    <part name="parameters" element="tns:jaxWsTest1"/>
  </message>
  <message name="jaxWsTest1Response">
    <part name="parameters" element="tns:jaxWsTest1Response"/>
  </message>
  <message name="UserDefinedFault">
    <part name="fault" element="tns:UserDefinedFault"/>
  </message>
  <portType name="TestJaxWs">
    <operation name="jaxWsTest1">
      <input message="tns:jaxWsTest1"/>
      <output message="tns:jaxWsTest1Response"/>
      <fault message="tns:UserDefinedFault" name="UserDefinedFault"/>
    </operation>
  </portType>
  <binding name="testJaxWsBinding" type="tns:TestJaxWs">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
    <operation name="jaxWsTest1">
      <soap12:operation soapAction=""/>
      <input>
        <soap12:body use="literal"/>
      </input>
      <output>
        <soap12:body use="literal"/>
      </output>
      <fault name="UserDefinedFault">
        <soap12:fault name="UserDefinedFault" use="literal"/>
      </fault>
    </operation>
  </binding>
  <service name="TestJaxWsService">
    <port name="testJaxWs" binding="tns:testJaxWsBinding">
      <soap12:address location="http://webhost:8085/wsrm/TestJaxWsService"/>
    </port>
  </service>
</definitions>

The following is an example for modifying the TestJaxWsService_schema1.xsd. The parts in Italics indicate modifications.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="http://example.com/sample" xmlns:tns="http://example.com/sample" xmlns:xs="http://www.w3.org/2001/XMLSchema">
 
  <xs:element name="UserDefinedFault" type="tns:UserDefinedFault"/>
 
  <xs:element name="jaxWsTest1" type="tns:jaxWsTest1"/>
 
  <xs:element name="jaxWsTest1Response" type="tns:jaxWsTest1Response"/>
 
  <xs:complexType name="jaxWsTest1">
    <xs:sequence>
      <xs:element name="arg0" type="xs:string" minOccurs="0"/>
      <xs:element name="arg1" type="xs:int"/>
    </xs:sequence>
  </xs:complexType>
 
  <xs:complexType name="jaxWsTest1Response">
    <xs:sequence>
      <xs:element name="return" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
 
  <xs:complexType name="UserDefinedFault">
    <xs:sequence>
      <xs:element name="message" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

Change the name of the modified TestJaxWsService.wsdl file to input.wsdl, and save the file in the c:\temp\jaxws\works\wsrm\server\WEB-INF\wsdl\ directory.