Maverick

Friday, August 17, 2007

Calling Web Service using XMLHTTP Object

Filed under: ASP.NET, C# — debasishpramanik @ 8:26 pm
Tags: , , ,

Follow the steps to invoke a webservice using a XMLHTTP object in javascript

Step  1: Create a soap envelope for the requested method.

soapenvelope.gif

 var envelope = <The above string>;

Step 2: Create Instance of XMLHTTP Object

Now in the Javascript method create an instance of the XMLHTTP object

 xmlhttp.gif

 Step 3: Prepare the Webservice Request

 As shown above the url points the target webservice which is Service.asmx file and named of the method is HelloWorld. The syntax to be used

url1.gif
http://<Host Name>/<Virtual Directory>/<Webservice>/Method Name

in the next line we are initiating a POST request for the webservice url.

Step 4: Handling the Callback

callback.gif

Here when the response from the web service returns it just display the return string in alert box.

Step 5: Sending the  Request

 sendrequest1.gif

As shown above, the send message is send with the envelope  for the Web Method prepare in the Step 1.

Step 6: Executing the Web Service

calloutput.gif

Refer to this link for more  http://support.microsoft.com/default.aspx/kb/893659

2 Comments »

  1. Can the administrators set this page right please.

    Comment by Ganesh — Monday, October 15, 2007 @ 6:40 pm | Reply

  2. The post is nice n helpful for me.
    Can u tell me how to get the value within the xml nodes. I tried something like this
    alWSHttp.responseXML.xml.getElementsByTagName(“string”).firstChild.nodeValue;
    But it was giving run-time error.

    Comment by kalyan — Friday, November 7, 2008 @ 12:25 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.