Suppose there is a based on. NET Web Service with the name Saveproduct
post/productservice.asmx http/1.1host:localhostcontent-type:text/xml; Charset=utf-8content-length: Lengthsoapaction: "Http://sh.inobido.com/SaveProduct"<?XML version= "1.0" encoding= "Utf-8"?><Soap:envelopeXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd= "Http://www.w3.org/2001/XMLSchema"Xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/"> <Soap:body> <saveproductxmlns= "http://sh.inobido.com/"> <ProductID>Int</ProductID> <ProductName>String</ProductName> <manufacturedate>Datetime</manufacturedate> </saveproduct> </Soap:body></Soap:envelope>
The code for the AJAX call on the client with jquery is
varProductserviceurl = ' http://localhost:57299/ProductService.asmx?op=SaveProduct ';//preferably write this off from server side functionbeginsaveproduct (ProductID, ProductName, manufacturedate) {var SoapMessage=<soap:envelope xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd= "http://www.w3.org/2001/ XmlSchema "xmlns:soap=" http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <saveproduct xmlns=" http://sh.inobido.com/"> <productID>' + ProductID + '</productID> <productName>' + ProductName + '</productName> <manufactureDate>' + Manufacturedate + '</manufactureDate> </SaveProduct> </soap:Body> </soap:Envelope>‘; $.ajax ({url:productserviceurl, type:"POST", DataType:"XML", data: SoapMessage, complete: endsaveproduct, ContentType:"Text/xml; Charset=\ "Utf-8\" "}); return false;} function endsaveproduct (xmlhttprequest, status) {$ (xmlhttprequest.responsexml). Find (' Saveproductresult '). each (function() {varName = $ ( This). Find (' Name '). text (); });}
Description
- Type : types of requests sent-the type of request we ' re sending
- dataType: The type of response that is sent back-the type of the response will, in general, can be a type of HTML, JSON, and so on, but if it is a SOAP Web service, it must be defined as XML Type
- Data: Actual information sent to the Web service
- Complete: function (XMLHttpRequest, textstatus) {/* Code goes here */}
- contentType: The MIME content type of the request, similarly, if it is a SOAP Web service, it must be defined as "Text/xml"
- endsaveproduct: The XML data is now sent to the Web service, and once server server accepts the request and processes it, the Endsaveproduct method is called
If the XML response returned with jquery is processed, the SOAP reponse's schema definition must be understood, and the schema format of the saveproduct is as follows:
http/1.1 okcontent-type:text/xml; charset=utf-8content-length:length<?XML version= "1.0" encoding= "Utf-8"?><Soap:envelopeXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd= "Http://www.w3.org/2001/XMLSchema"Xmlns:soap= "http://schemas.xmlsoap.org/soap/envelope/"> <Soap:body> <Saveproductresponsexmlns= "http://sh.inobido.com/"> <Saveproductresult> <ID>Int</ID> <Name>String</Name> <manufacturedate>Datetime</manufacturedate> </Saveproductresult> </Saveproductresponse> </Soap:body></Soap:envelope>
The returned response is placed in the XMLHttpRequest parameter responsexml , which can be used firebug or dev. Tool view, we can now use jquery to traverse the node of the XML and process the data.
Excerpt from: http://openlandscape.net/2009/09/25/call-soap-xm-web-services-with-jquery-ajax/