web-services – cfcomponent web service – 获取SOAP属性

这是一个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,用Google搜索但找不到任何引用.有任何想法吗?

===编辑===

认为如果我附加类型定义可能会有用:

<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>

请注意,虽然这是我的测试Web服务,但它基于我们的合作伙伴提供的数据模式,这意味着我的Web服务必须符合它.

===分辨率===

根据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>

最佳答案 根据你的评论,我认为你需要getSoapRequest(),然后使用keshav-jha给出的答案中的代码解析它

<cfcomponent style="document" wsversion = 1>

    <cffunction name="testService" returntype="String" access="remote" >
        <cfargument type="string" name="e1"/>
        <cfargument type="string" name="e2"/>
        <cfscript>
            soapReq=GetSOAPRequest();
            soapXML=xmlParse(soapReq);
            bodyAttributes = {
                a1:soapXML.Envelope.body.XmlChildren[1].XmlAttributes.a1
                ,a2:soapXML.Envelope.body.XmlChildren[1].XmlAttributes.a2
            };
            return serializejson(bodyAttributes);
        </cfscript>

    </cffunction>
</cfcomponent>
点赞