Cfcomponent web service - getting SOAP attributes

Here is an example SOAP request:

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

And here is my cfc web service example:

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

I am new to Coldfusion and web service and I don't know how to extract attributes a1 and a2 from googled but cannot find any link. Any ideas? <testService>

=== Edit ===

Thought it might be useful if I attach a type definition:

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

Please note that although this is my test web service, it is based on the data schema provided by our partner, which means that my web service must comply with it.

=== Resolution ===

Based on Jerry's answer, this is what I ended up with:

<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>
+4
source share
3 answers

, , 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>
+1

XML, a1 a2

<cfsavecontent variable="myXML" >
    <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>
</cfsavecontent>
 <cfset parXML = xmlParse(myXML) />
<cfdump var="#parXML.Envelope.body.XmlChildren[1].XmlAttributes.a1#">
+1

-, -. a1 a2 CFC . , , , e1 e2.

, - -, SoapUI. example.cfc SOAPUI , XML-, :

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soap.stack">
   <soapenv:Header/>
   <soapenv:Body>
      <soap:testService>
         <soap:e1>e1</soap:e1>
         <soap:e2>e2</soap:e2>
      </soap:testService>
   </soapenv:Body>
</soapenv:Envelope>

a1 a2, .

, CFC, :

<cfcomponent style="document" wsversion = 1>

    <cffunction name="testService" returntype="String" access="remote" >
        <cfargument type="string" name="a1"/>
        <cfargument type="string" name="a2"/>
        <cfargument type="string" name="e1"/>
        <cfargument type="string" name="e2"/>


        <cfset var ret=serializeJSON(arguments) />
        <cfreturn "#ret#">
    </cffunction>
</cfcomponent>

SOAPUI , SOAP-, :

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soap.stack">
   <soapenv:Header/>
   <soapenv:Body>
      <soap:testService>
         <soap:a1>?</soap:a1>
         <soap:a2>?</soap:a2>
         <soap:e1>?</soap:e1>
         <soap:e2>?</soap:e2>
      </soap:testService>
   </soapenv:Body>
</soapenv:Envelope>
0
source

All Articles