Introduction to endpoint in wcf

What is endpoint

Every service has a unique address and this unique address has three attribute that is Address, Binding and Contract. In other word we can say endpoint is a combination of address, binding and contract. If you don’t know about address, binding and contract then please read my previous article introduction to wcf. In this article I ll give you a short note about these three attributes of endpoint.
Address: contain information about where service can be found.
Binding: contain information about how a client can communicate with service.
Contract: It’s an agreement between service and client.
There is one more property in endpoint that is behavior. Behavior is not an attribute of endpoint.
Behavior: A set of behaviors that specify local implementation details of the endpoint.
Let me describe using example. I am using my previous demo project.
In ImyService.cs

namespace myFirstApp
public interface IMyService
int AddTwoNo(int intFirstNo, int intSecondNo);

In MyService.svc.cs

namespace myFirstApp
public class MyService : IMyService
public int AddTwoNo(int intFirstNo, int intSecondNo)
return intFirstNo + intSecondNo;

Endpoint using web.config

<?xml version="1.0"?>
 <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
 <compilation debug="true" targetFramework="4.5" />
 <httpRuntime targetFramework="4.5"/>
 <service name="myFirstApp.MyService" behaviorConfiguration="serviceBehaviour">
 <!--endpoint start here-->
 <endpoint address="addTwo" binding="basicHttpBinding" contract="myFirstApp.ImyService"></endpoint>
 <!--endpoint end here-->
 <add baseAddress="http://localhost:36246/"/>
 <behavior name="serviceBehaviour">
 <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
 <serviceDebug includeExceptionDetailInFaults="false"/>
 <add binding="basicHttpsBinding" scheme="https" />
 <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
 <modules runAllManagedModulesForAllRequests="true"/>
 <directoryBrowse enabled="true"/>

Let’s update my service reference.
In default.aspx 

<tr><td>First No</td><td><asp:TextBox ID="txtFirst" runat="server"></asp:TextBox></td></tr>
<tr><td>Second No</td><td><asp:TextBox ID="txtSec" runat="server"></asp:TextBox></td></tr>
<tr><td colspan="2"><asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" /></td>
<tr><td colspan="2"><asp:Label ID="lblResult" runat="server"></asp:Label></td></tr>

In default.aspx.cs

using System;
namespace WCFClientApp
public partial class _default : System.Web.UI.Page
protected void btnAdd_Click(object sender, EventArgs e)
int intFirstNo = 0, intSecNo = 0, intResult = 0;
 intFirstNo = Convert.ToInt16(txtFirst.Text);
 intSecNo = Convert.ToInt16(txtSec.Text);
 WCFReference.MyServiceClient client = new WCFReference.MyServiceClient();
 intResult = client.AddTwoNo(intFirstNo, intSecNo);
 lblResult.Text = "Result is :"+intResult;

Run the application and get result as expected.
I hope this article is helpful for you.
Thanks :)

Tags: , , , ,