https://draft.blogger.com/blogger.g?blogID=2843354162346714112#editor/target=page;pageID=8609212820098816612
What is WCF?
WCF stands for Windows Communication Foundation and is part of .NET 3.0. WCF is Microsoft platform for building distributed and interoperable applications.
What is a distributed application?
In simple terms a distributed application, is an application where parts of it run on 2 or more computers. Distributed applications are also called as connected systems.
1. A web service to exchange messages in XML format using HTTP protocol for interoperability.
2. A remoting service to exchange messages in binary format using TCP protocol for performance.
http://csharp-video-tutorials.blogspot.in/2013/11/part-2-creating-remoting-service-and_17.html
Example:- HelloWebService.asmx.cs.
using System.Web.Services;
namespace WebServicesDemo
{
[WebService(Namespace = "http://pragimtech.com/WebServices")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class HelloWebService : System.Web.Services.WebService
{
[WebMethod]
public string GetMessage(string name)
{
return "Hello " + name;
}
}
}
//==============================
Build the solution.
Creating a client for the Web Service.
1. Right click on WebServicesDemo solution in solution explorer and add a new asp.net empty web application project and name it HelloWebApplication.
2. Right click on References folder in HelloWebApplication project and select Add Service Reference option. In Add Service Reference dialog box click the Discover button. In the namespace textbox type HelloWebService and click OK. This should generate a proxy class to invoke the HelloWebService.
3. Right click on HelloWebApplication project name in solution explorer and a new web form. This should add WebForm1.aspx
4. Copy and paste the following HTML on WebForm1.aspx
<table style="font-family:Arial">
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Get Message"
onclick="Button1_Click" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Font-Bold="true">
</asp:Label>
</td>
</tr>
</table>
5. Copy and paste the following code in WebForm1.aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
HelloWebService.HelloWebServiceSoapClient client = new
HelloWebService.HelloWebServiceSoapClient();
Label1.Text = client.GetMessage(TextBox1.Text);
}
What is WCF?
WCF stands for Windows Communication Foundation and is part of .NET 3.0. WCF is Microsoft platform for building distributed and interoperable applications.
What is a distributed application?
In simple terms a distributed application, is an application where parts of it run on 2 or more computers. Distributed applications are also called as connected systems.
1. A web service to exchange messages in XML format using HTTP protocol for interoperability.
2. A remoting service to exchange messages in binary format using TCP protocol for performance.
http://csharp-video-tutorials.blogspot.in/2013/11/part-2-creating-remoting-service-and_17.html
Example:- HelloWebService.asmx.cs.
using System.Web.Services;
namespace WebServicesDemo
{
[WebService(Namespace = "http://pragimtech.com/WebServices")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class HelloWebService : System.Web.Services.WebService
{
[WebMethod]
public string GetMessage(string name)
{
return "Hello " + name;
}
}
}
//==============================
Build the solution.
Creating a client for the Web Service.
1. Right click on WebServicesDemo solution in solution explorer and add a new asp.net empty web application project and name it HelloWebApplication.
2. Right click on References folder in HelloWebApplication project and select Add Service Reference option. In Add Service Reference dialog box click the Discover button. In the namespace textbox type HelloWebService and click OK. This should generate a proxy class to invoke the HelloWebService.
3. Right click on HelloWebApplication project name in solution explorer and a new web form. This should add WebForm1.aspx
4. Copy and paste the following HTML on WebForm1.aspx
<table style="font-family:Arial">
<tr>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Get Message"
onclick="Button1_Click" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label1" runat="server" Font-Bold="true">
</asp:Label>
</td>
</tr>
</table>
5. Copy and paste the following code in WebForm1.aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
HelloWebService.HelloWebServiceSoapClient client = new
HelloWebService.HelloWebServiceSoapClient();
Label1.Text = client.GetMessage(TextBox1.Text);
}
No comments:
Post a Comment