Click here to Skip to main content
13,355,335 members (74,566 online)
Click here to Skip to main content
Add your own
alternative version


40 bookmarked
Posted 23 Jun 2005

Calling a WebService from ASP3.0 and JavaScript

, 23 Jun 2005
Rate this:
Please Sign up or sign in to vote.
Calling a WebService from ASP3.0 and JavaScript.


I don’t know whether any body has faced this problem or not but we were stuck deep in a hole. Problem was to create a web service and consume it from ASP.NET and ASP 3.0.

Creating the web service and consuming it in ASP.NET was the easy part because .NET provides inherent support for it. Interesting part was to consume the same web service in ASP 3.0.

After much digging, I found three completely different ways in which this could be done.

  1. Using client-side JavaScript.
  2. Using Microsoft SOAP Toolkit 2.0.
  3. Using the .NET Framework and MSXML parser (the approach I used).

Using Client-Side JavaScript

I came across a few very good resources for this approach. Below are the links:

Using Microsoft SOAP Toolkit 2.0

This technique is the most common and prevalent way and easiest to use. But Microsoft recommends not to use it. Please check this link.

What they say is:

“The SOAP Toolkit has been decremented by the .NET Framework. SOAP Toolkit support will be retired in April 2005 with extended support retiring in April 2008.”

Still for the uninitiated ones, here is the ‘how to’ and the ‘code’ for using this technique:

<title>Calling a webservice from classic ASP, using the SOAP Toolkit</title>
‘Only to process a Post Request
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
    Dim oSOAP
    'Create an object of Soap Client
    Set oSOAP = Server.CreateObject("MSSOAP.SoapClient")
    oSOAP.ClientProperty("ServerHTTPRequest") = True
    'Initaialize the Web Service
    'Invoke the Web Service
    Response.write(oSOAP.Add(Request.Form("text1"), _
                   Request.Form("text2")) & "<BR>")
End If
<FORM method=POST name="form1">
Enter the two Values to be Added.<BR>
<INPUT type="text" name="text1">
<INPUT type="text" name="text2">
<INPUT type="submit" value="Add" name="submit1">

Using MSXML Parser

This technique leverages the .NET framework and MSXML parser for calling the Web Service in ASP 3.0. Below is the sample code. You need to install the .NET framework which is free to download.

<title>Calling a webservice from classic ASP</title>
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
    Dim xmlhttp
    Dim DataToSend
    Dim postUrl
    postUrl = " http://localhost/Add/SimpleAddService.asmx/Add"
    Set xmlhttp = server.Createobject("MSXML2.XMLHTTP")
    xmlhttp.Open "POST",postUrl,false
    xmlhttp.setRequestHeader "Content-Type", _
            "application/x-www-form-   urlencoded"
    xmlhttp.send DataToSend
End If
<FORM method=POST name="form1">
Enter the two Values to be Added<BR>
<INPUT type="text" name="text1">
<INPUT type="text" name="text2">
<INPUT type="submit" value="Add" name="submit1">

I will need to explain a few things over here.


The following are a sample HTTP POST request and response. The placeholders shown need to be replaced with actual values.

POST /Add/SimpleAddService.asmx/Add HTTP/1.1
Host: localhost
Content-Type: application/x-www-form-urlencoded
Content-Length: length

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="">string</string>

What you see above is the way you need to make a request and get a response to the web service if you use HTTP POST. So, why do I need to explain this to you. It’s because, if we want to invoke the web service using XMLHTTP then we need to construct the Request message that is to be posted, and only after the successful post can we expect a correct response.

In the middle I missed an important thing. This question may have crossed your mind that why do we need the POST method and why not the GET method? Yes, we can very well invoke a web service using GET method, but I can't pass parameters to the WEBMETHOD using GET. I don’t understand how it's possible but still if anyone is aware of a technique then please do update me about that by dropping a mail at as I am really looking forward to it.

That’s the key.


This is the line over where we are constructing the data that is to be sent in the HTTP POST.

xmlhttp.Open "POST",postUrl,false

