次に示す場合のWSDLの例およびクライアント側の処理の実装例を示します。
WSDLをインポートしない場合のWSDLの例およびDIIのコーディング例を示します。なお,WSDLの例では次の情報が定義されています。
<wsdl:definitions
targetNamespace="http://example.com"
xmlns:intf="http://example.com"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:message name="getLastTradePriceResponse">
<wsdl:part name="getLastTradePriceReturn" type="xsd:int"/>
</wsdl:message>
<wsdl:message name="getLastTradePriceRequest">
<wsdl:part name="in0" type="xsd:string"/>
</wsdl:message>
<wsdl:portType name="StockQuote">
<wsdl:operation name="getLastTradePrice" parameterOrder="in0">
<wsdl:input message="intf:getLastTradePriceRequest" name="getLastTradePriceRequest"/>
<wsdl:output message="intf:getLastTradePriceResponse" name="getLastTradePriceResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="StockQuoteSoapBinding" type="intf:StockQuote">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getLastTradePrice">
<soap:operation soapAction=""/>
<wsdl:input name="getLastTradePriceRequest">
<soap:body namespace="http://example.com" use="literal"/>
</wsdl:input>
<wsdl:output name="getLastTradePriceResponse">
<soap:body namespace="http://example.com" use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="StockQuoteService">
<wsdl:port binding="intf:StockQuoteSoapBinding" name="StockQuote">
<soap:address location="http://localhost:8080/StockQuote/services/StockQuote"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
//SOAPクライアントの開始
ClientID cltID = Management.initializeClient();
// クライアント識別子と実行スレッドを関連づける
Management.connectClientIDtoCurrentThread(cltID);
try {
// Serviceオブジェクトの生成
QName serviceName = new QName(
"http://example.com",
"StockQuoteService");
URL wsdlDocumentLocation = null;
try {
wsdlDocumentLocation = new URL("file:///C:/foo/StockQuote.wsdl");
} catch(MalFormedURLException e) {
// 異常時の処理
}
ServiceFactory factory = null;
Service service = null;
try {
factory = ServiceFactory.newInstance();
service = factory.createService(wsdlDocumentLocation, serviceName)
} catch(ServiceException e) {
// 異常時の処理
}
// Callオブジェクトの生成
QName portName = new QName(
"http://example.com",
"StockQuote");
QName operationName = new QName {
"http://example.com",
"getLastTradePrice");
javax.xml.rpc.Call call = null;
try {
call = service.createCall(portName, operationName);
} catch(ServiceException e) {
// 異常時の処理
}
// サービス呼び出し
// 入力パラメタを生成
Class inputClass = ((com.cosminexus.cws.xml.rpc.Call) call ).getParameterClassByName("in0");
Object in0 = null;
in(inputClass == String.class) {
in0 = "foo";
}
Object inParams = new Object[] {in0};
Object ret = null;
try {
Object ret = call.invoke(inParams);
} catch(RemoteException e) {
// 異常時の処理
Throwable cause = e.getCause();
if(cause != null) {
// 原因例外が存在する場合の処理
System.out.println(cause.getMessage());
}
}
//戻り値の処理
Class retClass = ret.getClass();
int price = 0;
if(retClass == Integer.class) {
price = ((Integer)ret).intValue();
}
System.out.println("price : " + price);
} finally {
// クライアント識別子と実行スレッドの関連づけを解除する
Management.disconnectClientIDtoCurrentThread(cltID);
// SOAPクライアントの終了
Management.finalizeClient(cltID);
}
例では,javax.xml.rpc.Callクラスとcom.cosminexus.cws.xml.rpc.Callクラスという二つのCallクラスが使われています。Javaでは,別パッケージに存在する,同じ名前のクラスをimport宣言に書けないため,同じクラス内でjavax.xml.rpc.Callクラスとcom.cosminexus.cws.xml.rpc.Callクラスを使用する場合には,例のように完全修飾名で指定する必要があります。
WSDLのインタフェース定義(porType要素)をインポートする場合のWSDLの例およびDIIのコーディング例を示します。なお,WSDLの例では次の情報が定義されています。
<wsdl:definitions
targetNamespace="http://example.com"
xmlns:intf="http://example.com"
xmlns:portType="http://portType.example.com"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:import
namespace="http://portType.example.com"
location="StockQuotePortType.wsdl"/>
<wsdl:binding name="StockQuoteSoapBinding" type="portType:StockQuote">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getLastTradePrice">
<soap:operation soapAction=""/>
<wsdl:input name="getLastTradePriceRequest">
<soap:body namespace="http://example.com" use="literal"/>
</wsdl:input>
<wsdl:output name="getLastTradePriceResponse">
<soap:body namespace="http://example.com" use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="StockQuoteService">
<wsdl:port binding="intf:StockQuoteSoapBinding" name="StockQuote">
<soap:address location="http://localhost:8080/StockQuote/services/StockQuote"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
wsdl:import要素のlocation属性には,インポートするWSDLへの相対パスを記述してください。
<wsdl:definitions
targetNamespace="http://portType.example.com"
xmlns:intf="http://portType.example.com"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:message name="getLastTradePriceResponse">
<wsdl:part name="getLastTradePriceReturn" type="xsd:int"/>
</wsdl:message>
<wsdl:message name="getLastTradePriceRequest">
<wsdl:part name="in0" type="xsd:string"/>
</wsdl:message>
<wsdl:portType name="StockQuote">
<wsdl:operation name="getLastTradePrice" parameterOrder="in0">
<wsdl:input message="intf:getLastTradePriceRequest" name="getLastTradePriceRequest"/>
<wsdl:output message="intf:getLastTradePriceResponse" name="getLastTradePriceResponse"/>
</wsdl:operation>
</wsdl:portType>
</wsdl:definitions>
//SOAPクライアントの開始
ClientID cltID = Management.initializeClient();
// クライアント識別子と実行スレッドを関連づける
Management.connectClientIDtoCurrentThread(cltID);
try {
// Serviceオブジェクトの生成
QName serviceName = new QName(
"http://example.com",
"StockQuoteService");
URL wsdlDocumentLocation = null;
try {
wsdlDocumentLocation = new URL("file:///C:/foo/StockQuote.wsdl");
} catch(MalFormedURLException e) {
// 異常時の処理
}
ServiceFactory factory = null;
Service service = null;
try {
factory = ServiceFactory.newInstance();
service = factory.createService(wsdlDocumentLocation, serviceName)
} catch(ServiceException e) {
// 異常時の処理
}
// Callオブジェクトの生成
QName portName = new QName(
"http://example.com",
"StockQuote");
QName operationName = new QName {
"http://portType.example.com",
"getLastTradePrice");
javax.xml.rpc.Call call = null;
try {
call = service.createCall(portName, operationName);
} catch(ServiceException e) {
// 異常時の処理
}
// サービス呼び出し
// 入力パラメタを生成
Class inputClass = ((com.cosminexus.cws.xml.rpc.Call) call ).getParameterClassByName("in0");
Object in0 = null;
in(inputClass == String.class) {
in0 = "foo";
}
Object inParams = new Object[] {in0};
Object ret = null;
try {
Object ret = call.invoke(inParams);
} catch(RemoteException e) {
// 異常時の処理
Throwable cause = e.getCause();
if(cause != null) {
// 原因例外が存在する場合の処理
System.out.println(cause.getMessage());
}
}
//戻り値の処理
Class retClass = ret.getClass();
int price = 0;
if(retClass == Integer.class) {
price = ((Integer)ret).intValue();
}
System.out.println("price : " + price);
} finally {
// クライアント識別子と実行スレッドの関連づけを解除する
Management.disconnectClientIDtoCurrentThread(cltID);
// SOAPクライアントの終了
Management.finalizeClient(cltID);
}
例では,javax.xml.rpc.Callクラスとcom.cosminexus.cws.xml.rpc.Callクラスという二つのCallクラスが使われています。Javaでは,別パッケージに存在する,同じ名前のクラスをimport宣言に書けないため,同じクラス内でjavax.xml.rpc.Callクラスとcom.cosminexus.cws.xml.rpc.Callクラスを使用する場合には,例のように完全修飾名で指定する必要があります。
INOUTパラメタを使用する場合のWSDLの例およびDIIのコーディング例を示します。なお,WSDLの例では次の情報が定義されています。
<wsdl:definitions
targetNamespace="http://example.com"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:impl="http://example.com-impl"
xmlns:intf="http://example.com"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:message name="getLastTradePriceResponse">
<wsdl:part name="getLastTradePriceReturn" type="xsd:int"/>
<wsdl:part name="in0" type="xsd:string"/>
</wsdl:message>
<wsdl:message name="getLastTradePriceRequest">
<wsdl:part name="in0" type="xsd:string"/>
</wsdl:message>
<wsdl:portType name="StockQuote">
<wsdl:operation name="getLastTradePrice" parameterOrder="in0">
<wsdl:input message="intf:getLastTradePriceRequest" name="getLastTradePriceRequest"/>
<wsdl:output message="intf:getLastTradePriceResponse" name="getLastTradePriceResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="StockQuoteSoapBinding" type="intf:StockQuote">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getLastTradePrice">
<soap:operation soapAction=""/>
<wsdl:input name="getLastTradePriceRequest">
<soap:body namespace="http://example.com" use="literal"/>
</wsdl:input>
<wsdl:output name="getLastTradePriceResponse">
<soap:body namespace="http://example.com" use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="StockQuoteService">
<wsdl:port binding="intf:StockQuoteSoapBinding" name="StockQuote">
<soap:address location="http://localhost:8081/StockQuote/services/StockQuote"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
ClientID cltID = null;
try {
// SOAPクライアントの開始
cltID = Management.initializeClient();
// クライアント識別子と実行スレッドを関連づける
Management.connectClientIDtoCurrentThread(cltID);
// Serviceオブジェクトの生成
QName serviceName = new QName(
"http://example.com",
"StockQuoteService");
URL wsdlDocumentLocation = null;
try {
wsdlDocumentLocation = new URL("file:///F:/soap/V71/test/dii/module/fsSample/out/StockQuote.wsdl");
} catch (MalformedURLException e) {
System.out.println(e.getMessage());
}
ServiceFactory factory = null;
Service service = null;
try {
factory = ServiceFactory.newInstance();
service = factory.createService(wsdlDocumentLocation,
serviceName);
} catch (ServiceException e) {
System.out.println(e.getMessage());
}
// Callオブジェクトの生成
QName portName = new QName(
"http://example.com",
"StockQuote");
QName operationName = new QName(
"http://example.com",
"getLastTradePrice");
javax.xml.rpc.Call call = null;
try {
call = service.createCall(portName, operationName);
} catch (ServiceException e) {
System.out.println(e.getMessage());
}
// サービスメソッドの呼出し
// 入力パラメタを生成
Class inputClass = ((com.cosminexus.cws.xml.rpc.Call) call ).getParameterClassByName("in0");
Object in0 = null;
if(inputClass == String.class) {
in0 = "foo";
}
Object[] inParams = new Object[] {in0};
Object ret = null;
try {
Object ret = call.invoke(inParams);
} catch(RemoteException e) {
// 異常時の処理
Throwable cause = e.getCause();
if(cause != null) {
// 原因例外が存在する場合の処理
System.out.println(cause.getMessage());
}
}
// 出力パラメタの処理
Map out = call.getOutputParams();
Iterator itr = out.entrySet().iterator();
while(itr.hasNext()) {
Map.Entry entry = (Map.Entry) itr.next();
String key = (String) entry.getKey();
if(key.equals("in0")) {
System.out.println(entry.getValue());
}
}
// 戻り値の処理
Class retClass = ret.getClass();
int price = 0;
if(retClass == Integer.class) {
price = ((Integer)ret).intValue();
}
System.out.println("price: " + price);
} finally {
// クライアント識別子と実行スレッドの関連づけを解除する
Management.disconnectClientIDtoCurrentThread(cltID);
// SOAPクライアントの終了
Management.finalizeClient(cltID);
}
例では,javax.xml.rpc.Callクラスとcom.cosminexus.cws.xml.rpc.Callクラスという二つのCallクラスが使われています。Javaでは,別パッケージに存在する,同じ名前のクラスをimport宣言に書けないため,同じクラス内でjavax.xml.rpc.Callクラスとcom.cosminexus.cws.xml.rpc.Callクラスを使用する場合には,例のように完全修飾名で指定する必要があります。
DIIでは,引数にHolderクラスを指定しません。Holderクラスに対応するJavaの基本型クラスを指定してください。例では,javax.xml.rpc.holders.StringHolderに対応するjava.lang.Stringクラスを指定しています。
ユーザ定義のデータ型クラスを使用する場合のWSDLの例およびDIIのコーディング例を示します。なお,WSDLの例では次の情報が定義されています。
<wsdl:definitions
targetNamespace="http://example.com"
xmlns:intf="http://example.com"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<schema elementFormDefault="qualified"
targetNamespace="http://example.com"
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="getLastTradePrice">
<complexType>
<sequence>
<element name="in0" type="intf:TradeDate"/>
</sequence>
</complexType>
</element>
<complexType name="TradeDate">
<sequence>
<element name="date" nillable="true" type="xsd:string"/>
</sequence>
</complexType>
<element name="getLastTradePriceResponse">
<complexType>
<sequence>
<element name="getLastTradePriceReturn" type="intf:TradePrice"/>
</sequence>
</complexType>
</element>
<complexType name="TradePrice">
<sequence>
<element name="price" type="xsd:int"/>
</sequence>
</complexType>
<element name="TradePriceException" type="intf:TradePriceException"/>
<complexType name="TradePriceException">
<sequence>
<element name="errcode" type="xsd:int"/>
</sequence>
</complexType>
</schema>
</wsdl:types>
<wsdl:message name="getLastTradePriceResponse">
<wsdl:part name="parameters" element="intf:getLastTradePrice"/>
</wsdl:message>
<wsdl:message name="getLastTradePriceRequest">
<wsdl:part name="parameters" element="intf:getLastTradePriceResponse"/>
</wsdl:message>
<wsdl:message name="TradePriceException">
<wsdl:part name="fault" type="intf:TradePriceException"/>
</wsdl:message>
<wsdl:portType name="StockQuote">
<wsdl:operation name="getLastTradePrice">
<wsdl:input message="intf:getLastTradePriceRequest" name="getLastTradePriceRequest"/>
<wsdl:output message="intf:getLastTradePriceResponse" name="getLastTradePriceResponse"/>
<wsdl:fault message="intf:TradePriceException" name="TradePriceException"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="StockQuoteSoapBinding" type="intf:StockQuote">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getLastTradePrice">
<soap:operation soapAction=""/>
<wsdl:input name="getLastTradePriceRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getLastTradePriceResponse">
<soap:body use="literal"/>
</wsdl:output>
<wsdl:fault name="TradePriceException">
<soap:fault name="TradePriceException" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="StockQuoteService">
<wsdl:port binding="intf:StockQuoteSoapBinding" name="StockQuote">
<soap:address location="http://localhost:8080/StockQuote/services/StockQuote"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
// SOAPクライアントの開始
ClientID cltID = Management.initializeClient();
// クライアント識別子と実行スレッドを関連づける
Management.connectClientIDtoCurrentThread(cltID);
try {
// Serviceオブジェクトの生成
QName serviceName = new QName(
"http://example.com",
"StockQuoteService");
URL wsdlDocumentLocation = null;
try {
wsdlDocumentLocation = new URL("file:///C:/foo/StockQuote.wsdl");
} catch (MalformedURLException e) {
// 異常時の処理
}
ServiceFactory factory = null;
Service service = null;
try {
factory = ServiceFactory.newInstance();
service = factory.createService(wsdlDocumentLocation, serviceName);
} catch (ServiceException e) {
// 異常時の処理
}
// Callオブジェクトの生成
QName portName = new QName(
"http://example.com",
"StockQuote");
QName operationName = new QName(
"http://example.com",
"getLastTradePrice");
javax.xml.rpc.Call call = null;
try {
call = service.createCall(portName, operationName);
} catch (ServiceException e) {
// 異常時の処理
}
// サービス呼び出し
// 入力パラメータを生成
Class inputClass =((com.cosminexus.cws.xml.rpc.Call)
call).getParameterClassByName("in0");
Object in0 = null;
try {
if (inputClass != null) {
if (inputClass.getName().equals("com.example.TradeDate")) {
in0 = inputClass.newInstance();
// メンバメソッドをリフレクトするMethodオブジェクトを取得
Class[] parameterTypes = {String.class};
Method method = inputClass.getMethod("setDate", parameterTypes);
// メンバメソッドを実行
Object[] initargs = {"20070101"};
method.invoke(in0, initargs);
}
}
} catch (Exception e) {
// 異常時の処理
}
Object[] inParams = new Object[]{in0};
Object ret = null;
try {
ret = call.invoke(inParams);
} catch (RemoteException e) {
// 異常時の処理
Throwable cause = e.getCause();
if (cause instanceof C4Fault) {
C4Fault fault = (C4Fault)cause;
// 例外メッセージの取得
String msg = fault.getMessage();
System.out.println(msg);
Throwable uerr = fault.getCause();
if (uerr != null) {
// ユーザ定義例外が含まれる場合
Class errClass = uerr.getClass();
int errcode = 0;
try {
if (errClass != null) {
if (errClass.getName().equals(
"com.example.TradePriceException")) {
Class[] clParam = {};
Object[] objParam = {};
// メンバメソッドをリフレクトするMethodオブジェクトを取得
Method method = errClass.getMethod(
"getErrcode", clParam);
// メンバメソッドを実行し,戻り値を取得
Object retErrcode = method.invoke(uerr, objParam);
if (retErrcode.getClass() == Integer.class) {
errcode = ((Integer)retErrcode).intValue();
}
}
}
} catch (Exception ex) {
// 異常時の処理
}
System.out.println("errcode : " + errcode);
} else {
// ユーザ定義例外が含まれない場合
// C4Fault例外からSOAP Faultの情報を取得する
}
}
}
// 戻り値の処理
Class retClass = ret.getClass();
int price = 0;
try {
if (retClass != null) {
if (retClass.getName().equals("com.example.TradePrice")) {
Class[] clParam = {};
Object[] objParam = {};
// メンバメソッドをリフレクトするMethodオブジェクトを取得
Method method = retClass.getMethod("getPrice", clParam);
// メンバメソッドを実行し,戻り値を取得
Object retPrice = method.invoke(ret, objParam);
if (retPrice.getClass() == Integer.class) {
price = ((Integer)retPrice).intValue();
}
}
}
} catch (Exception e) {
// 異常時の処理
}
System.out.println("price : " + price);
} finally {
// クライアント識別子と実行スレッドの関連づけを解除する
Management.disconnectClientIDtoCurrentThread(cltID);
// SOAPクライアントの終了
Management.finalizeClient(cltID);
}
例では,javax.xml.rpc.Callクラスとcom.cosminexus.cws.xml.rpc.Callクラスという二つのCallクラスが使われています。Javaでは,別パッケージに存在する,同じ名前のクラスをimport宣言に書けないため,同じクラス内でjavax.xml.rpc.Callクラスとcom.cosminexus.cws.xml.rpc.Callクラスを使用する場合には,例のように完全修飾名で指定する必要があります。
配列を使用する場合のWSDLの例およびDIIのコーディング例を示します。なお,WSDLの例では次の情報が定義されています。
<wsdl:definitions
targetNamespace="http://example.com"
xmlns:intf="http://example.com"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<schema elementFormDefault="qualified"
targetNamespace="http://example.com"
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="getLastTradePrice">
<complexType>
<sequence>
<element name="in0" maxOccurs="unbounded" minOccurs="0" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="getLastTradePriceResponse">
<complexType>
<sequence>
<element name="getLastTradePriceReturn" maxOccurs="unbounded" minOccurs="0" type="xsd:in/>
</sequence>
</complexType>
</element>
</schema>
</wsdl:types>
<wsdl:message name="getLastTradePriceRequest">
<wsdl:part element="intf:getLastTradePrice" name="parameters"/>
</wsdl:message>
<wsdl:message name="getLastTradePriceResponse">
<wsdl:part element="intf:getLastTradePriceResponse" name="parameters"/>
</wsdl:message>
<wsdl:portType name="StockQuote">
<wsdl:operation name="getLastTradePrice">
<wsdl:input message="intf:getLastTradePriceRequest" name="getLastTradePriceRequest"/>
<wsdl:output message="intf:getLastTradePriceResponse" name="getLastTradePriceResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="StockQuoteSoapBinding" type="intf:StockQuote">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getLastTradePrice">
<soap:operation soapAction=""/>
<wsdl:input name="getLastTradePriceRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getLastTradePriceResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="StockQuoteService">
<wsdl:port binding="intf:StockQuoteSoapBinding" name="StockQuote">
<soap:address location="http://localhost:8080/StockQuote/services/StockQuote"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
// SOAPクライアントの開始
ClientID cltID = Management.initializeClient();
// クライアント識別子と実行スレッドを関連づける
Management.connectClientIDtoCurrentThread(cltID);
try {
// Serviceオブジェクトの生成
QName serviceName = new QName(
"http://example.com",
"StockQuoteService");
URL wsdlDocumentLocation = null;
try {
wsdlDocumentLocation = new URL("file:///C:/foo/StockQuote.wsdl");
} catch (MalformedURLException e) {
// 異常時の処理
}
ServiceFactory factory = null;
Service service = null;
try {
factory = ServiceFactory.newInstance();
service = factory.createService(wsdlDocumentLocation, serviceName);
} catch (ServiceException e) {
// 異常時の処理
}
// Callオブジェクトの生成
QName portName = new QName(
"http://example.com",
"StockQuote");
QName operationName = new QName(
"http://example.com",
"getLastTradePrice");
javax.xml.rpc.Call call = null;
try {
call = service.createCall(portName, operationName);
} catch (ServiceException e) {
// 異常時の処理
}
// サービス呼び出し
// 入力パラメータを生成
Class inputClass = ((com.cosminexus.cws.xml.rpc.Call)call).getParameterClassByName("in0");
Object in0 = null;
if (inputClass == String[].class) {
in0 = new String[]{"20070101", "20070201"};
}
Object[] inParams = new Object[]{in0};
Object ret = null;
try {
ret = call.invoke(inParams);
} catch (RemoteException e) {
// 異常時の処理
Throwable cause = e.getCause();
if (cause != null) {
// 原因例外が存在する場合の処理
System.out.println(cause.getMessage());
}
}
// 戻り値の処理
Class retClass = ret.getClass();
int price = 0;
if (retClass == Integer[].class) {
Integer[] prices = (Integer[])ret;
if (prices.length > 0) {
price = prices[0].intValue();
}
}
System.out.println("price : " + price);
} finally {
// クライアント識別子と実行スレッドの関連づけを解除する
Management.disconnectClientIDtoCurrentThread(cltID);
// SOAPクライアントの終了
Management.finalizeClient(cltID);
}