What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 12359 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > ASP.NET > Calling XML webservice through classic ASP ...
Nakul.Lande

Calling XML webservice through classic ASP

 Code Snippet posted by: Nakul.Lande | Posted on: 8/16/2012 | Category: ASP.NET Codes | Views: 846 | Status: [Member] | Points: 40 | Alert Moderator   


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
This article contains to major Part :-
1. .Net XML Web Service
2. ASP Web application calling the XML Web service.

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

using System.Diagnostics;

using System.Web;
using System.Web.Services;
namespace Test_ASP_Service1
{
public class Service1 : System.Web.Services.WebService
{
public Service1()
{
//CODEGEN: This call is required by the ASP.NET Web Services Designer
InitializeComponent();
}
private IContainer components = null;
private void InitializeComponent()
{}
protected override void Dispose( bool disposing )
{
if(disposing && components != null)
{ components.Dispose(); }
base.Dispose(disposing);
}
[WebMethod]
public string Sum(int val1,int val2)
{
return "The Sum of two number= "+(val1+val2);
}
[WebMethod]
public string Subtract(int val1,int val2)
{
return "The Subtraction of two number= "+ ( (val1>val2) ? (val1-val2):(val2-val1));
}
}
}


Next is the ASP Web application code calling the Web Service.
<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>


Nakul Lande
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/24/2013 3:44:25 PM