This line indicates that the method to be used is POST and the postUrl is the URL to which the request has to be sent.

xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"

We set the request header over here setting the Content-Type.

And then the data is posted. That’s it and finally we use responseText to get the text returned from the web service. If you want, you can very well set the response content type to be XML and then get the data in XML form by using xmlhttp.responseXml. It all depends on your needs. I have tried my best to lay out what I understand of this particular technique.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

Generalcalling a WEBSERVICE .NET FROM ASP CLASSIC .... the result is a Class Pin
JuanEsteban21-Dec-07 14:18
sussJuanEsteban21-Dec-07 14:18 
GeneralGetting Error - Argument 'Length' must be greater or equal to zero. Pin
gcdand15-Nov-07 2:26
membergcdand15-Nov-07 2:26 
GeneralAjax solution Pin
semenoff18-Sep-07 9:40
membersemenoff18-Sep-07 9:40 
Generalerror using MSXML PARSER Pin
Vhakti22-Nov-06 12:58
memberVhakti22-Nov-06 12:58 
NewsA cross browser SOAP client Pin
Matthias Hertel18-Jul-06 6:54
memberMatthias Hertel18-Jul-06 6:54 
QuestionWhat about ATLAS? Pin
dlesko8-Mar-06 14:56
memberdlesko8-Mar-06 14:56 
AnswerRe: What about ATLAS? Pin
ipsit.naik12-Mar-06 3:28
memberipsit.naik12-Mar-06 3:28 
GeneralRe: What about ATLAS? Pin
dlesko12-Mar-06 5:44
memberdlesko12-Mar-06 5:44 
GeneralRe: What about ATLAS? Pin
ipsit.naik12-Mar-06 6:14
memberipsit.naik12-Mar-06 6:14 
GeneralNo Longer works in Net 2.0 Pin
teddyg24531-Feb-06 18:46
memberteddyg24531-Feb-06 18:46 
AnswerRe: No Longer works in Net 2.0 Pin
Jeffrey Kohler4-Apr-06 6:46
memberJeffrey Kohler4-Apr-06 6:46 
GeneralRe: No Longer works in Net 2.0 Pin
Delie18-Oct-06 6:51
memberDelie18-Oct-06 6:51 
GeneralRe: No Longer works in Net 2.0 Pin
Klok27-Dec-06 23:22
memberKlok27-Dec-06 23:22 
GeneralRe: No Longer works in Net 2.0 Pin
sulley5-Dec-06 6:54
membersulley5-Dec-06 6:54 
GeneralRe: No Longer works in Net 2.0 Pin
Truck868-Feb-07 3:28
memberTruck868-Feb-07 3:28 
GeneralRe: No Longer works in Net 2.0 Pin
Harish Mokhasania27-Mar-07 8:28
memberHarish Mokhasania27-Mar-07 8:28 
GeneralRe: No Longer works in Net 2.0 Pin
mikepc2-Mar-08 2:53
membermikepc2-Mar-08 2:53 
GeneralUsing MSXML Parser: has a bug: ServerXMHTTP should have been used Pin
Umut Alev25-Jul-05 22:11
memberUmut Alev25-Jul-05 22:11 
GeneralRe: Using MSXML Parser: has a bug: ServerXMHTTP should have been used Pin
Umut Alev25-Jul-05 22:13
memberUmut Alev25-Jul-05 22:13 
GeneralGreat Article Pin
RichTeel18-Jul-05 9:25
memberRichTeel18-Jul-05 9:25 
GeneralWebServices using GET Pin
DjDanny3-Jul-05 23:49
memberDjDanny3-Jul-05 23:49 
GeneralRe: WebServices using GET Pin
ipsit.naik12-Mar-06 3:30
memberipsit.naik12-Mar-06 3:30 
GeneralRe: WebServices using GET Pin
HITALFvn29-Jun-06 19:09
memberHITALFvn29-Jun-06 19:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 24 Jun 2005
Article Copyright 2005 by ipsit.naik
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid