...

All | Personal | Sun
« JAX-WS 2.0, an Hello... | メイン | Import Client's cert... »
20060224 2006年 2月 24日 金曜日

JAX-WS 2.0 Java<===>WSDL1.1 mappings (written in Japanese) JAX-WS 2.0 Java<===>WSDL1.1 mappings (written in Japanese)

別のスレッドで書いたサンプルをいじって(文章が中国語となってますが、クラスやコマンドが化けないと思うが)、Java<===>WSDL1.1のマッピングをみていきたいと思います。

まず、List1を使って、annotationsのWebServiceとWebMethodの属性のデフォルト値を確認します。Glassfishに提供されているwsgenを使って、WSDLファイル(List2)を生成します。

List 1 (HelloWorld.java)
@WebService()   
public class HelloWorld{
    
    //the implementation class must have a default public constructor
    public HelloWorld() {};

    @WebMethod()
    public String sayHello(String name){
  	return "Hello "+ name + "!";
    }
}

List 2 (HelloWorldService.wsdl)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions targetNamespace="http://endpoint/" name="HelloWorldService" xmlns:tns="http://endpoint/" 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>
<xsd:import namespace="http://endpoint/" schemaLocation="HelloWorldService_schema1.xsd"/>
</xsd:schema>
</types>
<message name="sayHello">
<part name="parameters" element="tns:sayHello"/>
</message>
<message name="sayHelloResponse">
<part name="parameters" element="tns:sayHelloResponse"/>
</message>
<portType name="HelloWorld">
<operation name="sayHello">
<input message="tns:sayHello"/>
<output message="tns:sayHelloResponse"/>
</operation>
</portType>
<binding name="HelloWorldPortBinding" type="tns:HelloWorld">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="sayHello">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="HelloWorldService">
<port name="HelloWorldPort" binding="tns:HelloWorldPortBinding">
<soap:address location="REPLACE_WITH_ACTUAL_URL"/>
</port>
</service>
</definitions>

クラスHelloWorldがportTypeのnameに、メソッド名sayHelloがportTypeの子要素operationの名前にそれぞれとマッピングされているのが分かります。

ここで、annotationsのWebService、WebMethodの属性を指定して(List 3)、List 4のWSDLが生成されます。


List 3 (HelloWorld.java 修正バージョン)
@WebService(
    name="MyHelloWorld",
    serviceName="MyHelloWorldService",
    targetNamespace="http://javaee5.com/jaxws/helloworld"
)   
public class HelloWorld{
    
    //the implementation class must have a default public constructor
    public HelloWorld() {};

    @WebMethod(operationName="mySayHello", action="urn:mySayHello")
    public String sayHello(String name){
	return "Hello "+ name + "!";
    }
}

List 4 (MyHelloWorldService.wsdl)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions
targetNamespace="http://javaee5.com/jaxws/helloworld"
name="MyHelloWorldService"
xmlns:tns="http://javaee5.com/jaxws/helloworld"
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>
<xsd:import namespace="http://javaee5.com/jaxws/helloworld" schemaLocation="MyHelloWorldService_schema1.xsd"/>
</xsd:schema>
</types>
<message name="mySayHello">
<part name="parameters" element="tns:mySayHello"/>
</message>
<message name="mySayHelloResponse">
<part name="parameters" element="tns:mySayHelloResponse"/>
</message>
<portType name="MyHelloWorld">
<operation name="mySayHello">
<input message="tns:mySayHello"/>
<output message="tns:mySayHelloResponse"/>
</operation>
</portType>
<binding name="MyHelloWorldPortBinding" type="tns:MyHelloWorld">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document"/>
<operation name="mySayHello">
<soap:operation soapAction="urn:mySayHello"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="MyHelloWorldService">
<port name="MyHelloWorldPort" binding="tns:MyHelloWorldPortBinding">
<soap:address location="REPLACE_WITH_ACTUAL_URL"/>
</port>
</service>
</definitions>

グラフ1にマッピング関係を示しています。

グラフ 1

ここで見た例はstyle/useに関して暗黙でDocument/Literalが使用されますが、

List 5 (SOAPBindingの指定)
@WebService
@SOAPBinding(style=SOAPBinding.Style.RPC, use=SOAPBinding.Use.ENCODED)
public class HelloWorld{
//the implementation class must have a default public constructor
public HelloWorld() {};     @WebMethod(operationName="mySayHello",          action="urn:mySayHello")
public String sayHello(String name){
return "Hello "+ name + "!";
}
}

List 5のようにSOAPBinding属性の指定を通して、RPC/Encodedに変えられます。

他にも、Oneway、WebParamなどがありますので、用途に応じてカスタマイズできます。

 

Posted by xiaojun ( 2月 24日 2006年, 09:18:16 午後 JST ) Permalink 投稿されたコメント [1]

Trackback URL: http://blogs.sun.com/xiaojun/entry/jax_ws_2_0_java
投稿されたコメント:

cool

Posted by wow gold on 11月月 03日, 2008年 at 10:37 午前 JST #

コメント

名前
メール
URL

投稿されたコメント

HTML文法 不許可

Calendar

RSS Feeds

Search

Links

Navigation

Referers