ASP.NET Web Services
::
1) Project-1 : (Name
is Service Provider )
Visual Studio à
New project à
web à(
Asp.Net Web Application) à
(Name it as Service Provider ).
Now right click on (Service Provider) project à Add New Items à Select (WebServices
(ASMX)) and Name it as CALCULATOR.asmx)
( CALCULATOR.asmx ) :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace Service_Provider
{
/// <summary>
/// Summary description for CALCULATOR
/// </summary>
[WebService(Namespace = "http://pauldotnet.blogspot.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow
this Web Service to be called from script, using ASP.NET AJAX, uncomment the
following line.
//
[System.Web.Script.Services.ScriptService]
public class CALCULATOR : System.Web.Services.WebService
{
[WebMethod] //this is called a Attribute which is says that the services are
defined here.
public int Add(int x, int y) // Addition Here.
{
return x + y;
}
}
}
Build the
Project Once
2) Project-2 : (Name
is Service_Consumer)
Add a New Project:
Right click on project à Add à
New project à
web à(Asp.Net
Web Application) à
(Name it as Service_Consumer ).
Now Generate the proxy classes , below is the step:à
Goto Project-2 à Right Click on
(Project-2) à Add à Service References-
Select Address
http://localhost:61495/CALCULATOR.asmx
Namespace : CALCULATOR (Write it down)
Then OK.
3) Goto Service_Consumer project)
Right click on on project à ADD à
Web Form à (Name it as User_Interface)
[User_Interface.aspx]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="User_Interface.aspx.cs" Inherits="Service_Consumer.User_Interface" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td>
<asp:Label ID="tbl1" runat="server" Text="Enter
First Number :"></asp:Label><br />
<asp:TextBox ID="txt_first" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbl2" runat="server" Text="Enter
Second Number :"></asp:Label><br />
<asp:TextBox ID="txt_second" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbl3" runat="server" Text="RESULT
IS :"></asp:Label>
<asp:TextBox ID="txt_result" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btn_add" runat="server" Text="ADD" OnClick="btn_add_Click"></asp:Button>
</td>
</tr>
</table>
</form>
</body>
</html>
[User_Interface.cs]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Service_Consumer
{
public partial class User_Interface : System.Web.UI.Page
{
protected void
Page_Load(object sender, EventArgs e)
{
}
protected void
btn_add_Click(object sender, EventArgs e)
{
CALCULATOR.CALCULATORSoapClient obj = new CALCULATOR.CALCULATORSoapClient();
int final = obj.Add(Convert.ToInt32(txt_first.Text), Convert.ToInt32(txt_second.Text));
txt_result.Text = Convert.ToString(final);
}
}
}
NOW
Run the (User_Interface.aspx) PAGE:
HOME BACK |
No comments:
Post a Comment