国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

手工創建的SOAP消息中命名空間的處理

2019-11-18 12:50:32
字體:
來源:轉載
供稿:網友

  引言
  
  在典型的 Web 服務場景中,通常使用工具技術來處理命名空間的所有細微差別。但是有些時候,非凡是在使用 SAAJ(SOAP with Attachments API for java)為特定的 Web 服務構造 SOAP 消息時,您必須自己處理命名空間問題。在沒有任何工具輔助的情況下構造消息――或是部分消息時――可以使用該技巧。
  
  雖然命名空間看似復雜,但您真正只需要把握的是以下一份簡短的規則清單:
  
  假如 WSDL 樣式為 RPC,那么可在 WSDL 綁定的 wsdlsoap:body 元素中查看命名空間。
  
  假如 wsdlsoap:body 有命名空間屬性(且 Web 服務互操作性組織(WS-I)的 Basic PRofile(參見參考資料部分)需要該屬性用于 RPC 樣式),那么這就是 SOAP 消息中操作元素的命名空間。
  
  假如 wsdlsoap:body 沒有命名空間,那么該操作元素不符合要求。
  
  對于數據元素而言:
  
  假如元素通過根元素(不是根類型)定義,那么它的命名空間就是根元素的命名空間;
  
  假如元素不是通過根定義的,那么該元素不符合要求(對于該規則的說明請參見以下 elementFormDefault 部分的討論。)
  
  這些都是簡單的規則,但如同大多數規則一樣,需要對其進行少許說明。本文的其余部分將展示使用這些規則的各類實例。
  
  有兩種常用類型的 Web 服務描述語言(WSDL)文件: RPC/literal 和 document/literal 封裝。當然還有其它的類型,但在本文中只包含這兩種。(各類 WSDL 的具體內容參見文章“我應該使用哪種樣式的 WSDL?”――參見參考資料。)
  
  RPC/literal WSDL
  
  清單 1 中的 RPC/literal WSDL 有三個操作:op1、op2 和 op3。注重 WSDL 文件中用粗體強調的不同命名空間。
  
  清單 1. RPC/literal WSDL
  <?XML version="1.0" encoding="UTF-8"?>
  <definitions
  targetNamespace="http://apiNamespace.com"
  xmlns="http://schemas.xmlsoap.org/wsdl/"
  xmlns:tns="http://apiNamespace.com"
  xmlns:data="http://dataNamespace.com"
  xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/">
  <types>
  <schema
  targetNamespace="http://refNamespace.com"
  xmlns="http://www.w3.org/2001/XMLSchema"
  xmlns:tns="http://refNamespace.com">
  <element name="RefDataElem" type="int"/>
  </schema>
  <schema
  targetNamespace="http://dataNamespace.com"
  xmlns="http://www.w3.org/2001/XMLSchema"
  xmlns:ref="http://refNamespace.com"
  xmlns:tns="http://dataNamespace.com"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <import namespace="http://refNamespace.com"/>
  <complexType name="Data">
  <sequence>
  <element name="data1" type="int"/>
  <element name="data2" type="int"/>
  </sequence>
  </complexType>
  <element name="DataElem" nillable=
  "true" type="tns:Data"/>
  <complexType name="Data2">
  <sequence>
  <element ref="ref:RefDataElem"/>
  </sequence>
  </complexType>
  </schema>
  </types>
  <message name="op1Request">
  <part name="in" type="data:Data"/>
  </message>
  <message name="op1Response">
  <part name="op1Return"
  type="data:Data"/>
  </message>
  <message name="op2Request">
  <part name="in" type="data:Data"/>
  </message>
  <message name="op2Response">
  <part name="op2Return" type="data:Data"/>
  </message>
  <message name="op3Request">
  <part name="in1" element="data:DataElem"/>
  <part name="in2" type="data:Data2"/>
  </message>
  <message name="op3Response">
  <part name="op3Return" type="data:Data2"/>
  </message>
  <portType name="Sample">
  <operation name="op1">
  <input message="tns:op1Request"/>
  <output message="tns:op1Response"/>
  </operation>
  <operation name="op2">
  <input message="tns:op2Request"/>
  <output message="tns:op2Response"/>
  </operation>
  <operation name="op3">
  <input message="tns:op3Request"/>
  <output message="tns:op3Response"/>
  </operation>
  </portType>
  <binding name="SampleSoapBinding" type="tns:Sample">
  <wsdlsoap:binding style="rpc" transport=
  "http://schemas.xmlsoap.org/soap/http"/>
  <operation name="op1">
  <wsdlsoap:operation soapAction=""/>
  <input>
  <wsdlsoap:body namespace=
  "http://apiNamespace.com" use="literal"/>
  </input>
  <output>
  <wsdlsoap:body namespace=
  "http://apiNamespace.com" use="literal"/>
  </output>
  </operation>
  <operation name="op2">
  <wsdlsoap:operation soapAction=""/>
  <input>
  <wsdlsoap:body namespace=
  "http://op2Namespace.com" use="literal"/>   </input>
  <output>
  <wsdlsoap:body namespace=
  "http://op2Namespace.com" use="literal"/>
  </output>
  </operation>
  <operation name="op3">
  <wsdlsoap:operation soapAction=""/>
  <input>
  <wsdlsoap:body use="literal"/>
  </input>
  <output>
  <wsdlsoap:body use="literal"/>
  </output>
  </operation>
  </binding>
  <service name="SampleService">
  <port binding="tns:SampleSoapBinding" name=
  "Sample">
  <wsdlsoap:address location=
  "http://localhost:9080/RPCNamespaces/services/Sample"/>
  </port>
  </service>
  </definitions>
  
  WS-I 遵從性
  
  WS-I(參見參考資料)為 WSDL 定義遵從性標準。從兩個方面來講,op3 不遵從 RPC/literal WSDL:它并不在綁定的 wsdlsoap:body 中定義命名空間;它的消息部分引用了元素,而不是類型。在此提出是為了展示可以用 WS-I 的 Basic Profile 解決的一些命名空間問題。
  
  查看用于每個操作的綁定的 wsdlsoap:body 元素中的命名空間。op1 和 op2 是規則 1.1 的實例(參見以下有關 SOAP 消息的內容)。op3 是規則 1.2 的實例。op1 展示了使用 targetNamespace 的常規實例――在這種情況下是“http://apiNamespace.com”――作為該操作的命名空間,但是這僅僅是通常情況。op2 使用的命名空間將不會在 WSDL 中的其他任何地方被使用。op3 無需定義任何命名空間。
  
  清單 2、3 和 4 分別展示了 op1、op2 和 op3 的 SOAP 消息。注重消息中用粗體強調的命名空間。
  
  清單 2. op1 的 RPC/literal 請求/響應 SOAP 消息
  
  <soapenv:Envelope xmlns:soapenv=
  "http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
  <p582:op1 xmlns:p582="http://apiNamespace.com">
  <in>
  <data1>1</data1>
  <data2>2</data2>
  </in>
  </p582:op1>
  </soapenv:Body>
  </soapenv:Envelope>
  <soapenv:Envelope xmlns:soapenv=
  "http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
  <p582:op1Response xmlns:p582=
  "http://apiNamespace.com">
  <op1Return>
  <data1>10</data1>
  <data2>20</data2>
  </op1Return>
  </p582:op1Response>
  </soapenv:Body>
  </soapenv:Envelope>
  
  在上文中已經提及,清單 2 中的 SOAP 消息遵從規則 1.1。op1 的命名空間為“http://apiNamespace.com”。這些消息同樣遵從規則 2.2。所有參數數據都不通過根元素定義,僅僅是根類型――數據――以及它的子元素。既然沒有使用根元素,那么這些元素都是不合要求的。
  
  清單 3. op2 的 RPC/literal 請求/響應 SOAP 消息
  
  <soapenv:Envelope xmlns:soapenv=
  "http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
  <p999:op2 xmlns:p999=
  "http://op2Namespace.com">
  <in>
  <data1>3</data1>
  <data2>4</data2>
  </in>
  </p999:op2>
  </soapenv:Body>
  </soapenv:Envelope>
  <soapenv:Envelope xmlns:soapenv=
  "http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
  <p999:op2Response xmlns:p999=
  "http://op2Namespace.com">
  <op2Return>
  <data1>300</data

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 钟祥市| 新平| 休宁县| 磴口县| 宜昌市| 古蔺县| 揭西县| 阿图什市| 三台县| 水富县| 赫章县| 百色市| 蕉岭县| 四川省| 安陆市| 翁牛特旗| 泾源县| 得荣县| 灌南县| 于田县| 丽水市| 广宁县| 阳原县| 开封市| 唐河县| 宾川县| 新乐市| 博客| 固始县| 泗阳县| 阿拉善左旗| 布拖县| 长岭县| 黄骅市| 德庆县| 和田县| 余庆县| 霍州市| 旌德县| 兴安县| 临朐县|