



This library is used to establish communication with SOAP services from client-side JavaScript. Implementation of this code deals with browser cross-domain violation by means of proxying requests through a server-side code (unless service resides on the same domain as your application). Example of simple proxy is demonstrated. This library relies on jQuery platform for it's ability to perform AJAX requests, this feature can easily be replaced by either a custom code or similar functionality of other javaScript packages.
SOAP Client library is a set of three core classes: SOAPClient, SOAPRequest and SOAPObject.
SOAPClient is a singleton(static) wrapper that exposes basic functionality to send a SOAPRequest to the web-service and get a response in a form of a JSON object. SOAPRequest is a class that packages all required envelope components as well as SOAPAction into one convenient package. SOAPObject is a class that is used to assemble envelope data content and represents a single SOAP node element.
So your basic usage scenario would be:
Lets take a look at code example:
//First lets include three required libraries
<script language="javascript" src="jquery.js"></script>
<script language="javascript" src="jqXMLUtils.js"></script>
<script language="javascript" src="jqSOAPClient.js"></script>
JavaScript:
var soapBody = new SOAPObject("testObject"); //Create a new object that we want to send to a web service
soapBody.attr("type","test"); //Setting attributes of that object
soapBody.val("Hello World"); //Setting value of that object
//You can also use chained method that looks like this:
// var soapBody = new SOAPObject("testObject").attr("type","test").val("Hello World");
//Create a new SOAP Request
var sr = new SOAPRequest("MyAction", soapBody); //Request is now ready to be sent to a web-service
//Lets send it
SOAPClient.Proxy = "http://my-ws.com/webservice/"; //Specify web-service address (if local to your domain) or a proxy file
SOAPClient.SendRequest(sr, processResponse); //Send request to server and assign callback function
function processResponse(respObj) { //respObj is a JSON equivalent of SOAP Response XML (all namespaces are dropped)
//... do something with response
}
This SOAP implementation does NOT use WSDL to resolve request and response entities which is a plus and a minus. It's a plus because there is no extra validation logic that takes time, and there is no caching of WSDL that can be quite big. It's a minus, because what you get back from the server is JSON envelope and not an Object that corresponds to WSDL, instead you have to extract the data you need by accessing Body and it's sub items directly. I also implemented only asynchronous request type, since I see very little use of using it synchronously. So let me just summarize it's features as Cons and Pros:
Pros:
Cons:
For all support question and suggestions please visit jQuery project page or Comments section.
Thank You,
Sam Tsvilik - Author


