uCosminexus Application Server, Web Service Development Guide

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

4.3.1 Creating a WSDL file

Create a WSDL file and define the meta data for Web Services. Define the WSDL definition within the support range of the following specifications:

There are two methods for creating a WSDL file; create a new WSDL file or create a WSDL file by using other WSDL file and changing the Java source.

Organization of this subsection
(1) Creating a new WSDL file
(2) Creating a WSDL file based on the WSDL file in which the Java source is converted

(1) Creating a new WSDL file

Create a WSDL file (input.wsdl). Save the created WSDL file in the c:\temp\jaxws\works\fromwsdl\server\WEB-INF\wsdl\ directory with the UTF-8 format.

The following is an example of creating a new 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/fromwsdl/TestJaxWsService"/>
 </wsdl:port>
 </wsdl:service>
 
</wsdl:definitions>
 

The following is an example of creating a new 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"/>
      
      <!-- 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.2/HTTP binding) -->
  <wsdl:binding name="testJaxWsBinding" type="tns:TestJaxWs">
    <!-- document/literal/wrapped -->
    <soap12:binding style="document" transport="http://www.w3.org/2003/05/soap/bindings/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/fromwsdl/TestJaxWsService"/>
    </wsdl:port>
  </wsdl:service>
 
</wsdl:definitions>

(2) Creating a WSDL file based on the WSDL file in which the Java source is converted

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. Use the javax.jws.WebService annotation to specify the annotations for the created class. You need not implement any method.

The following is an example of the temporarily implemented Web Service Implementation Class:

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 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 classes TestJaxWsImpl.java and UserDefinedFault.java to the c:\temp\jaxws\works\fromwsdl\server\temporary\src\com\example\sample\ directory with the UTF-8 format. The following is an compilation example:

> cd c:\temp\jaxws\works\fromwsdl\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

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

The following is an example for executing the cjwsgen command:

> cd c:\temp\jaxws\works\fromwsdl\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

If the cjwsgen command is successfully terminated, TestJaxWsService.wsdl and TestJaxWsService_schema1.xsd are generated in the c:\temp\jaxws\works\fromwsdl\WEB-INF\wsdl\ directory. Delete the classes that exist in the c:\temp\jaxws\works\fromwsdl\temporary\classes\ directory.

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

The following is an example of modifying TestJaxWsService.wsdl. The text in italics indicates the modified part.

<?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/fromwsdl/TestJaxWsService"/>
    </port>
  </service>
</definitions>

The following is an example of modifying TestJaxWsService_schema1.xsd. The text in italics indicates the modified part.

<?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 to input.wsdl, and save under the c:\temp\jaxws\works\fromwsdl\server\WEB-INF\wsdl\ directory.