Making Soap based web service calls with Ajax


By David Fekke
January 17th, 2011

I have been preparing a presentation for my local user group on Ajax. Part of my presentation will be on REST vs. SOAP based RPC calls. One of the arguments against using SOAP based web service calls is that it is too hard to make SOAP calls using the XMLHTTPRequest object. I have not found this to be the case. The trick to making SOAP calls with XMLHTTPRequest object is setting the right request headers before making the call. SOAP calls should also be made as a post rather than a get. Here is an example below;

xmlhttp.open("POST",url,true);

_ // set header for valid XML document_

xmlhttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');

_ // Set the SOAPAction header, ColdFusion will look for the SOAPAction header._

xmlhttp.setRequestHeader('SOAPAction','http://www.fekke.com/com/Wright/getQuote');

I am going to be redoing portions of my main site using Ajax. Here is a [preview](http://www.fekke.com/index.cfm?fuseaction=home.wrightajax) of my Quote from Steven Wright as an Ajax app. IBM also has a [javascript framework](http://www.ibm.com/developerworks/webservices/library/ws-wsajax/) for making SOAP based web service calls.
← Previous Page  Next Page →