웹 서비스 코드 예제
이 WSDL(Web Services Description Language) 예제 및 코드 스니펫은 중개를 프로그래밍하기 위해 웹 서비스 메시지 내에 있는 필드에 액세스하는 방법을 보여줍니다.
웹 서비스 메시지 정의
이 주제는 웹 서비스 메시지의 예제를 포함합니다. 이 예제는 비즈니스가 제공하는 서비스 및 해당 서비스에 액세스하는 방법을 설명하는 데 사용되는 XML 기반 언어인 WSDL을 특징으로 합니다.
이 주제는 여러 파트의 웹 서비스 메시지에 대한 작업을 하기 위해 중개를 프로그래밍하는 방법을 보여주며 이는 웹 서비스 메시지의 SDO 데이터 그래프 맵핑의 SDO(Service Data Objects) 버전 1 표시로 설명됩니다. 메시지의 각 파트에 대해서 메시지의 XML 설명이 있고 해당 SDO 데이터 그래프를 나타냅니다. 각 XML 설명은 해당 메시지 파트에 대해 작업하는 방법을 보여주는 코드 스니펫을 동반합니다.
참고: 다음 예제에서 SOAP 헤더 스키마는 WSDL에 포함됩니다. 또는 SDO 저장소에 개별 스키마로 포함될 수 있습니다.
다음은 후속 코드 스니펫의 예제로 사용되는 메시지의 WSDL 설명입니다.
companyInfo 웹 서비스 메시지 설명
<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>
정보 노드에 대한 작업
이 예제는 단순한 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");
// 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");