Web サービス・コード実例
この Web サービス記述言語 (WSDL) の例およびコード・スニペットは、メディエーションをプログラミングするために Web サービス・メッセージ内のフィールドにアクセスする方法を示しています。
Web サービス・メッセージ定義
このトピックには、Web サービス・メッセージの実例があります。この例は、WSDL で表現されています。これはビジネスが提供するサービスおよびそれらのサービスへのアクセス方法を記述するために使用される、XML ベースの言語です。
このトピックでは、Web サービス・メッセージ用の SDO データ・グラフのマッピングにあるサービス・データ・オブジェクト (SDO) バージョン 1 表現で記述されている、Web サービス・メッセージのさまざまな部分を処理するメディエーションをプログラムする方法を示しています。メッセージのそれぞれの部分ごとに、SDO データ・グラフを表しているメッセージの XML 記述があります。 それぞれの XML 記述には、メッセージの特定の部分を処理する方法を例示するコード・スニペットが付記されています。
注: 以下の例では、SOAP ヘッダー・スキーマが WSDL に組み込まれています。
また、SDO
リポジトリーに別個のスキーマとして組み込まれている場合があります。
これは、後続のコード・スニペットの例として使用されるメッセージの WSDL 記述です。
companyInfo Web サービス・メッセージの説明
<wsdl:definitions targetNamespace="http://example.companyInfo"
xmlns:tns="http://example.companyInfo"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdlmime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xsd:schema elementFormDefault="qualified"
targetNamespace="http://example.header">
<xsd:element name="sampleHeader">
<xsd:complexType>
<xsd:all>
<xsd:element name="priority" type="xsd:int"/>
</xsd:all>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<xsd:schema elementFormDefault="qualified"
targetNamespace="http://example.companyInfo">
<xsd:element name="getCompanyInfo">
<xsd:complexType>
<xsd:all>
<xsd:element name="tickerSymbol" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
</xsd:element>
<xsd:element name="getCompanyInfoResult">
<xsd:complexType>
<xsd:all>
<xsd:element name="result" type="xsd:float"/>
</xsd:all>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="getCompanyInfoRequest">
<wsdl:part name="part1" element="tns:getCompanyInfo"/>
</wsdl:message>
<wsdl:message name="getCompanyInfoResponse">
<wsdl:part name="part1" element="tns:getCompanyInfoResult"/>
<wsdl:part name="part2" type="xsd:string"/>
<wsdl:part name="part3" type="xsd:base64Binary"/>
</wsdl:message>
<wsdl:portType name="CompanyInfo">
<wsdl:operation name="GetCompanyInfo">
<wsdl:input message="tns:getCompanyInfoRequest"
name="getCompanyInfoRequest"/>
<wsdl:output message="tns:getCompanyInfoResponse"
name="getCompanyInfoResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="CompanyInfoBinding" type="tns:CompanyInfo">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="GetCompanyInfo">
<wsdlsoap:operation soapAction=""/>
<wsdl:input name="getCompanyInfoRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getCompanyInfoResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="CompanyInfoService">
<wsdl:port binding="tns:CompanyInfoBinding" name="SOAPPort">
<wsdlsoap:address location="http://somewhere/services/CompanyInfoService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
info ノードの操作
これは、単純な SOAP 要求の実例です。
<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:ns1='http://example.companyInfo'>
<env:Body>
<ns1:getCompanyInfo>
<ns1:tickerSymbol>IBM</ns1:tickerSymbol>
</ns1:getCompanyInfo>
</env:Body>
</env:Envelope>
このようなコード・スニペットを使用して info ノードのプロパティーにアクセスすることができます (Web サービス・メッセージの全体のレイアウトを参照してください)。
// Get the info node (a child of the graph root object)
DataObject rootNode = graph.getRootObject();
DataObject infoNode = rootNode.getDataObject("Info");
// Query the operationName, and messageType.
String opName = infoNode.getString("operationName");
String type = infoNode.getString("messageType");
ヘッダーの使用
これは、ヘッダーを含む SOAP 要求の実例です。
<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:ns1='http://example.companyInfo'>
<env:Header>
<example:sampleHeader
env:mustUnderstand='1'
xmlns:example='http://example.header'>
<example:priority>4</example:priority>
</example:sampleHeader>
</env:Header>
<env:Body>
<ns1:getCompanyInfo>
<ns1:tickerSymbol>IBM</ns1:tickerSymbol>
</ns1:getCompanyInfo>
</env:Body>
</env:Envelope>
ヘッダーのリストがあるヘッダー・エントリーのプロパティーの説明については、ヘッダー・エントリーを参照してください。
ヘッダー・エントリーおよびそのプロパティーを処理にするには、以下のようなコードを使用します。
// Get the info node (a child of the graph root object)
DataObject rootNode = graph.getRootObject();
DataObject infoNode = rootNode.getDataObject("Info");
// Access the list of headers
List headerEntries = infoNode.getList("headers");
// Get the first entry from the list
DataObject headerEntry = (DataObject) headerEntries.get(0);
// Query the mustUnderstand property of the header entry
boolean mustUnderstand = headerEntry.getBoolean("mustUnderstand");
// Get the Sequence that holds the content of the header entry
Sequence headerContent = headerEntry.getSequence("any");
// Get the first piece of content from the Sequence
DataObject header = (DataObject) headerContent.getValue(0);
// Read the priority from the header
int priority = header.getInt("priority");
// Shorthand for the above, using SDO path expressions that start
// from the info node.
mustUnderstand = infoNode.getBoolean("headers[1]/mustUnderstand");
priority = infoNode.getInt("headers[1]/any[1]/priority");
添付の使用
これは、XML 添付を含む SOAP 要求の実例です。
Content-Type: multipart/related; start="<start>"; boundary="boundary"
--boundary
Content-Type: text/xml
Content-Transfer-Encoding: 7bit
Content-ID: <start>
<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:ns1='http://example.companyInfo'>
<env:Body>
<ns1:getCompanyInfo>
<ns1:tickerSymbol>IBM</ns1:tickerSymbol>
</ns1:getCompanyInfo>
</env:Body>
</env:Envelope>
--boundary
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-ID: <myAttachment>
<info>Some attached information</info>
--boundary--
バイト配列がある添付エントリーのプロパティーの説明については、添付エントリーを参照してください。
ヘッダー・エントリーおよびそのプロパティーを処理にするには、以下のようなコードを使用します。
// Get the info node (a child of the graph root object)
DataObject rootNode = graph.getRootObject();
DataObject infoNode = rootNode.getDataObject("Info");
// Access the list of attachments
List attachmentEntries = infoNode.getList("attachments");
// Get the first entry from the list
DataObject attachmentEntry = (DataObject) attachmentEntries.get(0);
// Query the contentId property of the header entry
String contentId = attachmentEntry.getString("contentId");
// Get the data contained in the attachment
byte[] data = attachmentEntry.getBytes("data");
メッセージ本体の使用
これは、単純な SOAP 要求の実例です。
<env:Envelope
xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'
xmlns:ns1='http://example.companyInfo'>
<env:Body>
<ns1:getCompanyInfo>
<ns1:tickerSymbol>IBM</ns1:tickerSymbol>
</ns1:getCompanyInfo>
</env:Body>
</env:Envelope>
本体のプロパティーについては、メッセージ本体レイアウトを参照してください。
本体の内容を処理するには、以下のようなコードを使用します。
// Get the info node (a child of the graph root object)
DataObject rootNode = graph.getRootObject();
DataObject infoNode = rootNode.getDataObject("Info");
// Get hold of the body node
DataObject bodyNode = infoNode.getDataObject("body");
// Get hold of the data object for the first part of the body
DataObject part1Node = bodyNode.getDataObject("part1");
// Query the tickerSymbol
String ticker = part1Node.getString("tickerSymbol");
// Shorthand for the above, using a SDO path expression that
// starts from the info node.
ticker = infoNode.getString("body/part1/tickerSymbol");