{"id":297,"date":"2013-10-04T07:43:55","date_gmt":"2013-10-04T07:43:55","guid":{"rendered":"https:\/\/praveenkatiyar.wordpress.com\/?p=297"},"modified":"2013-10-04T07:43:55","modified_gmt":"2013-10-04T07:43:55","slug":"understanding-operations-in-wcf","status":"publish","type":"post","link":"https:\/\/praveenkatiyar.in\/blog\/index.php\/2013\/10\/04\/understanding-operations-in-wcf\/","title":{"rendered":"Understanding Operations in WCF"},"content":{"rendered":"<p>WCF supports 3 ways for a client to call a service.<\/p>\n<ol>\n<li><strong>Request Reply : <\/strong>default way of invocation, the client would issue a call, <strong>block<\/strong>&#160;<strong>while the call was in progress<\/strong>, and would <strong>continue executing once the method returned<\/strong>. If service doesn&#8217;t respond to the service within <strong>receiveTimeout<\/strong>, client will receive <i><strong>TimeOutException<\/strong><\/i>. <\/li>\n<li><strong>One way calls: <\/strong>fire and forget type operations. that simply means client will send a request to the server and does not care whether service execution was a success or failure. There is no return value from the server side. Client <strong>will be blocked only for a moment till it dispatches its call to service<\/strong>. Client <strong>can continue to execute its statement<\/strong>, <strong>after making one-way call to<\/strong> the service. sometime calls are queued at the server side to be dispatched one at a time. if the number of queued messages has exceeded the queue&#8217;s capacity, client will be blocked for the moment till the message is being queued. and as soon as the call is queued, the client will be unblocked and can continue executing, while the service processes the operation in the background. <\/li>\n<li><strong>Call back Operation:<\/strong> WCF Supports allowing a service to call back to its clients. They are specially useful, for <strong>notifying client(s) that something happened<\/strong> on the service side. call backs are also commonly referred as duplex operations. not all binding types support call back operations. for example HTTP (for obvious reasons of being a connectionless nature). only two commonly used binding that offer call backs are <strong>NetTcpBinding and NetNamedBinding<\/strong>. to offer call backs over HTTP, WCF offers the WSDualHttpBinding, which actually sets up two WS channels.&#160; <\/li>\n<\/ol>\n<p>Now to see all these things in action let&#8217;s create a service. <\/p>\n<h3>Creating the Class Library<\/h3>\n<p>let&#8217;s create a service, create a new project, take a Class Library template, name it <strong>OperationLib<\/strong>, let&#8217;s do some house keeping with the newly created project.<\/p>\n<ul>\n<li>Delete the file<strong> Class1.cs<\/strong> from the project workspace. <\/li>\n<li>Add a new <strong>Interface<\/strong> named <strong>I<strong>RequestReplyService<\/strong> <\/strong>to the project, a new file <strong>I<strong>RequestReplyService<\/strong>.cs<\/strong> will be added to the project. 5t6 <\/li>\n<li>Add a new <strong>Class<\/strong> named <strong>RequestReplyService<\/strong>, to the project. that will implement the <strong>I<strong>RequestReplyService<\/strong> <\/strong>interface, a new file <strong><strong>RequestReplyService<\/strong>.cs<\/strong> will be added to the project. <\/li>\n<li>Add a new <strong>Interface<\/strong> named <strong>IOneWayCallService<\/strong> to the project, a new file <strong>IOneWayCallService.cs<\/strong> will be added to the project. <\/li>\n<li>Add a new <strong>Class <\/strong>named <strong>OneWayCallService<\/strong>, to the project. that will implement the <strong>I<strong>OneWayCallService <\/strong><\/strong>interface, a new file <strong>OneWayCallService.cs<\/strong> will be added to the project. <\/li>\n<li><\/li>\n<li>Add a new <strong>Interface<\/strong> named <strong>IDuplexService<\/strong> to the project, a new file <strong>IDuplexService.cs<\/strong> will be added to the project. <\/li>\n<li>Add a new <strong>Class<\/strong> named <strong>DuplexService<\/strong>, to the project. that will implement the <strong>IDuplexService <\/strong>interface, a new file <strong>DuplexService.cs<\/strong> will be added to the project. <\/li>\n<\/ul>\n<p>to keep the things simple, let&#8217;s assume that each interface defines only one method, which simply adds a passed value, to&#160; its member variable.<\/p>\n<h4>Defining Interfaces<\/h4>\n<p>so let&#8217;s define interface for each service.<\/p>\n<p><strong><font color=\"#000000\" face=\"Courier New\">\/\/ Listing of IRequestReplyService.cs<\/font><\/strong><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">using System;      <br \/>using System.Text;       <br \/>using System.ServiceModel;<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">namespace OperationLib      <br \/>{       <br \/>&#160;&#160;&#160; [ServiceContract]       <br \/>&#160;&#160;&#160; interface IRequestReplyService       <br \/>&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; [OperationContract]       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; double AddValue(double dblNum1, double dblNum2);       <br \/>&#160;&#160;&#160; }       <br \/>}       <br \/><\/font><\/p>\n<p><strong><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">       <br \/><\/font><\/strong><\/p>\n<p><strong><font color=\"#000000\" face=\"Courier New\">\/\/ Listing of RequestReplyService.cs<\/font><\/strong><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">using System;      <br \/>using System.Text;<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">namespace OperationLib      <br \/>{       <br \/>&#160;&#160;&#160; public class RequestReplyService : IRequestReplyService       <br \/>&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public double AddValue(double dblNum1, double dblNum2)       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return (dblNum1 + dblNum2);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }       <br \/>&#160;&#160;&#160; }       <br \/>}<\/font><\/p>\n<p><strong>\/\/ Listing of IOneWayCallService.cs<\/strong><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">using System;      <br \/>using System.ServiceModel;       <br \/>using System.Text;<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">namespace OperationLib      <br \/>{       <br \/>[ServiceContract(SessionMode = SessionMode.Required)]       <br \/>&#160;&#160; interface IOneWayCallService       <br \/>&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; [OperationContract(IsOneWay = true)]       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; void AddValue(double dblNum );<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160; [OperationContract]      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; double GetResult();       <br \/>&#160;&#160;&#160; }<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">}<\/font><\/p>\n<p><strong><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">       <br \/><\/font><\/strong><\/p>\n<p><strong>\/\/ Listing of OneWayCallService.cs<\/strong><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>public class OneWayCallService : IOneWayCallService        <br \/>&#160;&#160;&#160; {         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; private double m_dblResult = 0;<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public void AddValue(double dblVal)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_dblResult += dblVal;         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public double GetResult()        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return m_dblResult;         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }         <br \/>&#160;&#160;&#160; }<\/strong><\/font><\/p>\n<p><strong>\/\/ Listing of IDuplexService.cs<\/strong><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">using System;      <br \/>using System.ServiceModel;       <br \/>using System.Text;<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">namespace OperationLib      <br \/>{       <br \/>&#160;&#160;&#160; interface IDuplexServiceCallback       <br \/>&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; [OperationContract]       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; void OnValueAdded(double dblNum1, double dblNum2, double dblResult);       <br \/>&#160;&#160;&#160; }<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160; [ServiceContract(CallbackContract = typeof(IDuplexServiceCallback))]      <br \/>&#160;&#160;&#160; interface IDuplexService       <br \/>&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; [OperationContract()]       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; void AddValue(double dblNum1, double dblNum2);       <br \/>&#160;&#160;&#160; }       <br \/>}<\/font><\/p>\n<p><strong><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">       <br \/><\/font><\/strong><\/p>\n<p><strong>\/\/ Listing of DuplexService.cs<\/strong><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">using System;      <br \/>using System.ServiceModel ;       <br \/>using System.Text;<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">namespace OperationLib      <br \/>{       <br \/>&#160;&#160;&#160; public class DuplexService : IDuplexService       <br \/>&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public void AddValue(double dblNum1, double dblNum2)       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; double dblResult = dblNum1 + dblNum2;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; IDuplexServiceCallback callbackInstance = OperationContext.Current.GetCallbackChannel&lt;IDuplexServiceCallback&gt;();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; callbackInstance.OnValueAdded(dblNum1, dblNum2, dblResult);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }       <br \/>&#160;&#160;&#160; }       <br \/>}<\/font><\/p>\n<p>Now to see all these things in action let&#8217;s create a service. <\/p>\n<h3>Hosting the Service<\/h3>\n<p>for the sake of simplicity, i have have hosted this service as a self hosted service, to create the Host application, create a new <strong>Console based application<\/strong>.<\/p>\n<p>Before we write any code for the Host application, let&#8217;s define the configuration file for the Service(s).<\/p>\n<p>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;    <br \/>&lt;configuration&gt;     <br \/>&#160; &lt;system.serviceModel&gt;     <br \/>&#160;&#160;&#160; &lt;services&gt;     <br \/>&#160;&#160;&#160;&#160;&#160; <br \/><font color=\"#ff0000\"><strong>&#160;&#160;&#160;&#160; <\/strong><\/font><\/p>\n<p><font color=\"#ff0000\"><strong>&lt;!&#8211;************************* Request Reply Service **************************** &#8211;&gt;<\/strong><\/font>     <br \/>&#160; <font color=\"#0000ff\">&#160;&#160;&#160; &lt;service name=&quot;OperationLib.RequestReplyService&quot; behaviorConfiguration=&quot;<strong><font color=\"#ff0000\">RequestReplyServiceBehavior<\/font><\/strong>&quot;&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;host&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;baseAddresses&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;add baseAddress=&quot;http:\/\/localhost:9011\/RequestReplyService&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;add baseAddress=&quot;net.tcp:\/\/localhost:9012\/RequestReplyService&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/baseAddresses&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/host&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>http:\/\/localhost:9011\/RequestReplyService<\/strong>&quot; binding=&quot;<strong>wsHttpBinding<\/strong>&quot; contract=&quot;OperationLib.IRequestReplyService&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>net.tcp:\/\/localhost:9012\/RequestReplyService<\/strong>&quot; binding=&quot;<strong>netTcpBinding<\/strong>&quot; contract=&quot;OperationLib.IRequestReplyService&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>mex<\/strong>&quot; binding=&quot;<strong>mexHttpBinding<\/strong>&quot; contract=&quot;<strong>IMetadataExchange<\/strong>&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>mex<\/strong>&quot; binding=&quot;<strong>mexTcpBinding<\/strong>&quot; contract=&quot;<strong>IMetadataExchange<\/strong>&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160; &lt;\/service&gt;<\/font><\/p>\n<p><font color=\"#008000\"><strong>&#160;&#160;&#160;&#160;&#160; &lt;!\u2014******************** OnewayCall Service ************************* &#8211;&gt;        <br \/><\/strong><\/font><\/p>\n<p><font color=\"#0000ff\">&lt;service name=&quot;OperationLib.OneWayCallService&quot; behaviorConfiguration=&quot;<strong><font color=\"#008000\">OneWayCallServiceBehavior<\/font><\/strong>&quot;&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160; &lt;host&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;baseAddresses&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;add baseAddress=&quot;http:\/\/localhost:9013\/OneWayCallService&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;add baseAddress=&quot;net.tcp:\/\/localhost:9014\/OneWayCallService&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/baseAddresses&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/host&gt;<\/font><\/p>\n<p><font color=\"#0000ff\">&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>http:\/\/localhost:9013\/OneWayCallService<\/strong>&quot; binding=&quot;<strong>wsHttpBinding<\/strong>&quot; contract=&quot;OperationLib.IOneWayCallService&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>net.tcp:\/\/localhost:9014\/OneWayCallService<\/strong>&quot; binding=&quot;<strong>netTcpBinding<\/strong>&quot; contract=&quot;OperationLib.IOneWayCallService&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>mex<\/strong>&quot; binding=&quot;<strong>mexHttpBinding<\/strong>&quot; contract=&quot;<strong>IMetadataExchange<\/strong>&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>mex<\/strong>&quot; binding=&quot;<strong>mexTcpBinding<\/strong>&quot; contract=&quot;<strong>IMetadataExchange<\/strong>&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160; &lt;\/service&gt;       <br \/><\/font><\/p>\n<p>&#160;&#160;&#160;&#160; <font color=\"#9b00d3\"><strong>&lt;!\u2014********************* Duplex Service ***************************** &#8211;&gt;        <br \/><\/strong><\/font><\/p>\n<p><font color=\"#0000ff\">&lt;service name=&quot;OperationLib.DuplexService&quot; behaviorConfiguration=&quot;<strong><font color=\"#9b00d3\">DuplexServiceBehavior<\/font><\/strong>&quot; &gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;host&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;baseAddresses&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;add baseAddress=&quot;http:\/\/localhost:9015\/DuplexService&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;add baseAddress=&quot;net.tcp:\/\/localhost:9016\/DuplexService&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/baseAddresses&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/host&gt;<\/font><\/p>\n<p><font color=\"#0000ff\">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>http:\/\/localhost:9015\/DuplexService<\/strong>&quot; binding=&quot;<strong>wsDualHttpBinding<\/strong>&quot; contract=&quot;OperationLib.IDuplexService&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>net.tcp:\/\/localhost:9016\/DuplexService<\/strong>&quot; binding=&quot;<strong>netTcpBinding<\/strong>&quot; contract=&quot;OperationLib.IDuplexService&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>mex<\/strong>&quot; binding=&quot;<strong>mexHttpBinding<\/strong>&quot; contract=&quot;<strong>IMetadataExchange<\/strong>&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>mex<\/strong>&quot; binding=&quot;<strong>mexTcpBinding<\/strong>&quot; contract=&quot;<strong>IMetadataExchange<\/strong>&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160; &lt;\/service&gt;<\/font><\/p>\n<p><font color=\"#0000ff\">&lt;\/services&gt;<\/font><\/p>\n<p>&#160;&#160;&#160; &lt;!&#8211; ********************************** behaviors ********************************** &#8211;&gt;    <br \/>&#160;&#160;&#160; <\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&lt;behaviors&gt;      <br \/>&#160;&#160;&#160;&#160; &lt;serviceBehaviors&gt;<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160; &lt;!&#8211; Single Call Service Behavior &#8211;&gt;      <br \/>&#160;&#160;&#160;&#160;&#160;&#160; &lt;behavior name=&quot;<strong><font color=\"#ff0000\">RequestReplyServiceBehavior<\/font><\/strong>&quot;&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;serviceMetadata httpGetEnabled=&quot;true&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;serviceDebug includeExceptionDetailInFaults=&quot;true &quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/behavior&gt;<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160; &lt;!&#8211;Single Session Service Behavior &#8211;&gt;      <br \/>&#160;&#160;&#160;&#160;&#160;&#160; &lt;behavior name=&quot;<strong><font color=\"#008000\">OneWayCallServiceBehavior<\/font><\/strong>&quot;&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;serviceMetadata httpGetEnabled=&quot;true&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;serviceDebug includeExceptionDetailInFaults=&quot;true &quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/behavior&gt;<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160; &lt;!&#8211;Singleton Service Behavior &#8211;&gt;      <br \/>&#160;&#160;&#160;&#160;&#160;&#160; &lt;behavior name=&quot;<strong><font color=\"#9b00d3\">DuplexServiceBehavior<\/font><\/strong>&quot; &gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;serviceMetadata httpGetEnabled=&quot;true&quot;&#160; \/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;serviceDebug includeExceptionDetailInFaults=&quot;true &quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/behavior&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160; <br \/>&#160;&#160;&#160;&#160; &lt;\/serviceBehaviors&gt;       <br \/>&#160;&#160; &lt;\/behaviors&gt;       <br \/><\/font><\/p>\n<p>&#160;&#160;&#160; <br \/>&#160; &lt;\/system.serviceModel&gt;     <br \/>&lt;\/configuration&gt;<\/p>\n<p>Now let&#8217;s explain the configuration of each service.<\/p>\n<p>&#160;<\/p>\n<p>&lt;service name=&quot;OperationLib.RequestReplyService&quot; behaviorConfiguration=&quot;<strong><font color=\"#ff0000\">RequestReplyServiceBehavior<\/font><\/strong>&quot;&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;host&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;baseAddresses&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <strong>&lt;add baseAddress=&quot;http:\/\/localhost:9011\/RequestReplyService<\/strong>&quot;\/<strong>&gt;      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;add baseAddress=&quot;net.tcp:\/\/localhost:9012\/RequestReplyService&quot;\/&gt;       <br \/><\/strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/baseAddresses&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/host&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=<strong>&quot;http:\/\/localhost:9011\/RequestReplyService&quot;<\/strong> binding=&quot;<strong>wsHttpBinding<\/strong>&quot; contract=&quot;OperationLib.IRequestReplyService&quot;\/&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>net.tcp:\/\/localhost:9012\/RequestReplyService<\/strong>&quot; binding=&quot;<strong>netTcpBinding<\/strong>&quot; contract=&quot;OperationLib.IRequestReplyService&quot;\/&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>mex<\/strong>&quot; binding=&quot;<strong>mexHttpBinding<\/strong>&quot; contract=&quot;<strong>IMetadataExchange<\/strong>&quot;\/&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>mex<\/strong>&quot; binding=&quot;<strong>mexTcpBinding<\/strong>&quot; contract=&quot;<strong>IMetadataExchange<\/strong>&quot;\/&gt;     <br \/>&#160;&#160;&#160;&#160;&#160; &lt;\/service&gt;<\/p>\n<h5>Explanation:<\/h5>\n<p>&gt;&gt; to do <\/p>\n<p><font color=\"#008000\"><strong>&#160;&#160;&#160;&#160;&#160; &lt;!&#8211; ******************** Single Session Service ************************* &#8211;&gt;        <br \/><\/strong><\/font>&#160;&#160;&#160;&#160;&#160; &lt;service name=&quot;OperationLib.OneWayCallService&quot; behaviorConfiguration=&quot;<strong><font color=\"#008000\">OneWayCallServiceBehavior<\/font><\/strong>&quot;&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;host&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;baseAddresses&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <strong>&lt;add baseAddress=&quot;http:\/\/localhost:9013\/OneWayCallService&quot;\/&gt;      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;add baseAddress=&quot;net.tcp:\/\/localhost:9014\/OneWayCallService&quot;\/&gt;<\/strong>     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/baseAddresses&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/host&gt;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>http:\/\/localhost:9013\/OneWayCallService<\/strong>&quot; binding=&quot;<strong>wsHttpBinding<\/strong>&quot; contract=&quot;OperationLib.IOneWayCallService&quot;\/&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>net.tcp:\/\/localhost:9014\/OneWayCallService<\/strong>&quot; binding=&quot;<strong>netTcpBinding<\/strong>&quot; contract=&quot;OperationLib.IOneWayCallService&quot;\/&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>mex<\/strong>&quot; binding=&quot;<strong>mexHttpBinding<\/strong>&quot; contract=&quot;<strong>IMetadataExchange<\/strong>&quot;\/&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>mex<\/strong>&quot; binding=&quot;<strong>mexTcpBinding<\/strong>&quot; contract=&quot;<strong>IMetadataExchange<\/strong>&quot;\/&gt;     <br \/>&#160;&#160;&#160;&#160;&#160; &lt;\/service&gt;<\/p>\n<h5>Explanation:<\/h5>\n<p>&gt;&gt; to do <\/p>\n<p><font color=\"#9b00d3\"><strong>&lt;!&#8211; ********************* Singleton Service ***************************** &#8211;&gt;        <br \/><\/strong><\/font>&#160;&#160;&#160;&#160;&#160; &lt;service name=&quot;OperationLib.DuplexService&quot; behaviorConfiguration=&quot;<font color=\"#9b00d3\"><strong>DuplexServiceBehavior<\/strong><\/font>&quot;&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;host&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;baseAddresses&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <strong>&lt;add baseAddress=&quot;http:\/\/localhost:9015\/DuplexService&quot;\/&gt;      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;add baseAddress=&quot;net.tcp:\/\/localhost:9016\/DuplexService&quot;\/&gt;       <br \/><\/strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/baseAddresses&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/host&gt;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;http:\/\/localhost:9015\/DuplexService&quot; binding=&quot;<strong>wsDualHttpBinding<\/strong>&quot; contract=&quot;OperationLib.IDuplexService&quot;\/&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;net.tcp:\/\/localhost:9016\/DuplexService&quot; binding=&quot;<strong>netTcpBinding<\/strong>&quot; contract=&quot;OperationLib.IDuplexService&quot;\/&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>mex<\/strong>&quot; binding=&quot;<strong>mexHttpBinding<\/strong>&quot; contract=&quot;<strong>IMetadataExchange<\/strong>&quot;\/&gt;     <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint<\/strong> address=&quot;<strong>mex<\/strong>&quot; binding=&quot;<strong>mexTcpBinding<\/strong>&quot; contract=&quot;<strong>IMetadataExchange<\/strong>&quot;\/&gt;     <br \/>&#160;&#160;&#160;&#160;&#160; &lt;\/service&gt;<\/p>\n<h5>Explanation:<\/h5>\n<p>Now to see all these things in action let&#8217;s create a service.    <br \/>&#160;&#160;&#160;&#160; <\/p>\n<h4>Writing code to host the service.<\/h4>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">\/\/ Listing of Program.cs<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">using System;      <br \/>using System.Text;       <br \/>using System.ServiceModel;<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">namespace OperationLibHost      <br \/>{       <br \/>&#160;&#160;&#160; class Program       <br \/>&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; static void Main(string[] args)       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ServiceHost m_RequestReplyHost = null;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ServiceHost m_OneWayCallHost = null;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ServiceHost m_DuplexServiceHost = null;<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\nHosting RequestReplyService at &gt;&gt; &quot;);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;&#160;&#160;&#160; http:\/\/localhost:9011\/RequestReplyService&quot;);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;&#160;&#160;&#160; net.tcp:\/\/localhost:9012\/RequestReplyService&quot;);<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_RequestReplyHost = new ServiceHost(typeof(OperationLib.RequestReplyService));       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_RequestReplyHost.Open();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; catch (Exception eX)       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Failed while starting RequestReplyService [&quot; + eX.Message + &quot;]&quot;);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_RequestReplyHost = null;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (m_RequestReplyHost != null) Console.WriteLine(&quot;RequestReplyService hosted successfully . . .&quot;);<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\nHosting OneWayCallService at &gt;&gt; &quot;);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;&#160;&#160;&#160; <\/font><a href=\"http:\/\/localhost:9013\/OneWayCallService&quot;);\"><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">http:\/\/localhost:9013\/OneWayCallService&quot;);<\/font><\/a><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;&#160;&#160;&#160; net.tcp:\/\/localhost:9014\/OneWayCallService&quot;);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_OneWayCallHost = new ServiceHost(typeof(OperationLib.OneWayCallService));       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_OneWayCallHost.Open();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; catch (Exception eX)       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Failed while starting OneWayCallService [&quot; + eX.Message + &quot;]&quot;);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_OneWayCallHost = null;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (m_OneWayCallHost != null) Console.WriteLine(&quot;OneWayCallService hosted successfully . . .&quot;);<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\nHosting DuplexService&#160; at &gt;&gt; &quot;);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;&#160;&#160;&#160; <\/font><a href=\"http:\/\/localhost:9015\/DuplexService&quot;);\"><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">http:\/\/localhost:9015\/DuplexService&quot;);<\/font><\/a><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;&#160;&#160;&#160; net.tcp:\/\/localhost:9016\/DuplexService&quot;);<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_DuplexServiceHost = new ServiceHost(typeof(OperationLib.DuplexService ));       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_DuplexServiceHost.Open();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; catch (Exception eX)       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Failed while starting Service [&quot; + eX.Message + &quot;]&quot;);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_DuplexServiceHost = null;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (m_DuplexServiceHost != null) Console.WriteLine(&quot;DuplexService hosted successfully . . .&quot;);<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\n\\nPress any key to close . . .&quot;);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.ReadKey();<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_RequestReplyHost.Close();      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_OneWayCallHost.Close();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_DuplexServiceHost.Close();<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_RequestReplyHost = null;      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_OneWayCallHost = null;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_DuplexServiceHost = null;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }       <br \/>&#160;&#160;&#160; }       <br \/>}<\/font><\/p>\n<h5>Explanation:<\/h5>\n<p>Now to see all these things in action let&#8217;s create a service.    <\/p>\n<p>Build and Execute the host application.<\/p>\n<p>Open a command prompt and execute the host. here is the output.<\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;\" border=\"0\" alt=\"image\" src=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image_thumb.png\" width=\"588\" height=\"172\" \/><\/a><\/p>\n<p>Now when the service is hosted and running, let&#8217;s now create a client, which is actually going to use this service.<\/p>\n<h3>Creating Client<\/h3>\n<h4>Creating the base project <\/h4>\n<p>Take a console based application. <\/p>\n<h4>Generating proxies <\/h4>\n<p>while the host application is running, right click on the client application project, click on <\/p>\n<h5>Generate Proxy for RequestReplyService.<\/h5>\n<p><strong><font size=\"2\">References \u2013&gt; Add Service Reference <\/font><\/strong><\/p>\n<p>in the address bar type the address of the <strong>mex<\/strong> endpoint address of <strong>RequestReplyService<\/strong> as shown below.<\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image1.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;\" border=\"0\" alt=\"image\" src=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image_thumb1.png\" width=\"574\" height=\"404\" \/><\/a><\/p>\n<h5>Generate Proxy for OneWayCallService.<\/h5>\n<p><strong><font size=\"2\">References \u2013&gt; Add Service Reference <\/font><\/strong><\/p>\n<p>in the address bar type the address of the <strong>mex<\/strong> endpoint address of <strong>OneWayCallService<\/strong> as shown below.<\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image2.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;\" border=\"0\" alt=\"image\" src=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image_thumb2.png\" width=\"605\" height=\"404\" \/><\/a><\/p>\n<h5>Generate Proxy for DuplexService.<\/h5>\n<p><strong><font size=\"2\">References \u2013&gt; Add Service Reference <\/font><\/strong><\/p>\n<p>in the address bar type the address of the <strong>mex<\/strong> endpoint address of <strong>DuplexService <\/strong>as shown below.<\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image3.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;\" border=\"0\" alt=\"image\" src=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image_thumb3.png\" width=\"586\" height=\"392\" \/><\/a><\/p>\n<h4>Adding Callback implementation to the client. <\/h4>\n<p>Add a new Class to the Client Project, name it <strong>DuplexServiceCallbackSink<\/strong>, below is the listing.<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">using System;      <br \/>using System.Collections.Generic;       <br \/>using System.Linq;       <br \/>using System.Text;<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">namespace OperationClient      <br \/>{       <br \/>&#160;&#160;&#160; class DuplexServiceCallbackSink : DuplexServiceReference.IDuplexServiceCallback       <br \/>&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public void OnValueAdded(double dblNum1, double dblNum2, double dblResult)       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\n\\n&gt;&gt; Duplex Service &lt;&lt;CallBack&gt;&gt; called in Client &gt;&gt; Value 1 : {0:F2} Value 2 : {1:F2} Result : {2:F2}&quot;, dblNum1, dblNum2, dblResult);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }       <br \/>&#160;&#160;&#160; }       <br \/>}<\/font><\/p>\n<h4>Calling Services<\/h4>\n<p><font color=\"#0000ff\" face=\"Courier New\">using System;      <br \/>using System.Collections.Generic;       <br \/>using System.Linq;       <br \/>using System.Text;       <br \/>using System.ServiceModel;<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">namespace OperationClient      <br \/>{       <br \/>&#160;&#160;&#160; class Program       <br \/>&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; static void Main(string[] args)       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; double dblVal1 = 100; double dblVal2 = 200;<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; RequestReplyServiceReference.RequestReplyServiceClient obj1 = new RequestReplyServiceReference.RequestReplyServiceClient(&quot;WSHttpBinding_IRequestReplyService&quot;);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; RequestReplyServiceReference.RequestReplyServiceClient obj2 = new RequestReplyServiceReference.RequestReplyServiceClient(&quot;NetTcpBinding_IRequestReplyService&quot;);<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Calling Request Reply Service&quot;);<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; double dblResult1 = obj1.AddValue(dblVal1, dblVal2);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Using HTTP Binding &gt;&gt; Value 1: {0:F2} Value 2: {1:F2}&#160; Returns : {2:F2}&quot;, dblVal1, dblVal2, dblResult1);<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dblVal1 = 100; dblVal2 = 200;      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; double dblResult2 = obj2.AddValue(dblVal1, dblVal2);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Using TCP Binding &gt;&gt; Value 1: {0:F2} Value 2: {1:F2}&#160; Return : {2:F2}&quot;, dblVal1, dblVal2, dblResult2);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; catch (Exception eX)       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Error while calling Request Reply Service [ &quot; + eX.Message + &quot;]&quot;);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; OneWayCallServiceReference.OneWayCallServiceClient obj3 = new OneWayCallServiceReference.OneWayCallServiceClient(&quot;WSHttpBinding_IOneWayCallService&quot;);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; OneWayCallServiceReference.OneWayCallServiceClient obj4 = new OneWayCallServiceReference.OneWayCallServiceClient(&quot;NetTcpBinding_IOneWayCallService&quot;);<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Calling OneWayCall Service&quot;);<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; obj3.AddValue(dblVal1);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; obj3.AddValue(dblVal2);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; double dblResult3 = obj3.GetResult();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Using HTTP Binding &gt;&gt; Value 1: {0:F2} Value 2: {1:F2}&quot;, dblVal1, dblVal2 );       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Result : {0:F2}&quot;, dblResult3);<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; obj4.AddValue(dblVal1);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; obj4.AddValue(dblVal2);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; double dblResult4 = obj4.GetResult();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Using TCP Binding &gt;&gt; Value 1: {0:F2} Value 2: {1:F2}&quot;, dblVal1, dblVal2);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Result : {0:F2}&quot;, dblResult4);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; catch (Exception eX)       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Error while calling One way Service [ &quot; + eX.Message + &quot;]&quot;);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DuplexServiceCallbackSink callback = new DuplexServiceCallbackSink();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; InstanceContext insCntxt = new InstanceContext(callback);<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DuplexServiceReference.DuplexServiceClient obj5 = new DuplexServiceReference.DuplexServiceClient(insCntxt, &quot;WSDualHttpBinding_IDuplexService&quot;);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DuplexServiceReference.DuplexServiceClient obj6 = new DuplexServiceReference.DuplexServiceClient(insCntxt, &quot;NetTcpBinding_IDuplexService&quot;);<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; obj5.AddValue(dblVal1, dblVal2);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; obj6.AddValue(dblVal1, dblVal2);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; catch (Exception eX)       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Error while calling Duplex Service [ &quot; + eX.Message + &quot;]&quot;);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\n\\nPress any key &#8230;&quot;);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.ReadKey();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }       <br \/>&#160;&#160;&#160; }       <br \/>}<\/font><\/p>\n<p>and here is the output.<\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image4.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;\" border=\"0\" alt=\"image\" src=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image_thumb4.png\" width=\"591\" height=\"177\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>WCF supports 3 ways for a client to call a service. Request Reply : default way of invocation, the client would issue a call, block&#160;while the call was in progress, and would continue executing once the method returned. If service doesn&#8217;t respond to the service within receiveTimeout, client will receive TimeOutException. One way calls: fire&hellip; <a class=\"more-link\" href=\"https:\/\/praveenkatiyar.in\/blog\/index.php\/2013\/10\/04\/understanding-operations-in-wcf\/\">Continue reading <span class=\"screen-reader-text\">Understanding Operations in WCF<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[17,33],"class_list":["post-297","post","type-post","status-publish","format-standard","hentry","category-soa","tag-net","tag-wcf","entry"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/posts\/297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=297"}],"version-history":[{"count":0,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/posts\/297\/revisions"}],"wp:attachment":[{"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}