Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / Javascript

Calling Web Services From JavaScript - Using SOAP Client

4.63/5 (15 votes)
12 Feb 2009CPOL 179.2K   6.2K  
We can call any web service method using JavaScript soap client
html_small.JPG

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.

C#
//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. :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)