Click here to Skip to main content
14,208,191 members
Click here to Skip to main content
Add your own
alternative version


46 bookmarked
Posted 9 May 2007

Call XML Web service from ASP

, 9 May 2007
Rate this:
Please Sign up or sign in to vote.
How to Give a call to XML Web Service through ASP


This article helps you to understand about how to give a call to XML Web service through ASP Web application and retrieve the values from the service


Designing the web service and calling/using it in ASP.NET is a very easy part because Microsoft .NET technology provides inherent/inbuilt support for it. But doing the same through classic ASP web application is little bit tricky...........

Using the code

This article contains to major Part

1. .Net Web Service

2. ASP Web application calling the XML Web service.

Here is our .Net Web Service Code

using System.Diagnostics;
using System.Web;
using System.Web.Services;
namespace Test_ASP_Service1


/// <span class="code-SummaryComment"><summary>
</span>/// Summary description for Service1.
/// <span class="code-SummaryComment"></summary>
public class Service1 : System.Web.Services.WebService

public Service1()
    //CODEGEN: This call is required by the ASP.NET Web Services Designer


#region Component Designer generated code
//Required by the Web Services Designer 

private IContainer components = null;
private void InitializeComponent()

protected override void Dispose( bool disposing )
    if(disposing && components != null)


public string Sum(int val1,int val2)
    return "The Sum of two number= "+(val1+val2);
public string Subtract(int val1,int val2)
    return "The Subtraction of two number= "+ ( (val1>val2) ? (val1-val2):(val2-val1));


The Web Service contain Two web-methos Sum() and Subtract() performing the relative operation.

Next is the ASP Web application code calling the Web Service.

<title>Calling a webservice from classic ASP</title>
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
Dim xmlhttp
Dim DataToSend
Dim postUrl
If Request.Form.Item("Operation")="Sum" Then
postUrl = "http://localhost/Test_ASP_Service1/Service1.asmx/Sum"
postUrl = "http://localhost/Test_ASP_Service1/Service1.asmx/Subtract"
end if
Set xmlhttp = server.Createobject("MSXML2.XMLHTTP")
xmlhttp.Open "POST",postUrl,false
xmlhttp.setRequestHeader "Content-Type","application/x-www-form-urlencoded"
xmlhttp.send DataToSend
Response.Write DataToSend & "<br>"
Response.Write "Loading for first Time"
End If
<FORM method=POST name="form1" ID="Form1">
Enter the two Values to perform Operation<BR>
<select name="Operation">Select Operation<option value="Sum">Sum</option><option value="Subtraction">Subtraction</option></select>
<INPUT type="text" name="text1" ID="Text1">
<INPUT type="text" name="text2" ID="Text2">
<INPUT type="submit" value="GO" name="submit1" ID="Submit1">

Points of Interest

The Result getting back from XML Web service is in the form of string. So if you want the bulky result like dataset values or table , you have to tokenize the result as per desire.


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

Nakul Lande
Web Developer
United States United States
Optimistic....... and Looking forward

Comments and Discussions

Questionnot working when connect with live server Pin
amna876-Aug-13 2:13
professionalamna876-Aug-13 2:13 
AnswerRe: not working when connect with live server Pin
lenas111-Dec-17 10:02
memberlenas111-Dec-17 10:02 
QuestionThanks for the code Pin
NakulLande25-Jul-12 9:53
memberNakulLande25-Jul-12 9:53 
GeneralMy vote of 5 Pin
jmoller515-Oct-11 2:50
memberjmoller515-Oct-11 2:50 
QuestionDoes it need MSXML parser? Pin
jim.chb31-Jan-10 16:44
memberjim.chb31-Jan-10 16:44 
GeneralSame code not working Pin
Adeel Taseer29-Sep-08 6:14
memberAdeel Taseer29-Sep-08 6:14 

I tried your code and it works fine if Web Service and ASP page are on the same server, but if WebService is at different IIS, then it won't work. It won't give any error but Response XML is empty. Have you ever encountered this kind of problem. I have also tried with Response.ResponseText and it ain't work either. Please let me know if you have any solutio to that.


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 | Cookies | Terms of Use | Mobile
Web01 | 2.8.190612.1 | Last Updated 10 May 2007
Article Copyright 2007 by Nakul Lande
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid