I would like to call a SOAP WebService directly from Javascript. I have been looking all around but still is unable to have something working. I assumed that i must build the SO
You cannot send cross domain AJAX requests because of the same origin policy restriction that's built into the browsers. In order to make this work your HTML page containing the jQuery code must be hosted on the same domain as the Web Service (http://192.168.1.5/ws/MyWS/
).
There are workarounds that involve using JSONP on the server, but since your web service is SOAP this cannot work.
The only reliable way to make this work if you cannot move your javascript on the same domain as the web service is to build a server side script that will be hosted on the same domain as the javascript code and that will act as a bridge between the 2 domains. So you would send an AJAX request to your server side script which in turn will invoke the remote web service and return the result.
below code is working fine. may be it may help you.
var SoaMessage = '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >'
+ '<soapenv:Header/>'
+ '<soapenv:Body>'
+ '<myoperation soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns="http://MyService/"> '
+ ' <AgencyId xsi:type="xsd:string">ADBC</AgencyId >'
+ '</myoperation >'
+ '</soapenv:Body>'
+ '</soapenv:Envelope>';
var url = "http://XXXXXXX/XXX/XXXXX?wsdl";
$.support.cors = true;
$.ajax({
type: "POST",
url: url,
jsonpCallback: "MyCallbackDED",
dataType: "xml",
processData: false,
contentType: "text/xml; charset=\"utf-8\"",
success: function (msg) {
alert("suc: " + msg.tradeLicenseData.master[0].arabicAddress + ": " + msg.tradeLicenseData.master[0].arabicAddress);
},
error: function (msg) {
alert("Failed: " + msg.status + ": " + msg.statusText);
}
});
How about this? https://github.com/doedje/jquery.soap
Seems easy enough. Maybe it will help you.
Example:
$.soap({
url: 'http://my.server.com/soapservices/',
method: 'helloWorld',
data: {
name: 'Remy Blom',
msg: 'Hi!'
},
success: function (soapResponse) {
// do stuff with soapResponse
// if you want to have the response as JSON use soapResponse.toJSON();
// or soapResponse.toString() to get XML string
// or soapResponse.toXML() to get XML DOM
},
error: function (SOAPResponse) {
// show error
}
});
will result in
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<helloWorld>
<name>Remy Blom</name>
<msg>Hi!</msg>
</helloWorld>
</soap:Body>
</soap:Envelope>