Complex CF Webservices problem - solved
I was pretty determined to get this working and decided to build the SOAP envelope manually and send it to the webservice using a CFHTTP POST. This actually worked very nicely and this is how I did it:
Build the array of structures in SOAP format like so:
<soap:myArray>
<soap:item>
<soap:firstName>John</soap:firstName>
<soap:lastName>Smith</soap:lastName>
<soap:age>27</soap:age>
</soap:item>
<soap:item>
<soap:firstName>Chris</soap:firstName>
<soap:lastName>Jones</soap:lastName>
<soap:age>30</soap:age>
</soap:item>
</soap:myArray>
</cfsavecontent>
This is only a portion of the entire SOAP envelope. See SOAP Specifications for complete soap format.
After you've got your SOAP built up, all you need to do is post it:
<cfhttpparam type="header" name="SOAPACTION" value="wsMethod" />
<cfhttpparam type="header" name="Content-Type" value="application/soap+xml; charset=utf-8" />
<cfhttpparam type="header" name="Cache-Control" value="Cache-Control: max-age=0, must-revalidate, proxy-revalidate, no-cache" />
<cfhttpparam type="body" value="#soap#" />
</cfhttp>
As you can see, you must specify "SOAPACTION" in the header, where SOAPACTION is the Webservice method you are calling. I'm pretty sure that the other 2 parameters are optional, but I thought I'd throw them in just in case.
I haven't tested the efficiency of this approach, but I think this might actually be a quicker way of talking to webservices. The only time consuming part would be creating the SOAP envelope manually and possibly parsing the SOAP response, but if the transaction speed is important to you it might be worth considering this option - that's if it is quicker :). I will try to post some timing results soon.




There are no comments for this entry.
[Add Comment]