标题:18.11.解析WeBService的返回的SOAP响应
作者:网友
日期:2023-07-12 18:52:00
内容:

18.11.1. 问题
我需要解析返回的SOAP 响应。
18.11.2. 解决办法
使用Flash Player 将WebService 返回的SOAP 编码XML 的SOAP 类型转换为ActionScript 类型。
18.11.3. 讨论
返回的SOAP 响应可用E3X 表达式进行解析。常用的类型如表Table 18-1, 以及对应的SOAP和ActionScript 表示。
Table 18-1. SOAP 类型和对应的ActionScript类型

一个WSDL 文件定义如下返回类型:

+展开
-XML
<wsdl:types>
<schema elementFormDefault="qualifiedtargetNamespace="http://cookbook.webservices.comxmlns="http://www.w3.org/2001/XMLSchema">
<complexType name="Recipe">
<sequence>
<element name="titlenillable="truetype="xsd:string"/>
<element name="ingredientsnillable="truetype="xsd:string[]"/>
<element name="instructionsnillable="truetype="xsd:string[]"/>
</sequence>
</complexType>
</schema>
</wsdl:types>

WebService 的返回如下:
+展开
-XML
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body xmlns:ns="http://cookbook.oreilly.com/service">
<ns:GetRecipes>
<ns:Recipe>
<ns:title>"Blueberry Pie"</ns:title>
<SOAP-ENC:Array SOAP-ENC:arrayType="xsd:string[3]">
<ns:ingredient>"Blueberry"</ns:ingredient>
<ns:ingredient>"Sugar"</ns:ingredient>
<ns:ingredient>"Crust"</ns:ingredient>
</SOAP-ENC:Array>
<SOAP-ENC:Array SOAP-ENC:arrayType="xsd:string[3]">
<ns:instruction>"Blueberry"</ns:instruction>
<ns:instruction>"Sugar"</ns:instruction>
<ns:instruction>"Crust"</ns:instruction>
</SOAP-ENC:Array>
</ns:Recipe>
</ns:GetRecipes>
</soap:Body>
</soap:Envelope>

这个响应可用(.)符号解析出所需对象,和处理任何XML 对象一样。更多有关SOAP 类型和ActionScript 类型的区别,请看http://www.adobe.com/go/kb402005


返回列表 网站首页