Ask the Expert

Calling a Web service from JavaScript

I am new to Web services, and I need your help to know how to call a Web service (JAX-RPC model or Apache SOAP model) from JavaScript. Do I need any special tools for doing this?

    Requires Free Membership to View

If you are using Microsoft IE 5 or later, you can use the behavior/HTML-Component "WebService" to access a Web service. The "WebService" behavior communicates with Web services over HTTP using Simple Object Access Protocol (SOAP).

To use the "WebService" behavior, you must attach it to an element using the STYLE attribute, as follows:

<DIV ID="GiveItAName"

A complete example taken from the Microsoft Web site is as follows:

<script language="JavaScript"> 
var iCallID; function init() 

("", "servicename"); 

function onmyresult() 

if ((event.result.error)&&( 
  var xfaultcode = event.result.errorDetail.code; 
  var xfaultstring = event.result.errorDetail.string;    
  var xfaultsoap = event.result.errorDetail.raw; 
Add code to output error information here alert("Error ");   } 
  service.innerHTML= "The method returned the result: " 
                    + event.result.value; 

<body onload="init();"> 
Enter a Value 
<input type='text' id='param1'> 
<button onclick='iCallID = service.servicename.callService ("ProcedureName", param1.value);'>
Call A Web Method
<div id="service" 


This was first published in March 2004

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: