Calling Web Services From JavaScript - Using SOAP Client






4.63/5 (14 votes)
We can call any web service method using JavaScript soap client
Introduction
This article will show you how to make a web service call using only HTML markup and JavaScript.
Background
This article is based on JavaScript SOAP Client on http://www.codeplex.com/JavaScriptSoapClient.
Using the Code
Just copy and and change the scripts and markups. You can see a JavaScript example below.
//Calls Hello World Web Method.
var url = document.location.href.replace("default.htm", "webservicedemo.asmx");
// DEMO 1
function HelloWorld()
{
var pl = new SOAPClientParameters();
SOAPClient.invoke(url, "HelloWorld", pl, true, HelloWorld_callBack);
}
function HelloWorld_callBack(r)
{
alert(r);
}
// End of script.
That's all guys.
Points of Interest
I already knew how to make a web service call from JavaScript using webservice.htc. I could not make these calls on browsers other than Internet Explorer. So I searched and found this method. It is so simple to use. Add soapclient.js to your project and some code like the above. Then call it with something like button, etc.
History
- 12th February, 2009: Initial post
I will be waiting for your questions. If you like it, please vote. :)