Click here to Skip to main content
15,895,606 members
Articles / Web Development / IIS

Call XML Web service from ASP

Rate me:
Please Sign up or sign in to vote.
3.78/5 (9 votes)
9 May 20071 min read 137.2K   3.6K   46  
How to Give a call to XML Web Service through ASP
<html>
<head>
<title>Calling a webservice from classic ASP</title>
</head>
<body>
<%
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
    Dim xmlhttp
    Dim DataToSend
    DataToSend="val1="&Request.Form("text1")&"&val2="&Request.Form("text2")
    Dim postUrl
    If Request.Form.Item("Operation")="Sum" Then
		postUrl = "http://localhost/Test_ASP_Service1/Service1.asmx/Sum"
	else
	    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(xmlhttp.responseText)
Else
    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">
<BR><BR>
<INPUT type="submit" value="GO" name="submit1" ID="Submit1">
</form>
</body>
</html></PRE>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Web Developer
United States United States
Optimistic....... and Looking forward

Comments and Discussions