WCF Create and Example in asp.net
File ---> New Website ---> WCF Services
IServices.cs :
public interface IService
{
[OperationContract]
int Sum(int a,int b);
}
public class Service : IService
{
public void Add()
{
}
#region IService Members
//Class and Function Call
//Class and Function Call
int IService.Sum(int a, int b)
{
return (a + b);
}
#endregion
#endregion
}
---> Run the Program F5
URL Create :
---> Add Reference:
Website ---> Add Service Reference...
Sample aspx Create and Run WCF :
<div align="center">
A:
<asp:TextBox ID="txtA" runat="server"></asp:TextBox>
<br />
B:
<asp:TextBox ID="txtB" runat="server"></asp:TextBox>
<br />
<asp:Button ID="btnAdd" runat="server" Text="Add"
onclick="btnAdd_Click"/>
<br />
<asp:Label ID="lblAns" runat="server"></asp:Label>
</div>
aspx:cs
protected void btnAdd_Click(object sender, EventArgs e)
protected void btnAdd_Click(object sender, EventArgs e)
{
// FirstWCF Reference Name,NameSpace
FirstWCF.ServiceClient objFirstWcf = new FirstWCF.ServiceClient();
// FirstWCF Reference Name,NameSpace
FirstWCF.ServiceClient objFirstWcf = new FirstWCF.ServiceClient();
int A,B,Add;
A=Convert.ToInt16(txtA.Text);
B=Convert.ToInt16(txtB.Text);
//Service.cs Function Call SUM
Add = objFirstWcf.Sum(A,B);
//Response.Write("Ans :" +Add);
lblAns.Text = "Ans :" + Add;
}
ANS :
No comments:
Post a Comment