以下是一个SOAP请求示例:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ws="http://ws_test">
<soapenv:Header/>
<soapenv:Body>
<ws:testService a1="a1" a2="a2">
<ws:e1>e1</ws:e1>
<ws:e2>e2</ws:e2>
</ws:testService>
</soapenv:Body>
</soapenv:Envelope>
以下是我的示例cfc web服务:
<cfcomponent style="document" wsversion = 1>
<cffunction name="testService" returntype="String" access="remote" >
<cfargument type="string" name="e1"/>
<cfargument type="string" name="e2"/>
<!--- Missing: code to extract a1 and a2 --->
<cfreturn "#e1# #e2#">
</cffunction>
</cfcomponent>
我刚开始接触Coldfusion和Web服务,对于如何从
<testService>
中提取属性a1和a2一无所知,在谷歌上搜索了一下,但没有找到任何相关参考资料。有什么想法吗?===编辑===
想着附上类型定义可能会有用:
<complexType name="testServiceType">
<sequence>
<element name="e1" type="string"></element>
<element name="e2" type="string"></element>
</sequence>
<attribute name="a1" type="string"/>
<attribute name="a2" type="string"/>
</complexType>
请注意,尽管这是我的测试网络服务,但它基于我们合作伙伴提供的数据架构,这意味着我的网络服务必须符合它。
=== 解决方案 ===
根据Gerry的答案,这就是我最终采取的做法:
<cfcomponent style="document" wsversion = 1>
<cffunction name="testService" returntype="String" access="remote" >
<cfargument type="string" name="e1"/>
<cfargument type="string" name="e2"/>
<cfset soapReq = getSOAPRequest()>
<cfset soapXML = xmlParse(soapReq)>
<cfset attributes = soapXML.Envelope.body.XmlChildren[1].XmlAttributes>
<cfset a1 = attributes.a1>
<cfset a2 = attributes.a2>
<cfreturn "#e1# #e2# #a1# #a2#">
</cffunction>
</cfcomponent>