35.3.1 WSDLファイルを作成する
WSDLファイルを作成し,Webサービスのメタ情報を定義します。WSDL定義は,次の仕様のサポート範囲内で定義してください。
-
WSDL 1.1仕様
サポート範囲については,「20.1 WSDL 1.1仕様のサポート範囲」を参照してください。
-
XML Schema仕様
サポート範囲については,マニュアル「XML Processor ユーザーズガイド」を参照してください。
-
WS-I Basic Profile 1.1仕様
WSDLファイルの作成方法には,新規に作成する方法と,Javaソースを変換したものを利用して作成する方法の2種類があります。
(1) 新規にWSDLファイルを作成する
ここでは,WSDLファイル(input.wsdl)を作成します。作成したWSDLファイルは,UTF-8形式でc:\temp\jaxws\works\wsrm\server\WEB-INF\wsdl\ディレクトリに保存してください。
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要素 -->
<xsd:element name="jaxWsTest1" type="tns:jaxWsTest1"/>
<!-- 応答メッセージの wrapper要素 -->
<xsd:element name="jaxWsTest1Response" type="tns:jaxWsTest1Response"/>
<!-- フォルトメッセージの wrapper要素 -->
<xsd:element name="UserDefinedFault" type="tns:UserDefinedFault"/>
<!-- 要求メッセージの wrapper要素が参照する型 -->
<xsd:complexType name="jaxWsTest1">
<xsd:sequence>
<xsd:element name="information" type="xsd:string"/>
<xsd:element name="count" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
<!-- 応答メッセージの wrapper要素が参照する型 -->
<xsd:complexType name="jaxWsTest1Response">
<xsd:sequence>
<xsd:element name="return" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<!-- フォルトメッセージの wrapper要素が参照する型 -->
<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>
<!-- 要求メッセージ -->
<wsdl:message name="jaxWsTest1Request">
<wsdl:part name="inputParameters" element="tns:jaxWsTest1"/>
</wsdl:message>
<!-- 応答メッセージ -->
<wsdl:message name="jaxWsTest1Response">
<wsdl:part name="outputParameters" element="tns:jaxWsTest1Response"/>
</wsdl:message>
<!-- フォルトメッセージ -->
<wsdl:message name="UserDefinedException">
<wsdl:part name="fault" element="tns:UserDefinedFault"/>
</wsdl:message>
<!-- ポートタイプ -->
<wsdl:portType name="TestJaxWs">
<!-- オペレーション -->
<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>
<!-- バインディング(SOAP 1.1/HTTPバインディング) -->
<wsdl:binding name="testJaxWsBinding" type="tns:TestJaxWs">
<!-- document/literal/wrapped -->
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<!-- オペレーション -->
<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>
<!-- サービス -->
<wsdl:service name="TestJaxWsService">
<!-- ポート -->
<wsdl:port name="testJaxWs" binding="tns:testJaxWsBinding">
<soap:address location="http://webhost:8085/wsrm/TestJaxWsService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>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要素 -->
<xsd:element name="jaxWsTest1" type="tns:jaxWsTest1"/>
<!-- 応答メッセージの wrapper要素 -->
<xsd:element name="jaxWsTest1Response" type="tns:jaxWsTest1Response"/>
<!-- フォルトメッセージの wrapper要素 -->
<xsd:element name="UserDefinedFault" type="tns:UserDefinedFault"/>
<!-- 要求メッセージの wrapper要素が参照する型 -->
<xsd:complexType name="jaxWsTest1">
<xsd:sequence>
<xsd:element name="information" type="xsd:string"/>
<xsd:element name="count" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
<!-- 応答メッセージの wrapper要素が参照する型 -->
<xsd:complexType name="jaxWsTest1Response">
<xsd:sequence>
<xsd:element name="return" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<!-- フォルトメッセージの wrapper要素が参照する型 -->
<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>
<!-- 要求メッセージ -->
<wsdl:message name="jaxWsTest1Request">
<wsdl:part name="inputParameters" element="tns:jaxWsTest1"/>
</wsdl:message>
<!-- 応答メッセージ -->
<wsdl:message name="jaxWsTest1Response">
<wsdl:part name="outputParameters" element="tns:jaxWsTest1Response"/>
</wsdl:message>
<!-- フォルトメッセージ -->
<wsdl:message name="UserDefinedException">
<wsdl:part name="fault" element="tns:UserDefinedFault"/>
</wsdl:message>
<!-- ポートタイプ -->
<wsdl:portType name="TestJaxWs">
<!-- オペレーション -->
<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>
<!-- バインディング(SOAP 1.2/HTTPバインディング) -->
<wsdl:binding name="testJaxWsBinding" type="tns:TestJaxWs">
<!-- document/literal/wrapped -->
<soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<!-- オペレーション -->
<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>
<!-- サービス -->
<wsdl:service name="TestJaxWsService">
<!-- ポート -->
<wsdl:port name="testJaxWs" binding="tns:testJaxWsBinding">
<soap12:address location="http://webhost:8085/wsrm/TestJaxWsService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
(2) Javaソースを変換したものを基にWSDLファイルを作成する
ここでは,WSDL変換用に仮実装のWebサービス実装クラスと例外クラスを作成し,hwsgenコマンドのWSDL生成機能を実行して,コンパイル済みのJavaソースからWSDLファイルを作成します。作成したクラスは,javax.jws.WebServiceアノテーションでアノテートします。SOAP 1.2を使用する場合,さらにSOAP 1.2を指定したjavax.xml.ws.BindingTypeアノテーションでアノテートしてください。メソッドを実装する必要はありません。
SOAP 1.1を使用する場合とSOAP 1.2を使用する場合では,仮実装のWebサービス実装クラスとTestJaxWsService.wsdlでソースコードが異なります。
SOAP 1.1の場合の仮実装のWebサービス実装クラスの例を次に示します。
package com.example.sample;
@javax.jws.WebService
public class TestJaxWsImpl {
public String jaxWsTest1(String information, int count)
throws UserDefinedException
{
// 実装不要
return null;
}
}SOAP 1.2の場合の仮実装のWebサービス実装クラスの例を次に示します。
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
{
// 実装不要
return null;
}
}仮実装の例外クラスの例を次に示します。
package com.example.sample;
public class UserDefinedFault extends Exception{
// 実装不要
public int additionalInfo;
public String detail;
public String message;
}作成したTestJaxWsImpl.javaとUserDefinedFault.javaをUTF-8形式でc:\temp\jaxws\works\wsrm\server\temporary\src\com\example\sample\ディレクトリに保存し,コンパイルします。コンパイルの例を次に示します。
> 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\javaee\1100\lib\javaee-api.jar" -d .\temporary\classes .\temporary\src\com\example\sample\TestJaxWsImpl.java .\temporary\src\com\example\sample\UserDefinedFault.java
コンパイルが正常に終了すると,c:\temp\jaxws\works\wsrm\server\temporary\classes\com\example\sample\ディレクトリにTestJaxWsImpl.classとUserDefinedFault.classが生成されます。これらのクラスファイルを利用して,hwsgenコマンドのWSDL生成機能でWSDLファイルを作成します。
hwsgenコマンドの実行例を次に示します。
> cd c:\temp\jaxws\works\wsrm\server\ > mkdir .\WEB-INF\wsdl\ > "%COSMINEXUS_HOME%\jaxws\bin\hwsgen.bat" -r .\WEB-INF\wsdl -d .\temporary\classes -cp .\temporary\classes com.example.sample.TestJaxWsImpl
hwsgenコマンドが正常に終了すると,c:\temp\jaxws\works\wsrm\WEB-INF\wsdl\ディレクトリにTestJaxWsService.wsdlとTestJaxWsService_schema1.xsdが生成されます。c:\temp\jaxws\works\wsrm\temporary\classes\ディレクトリにあるクラスは削除してください。
生成されたTestJaxWsService.wsdlとTestJaxWsService_schema1.xsdは,一部修正する必要があります。
SOAP 1.1の場合のTestJaxWsService.wsdlの修正例を次に示します。イタリック体になっている個所が,修正した個所です。
<?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>SOAP 1.2の場合のTestJaxWsService.wsdlの修正例を次に示します。イタリック体になっている個所が,修正した個所です。
<?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>TestJaxWsService_schema1.xsdの修正例を次に示します。イタリック体になっている個所が,修正した個所です。
<?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>修正したTestJaxWsService.wsdlは,名前をinput.wsdlに変更して,c:\temp\jaxws\works\wsrm\server\WEB-INF\wsdl\ディレクトリに保存してください。