{"id":181,"date":"2013-09-12T11:27:29","date_gmt":"2013-09-12T11:27:29","guid":{"rendered":"https:\/\/praveenkatiyar.wordpress.com\/?p=181"},"modified":"2013-09-12T11:27:29","modified_gmt":"2013-09-12T11:27:29","slug":"creating-and-consuming-a-wcf-service-without-configuration-files","status":"publish","type":"post","link":"https:\/\/praveenkatiyar.in\/blog\/index.php\/2013\/09\/12\/creating-and-consuming-a-wcf-service-without-configuration-files\/","title":{"rendered":"Creating and Consuming a WCF Service without configuration files."},"content":{"rendered":"<h3><span style=\"font-weight:bold;\">Introduction<\/span><\/h3>\n<p>This article explains how to create a simple WCF Service Host it on a specified port according to specified binding. all this you can do on the fly.<\/p>\n<h3><span style=\"font-weight:bold;\">Background<\/span><\/h3>\n<p>Normally when we develop WCF Services, we are in habit of using Configuration files. (web.config\/app.config depending on the environment). it is indeed very good idea to use configuration files. all this seems very automatic. And using configuration files is default way of doing things.<\/p>\n<h3><span style=\"font-weight:bold;\">How this project is organized <\/span><\/h3>\n<p>In this article i have used 3 projects.<\/p>\n<ul>\n<li><strong>WCF Service (WCFMathLib.dll):<\/strong>&#160; Actual Service logic, which defines a Service Contract Interface, OperationContract, and implements them, and exposes few functions to the world to use them. <\/li>\n<li><strong>Host Application <\/strong>(<strong>ConWCFMathHost.exe<\/strong>): Defines the logic to host the said service, according to the parameters supplied at the command line. <\/li>\n<li><strong>Client Application (ConWCFMathClient.exe):<\/strong> Client Application which will use this service. <\/li>\n<\/ul>\n<h3><span style=\"font-weight:bold;\">First Part : WCF Service (WCFMathLib.dll):<\/span><\/h3>\n<p>The actual Service which implements the business logic. it defines an <strong>ServiceContract<\/strong> and few Operations available through Service. as shown below.&#160; let;s call it <strong>IMathInterface.cs<\/strong><\/p>\n<p>to create this project you can simply take a <strong>Class Library Project<\/strong>, from while choosing from project wizard option. let&#8217;s Name it &quot;<strong>WCFMathLib<\/strong>&quot;, it already contains a File <strong>Class1.cs<\/strong>, rename that file as <strong>MathService.cs<\/strong>, add one more file (<strong>IMathService.cs<\/strong>) to define the interface, although you can define interface this file also. below is the listing of both files.<\/p>\n<p>&#160;<\/p>\n<h4>Defining a Service Contract<\/h4>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>\/\/ Listing of IMathInterface.cs        <br \/>[ServiceContract]        <br \/>public interface IMathService        <br \/>{        <br \/>&#160;&#160;&#160; [OperationContract]        <br \/>&#160;&#160;&#160; double AddNumber(double dblX, double dblY);        <br \/>&#160;&#160;&#160; <br \/>&#160;&#160;&#160; [OperationContract]        <br \/>&#160;&#160;&#160; double SubtractNumber(double dblX, double dblY);        <br \/>&#160;&#160;&#160; <br \/>&#160;&#160;&#160; [OperationContract]        <br \/>&#160;&#160;&#160; double MultiplyNumber(double dblX, double dblY);        <br \/>&#160;&#160;&#160; <br \/>&#160;&#160;&#160; [OperationContract]        <br \/>&#160;&#160;&#160; double DivideNumber(double dblX, double dblY);        <br \/>} <\/strong><\/font><\/p>\n<h4>Implementation&#160; of Service Contract<\/h4>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>\/\/&#160;&#160;&#160; Listing MathInterface.cs        <br \/>public class MathService : IMathService        <br \/>{        <br \/>&#160;&#160;&#160; public double AddNumber(double dblX, double dblY)        <br \/>&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; return (dblX + dblY);        <br \/>&#160;&#160;&#160; } <\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160; public double SubtractNumber(double dblX, double dblY)       <br \/>&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; return (dblX &#8211; dblY);        <br \/>&#160;&#160;&#160; } <\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160; public double MultiplyNumber(double dblX, double dblY)       <br \/>&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; return (dblX * dblY);        <br \/>&#160;&#160;&#160; } <\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160; public double DivideNumber(double dblX, double dblY)       <br \/>&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; return ((dblY == 0 ) ? 0 : dblX \/ dblY);        <br \/>&#160;&#160;&#160; }        <br \/>}<\/strong><\/font><\/p>\n<h5>ServiceContract attribute<\/h5>\n<p>Service Contract. Describes which related operations can be tied together as a single functional unit that the client can perform on the service.<\/p>\n<h5>OperationContract attribute<\/h5>\n<p>An Operation contract specifyies that the said operation is exposed by the service, service defines the parameters and return type of an operation.<\/p>\n<p>as one can see, there is nothing special here, just an Service Contract definition and its implementation.<\/p>\n<h3><span style=\"font-weight:bold;\">Second Part : WCF Service (ConWCFMathHost.exe):<\/span><\/h3>\n<p>Host application has been developed as console based application, which host our Service (WCFMathLib.MathService), according to the supplied parameters, parameters are supplied in the following form.&#160; it accepts two parameters.<\/p>\n<p><strong>ConWCFMathHost.exe TCP\/HTTP portAdr &lt;return&gt;<\/strong><\/p>\n<p><strong>Parameter 1 <\/strong>: Binding accepted values are HTTP and TCP<\/p>\n<p><strong>Parameter 2 : <\/strong>Port Number, and integer value specifyin the port value.<\/p>\n<h4>Hosting Service using HTTP Bidnding<\/h4>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>private static void StartHTTPService( int nPort)       <br \/>{        <br \/>&#160;&#160;&#160; string strAdr = &quot;<\/strong><\/font><a href=\"http:\/\/localhost:&quot;\"><font color=\"#0000ff\" face=\"Courier New\">http:\/\/localhost:&quot;<\/font><\/a><font color=\"#0000ff\" face=\"Courier New\"><strong> + nPort.ToString() + &quot;\/MathService&quot;;       <br \/>&#160;&#160;&#160; try        <br \/>&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Uri adrbase = new Uri(strAdr);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost = new ServiceHost(typeof(MathService), adrbase);<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ServiceMetadataBehavior mBehave = new ServiceMetadataBehavior();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost.Description.Behaviors.Add(mBehave);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), &quot;mex&quot;);<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160; BasicHttpBinding httpb = new BasicHttpBinding();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost.AddServiceEndpoint(typeof(IMathService), httpb, strAdr);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost.Open();        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\n\\nService is Running as &gt;&gt; &quot; + strAdr );        <br \/>&#160;&#160;&#160; }        <br \/>&#160;&#160;&#160; catch (Exception eX)        <br \/>&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost = null;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Service can not be started as &gt;&gt; [&quot; + strAdr + &quot;] \\n\\nError Message [&quot; + eX.Message + &quot;]&quot;);        <br \/>&#160;&#160;&#160; }        <br \/>}        <br \/><\/strong><\/font><\/p>\n<h4>Hosting Service using TCP Bidnding<\/h4>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>private static void StartTCPService(int nPort)       <br \/>{        <br \/>&#160;&#160;&#160; string strAdr = &quot;net.tcp:\/\/localhost:&quot; + nPort.ToString() + &quot;\/MathService&quot;;        <br \/>&#160;&#160;&#160; try        <br \/>&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Uri adrbase = new Uri(strAdr);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost = new ServiceHost(typeof(MathService), adrbase);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; NetTcpBinding tcpb = new NetTcpBinding(); <\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ServiceMetadataBehavior mBehave = new ServiceMetadataBehavior();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost.Description.Behaviors.Add(mBehave);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost.AddServiceEndpoint(typeof(IMetadataExchange),&#160;&#160; MetadataExchangeBindings.CreateMexTcpBinding(), &quot;mex&quot;);<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost.AddServiceEndpoint(typeof(IMathService), tcpb, strAdr);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost.Open();        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\n\\nService is Running as &gt;&gt; &quot; + strAdr );        <br \/>&#160;&#160;&#160; }        <br \/>&#160;&#160;&#160; catch (Exception eX)        <br \/>&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost = null;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Service can not be started as &gt;&gt; [&quot; + strAdr + &quot;] \\n\\nError Message [&quot; + eX.Message + &quot;]&quot;);        <br \/>&#160;&#160;&#160; }        <br \/>}<\/strong><\/font><\/p>\n<h4>Code Description<\/h4>\n<h5>Create Desired binding (TCP\/HTTP)<\/h5>\n<p><strong>ServiceMetadataBehavior<\/strong>, Controls the publication of service metadata and associated information. although we can omit the part shown in <strong>bold<\/strong>, as far as this project is concerned, as we are going to create everything by hand, but it is a good Idea, to always add a <strong>IMetadataExchange <\/strong>endpoint to the service. as it&#160; exposes methods used to return the metadata about&#160; the service. it is usefull <strong>when we are generating the proxy class and config files<\/strong> from the service using <strong>SVCUtil.exe<\/strong> utility.<\/p>\n<h4>Host Application Complete Code<\/h4>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>\/\/ Program.cs<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>using System;       <br \/>using System.Collections.Generic;        <br \/>using System.Linq;        <br \/>using System.Text;        <br \/>using System.ServiceModel;        <br \/>using System.ServiceModel.Description;        <br \/>using WCFMathLib;<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>namespace ConWCFMathHost       <br \/>{        <br \/>&#160;&#160;&#160; class Program        <br \/>&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; static ServiceHost m_svcHost = null;        <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; if (args.Count() != 2)        <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;Insufficient arguments supplied&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Service Host must be started as &lt;Executable Name&gt; &lt;TCP\/HTTP&gt; &lt;Port#&gt;&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Argument 1 &gt;&gt; Specifying the Binding, which binding will be used to Host (Supported values are either HTTP or TCP) without quotes&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Argument 2 &gt;&gt; Port Number a numeric value, the port you want to use&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\nExamples&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;&lt;Executable Name&gt; TCP 9001&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;&lt;Executable Name&gt; TCP 8001&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;&lt;Executable Name&gt; HTTP 8001&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;&lt;Executable Name&gt; HTTP 9001&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; string strBinding = args[0].ToUpper();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bool bSuccess = ((strBinding == &quot;TCP&quot;) || (strBinding == &quot;HTTP&quot;));        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (bSuccess == false)        <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;\\nBinding argument is invalid, should be either TCP or HTTP)&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return;        <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; int nPort = 0;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bSuccess = int.TryParse(args[1], out nPort);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (bSuccess == false)        <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;\\nPort number must be a numeric value&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bool bindingTCP = (strBinding == &quot;TCP&quot;);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (bindingTCP) StartTCPService(nPort);&#160; else StartHTTPService(nPort);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (m_svcHost != 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;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\nPress any key to close the Service&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.ReadKey();        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; StopService();        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160; private static void StartTCPService(int nPort)       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; string strAdr = &quot;net.tcp:\/\/localhost:&quot; + nPort.ToString() + &quot;\/MathService&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; Uri adrbase = new Uri(strAdr);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost = new ServiceHost(typeof(MathService), adrbase);        <br \/>&#160;&#160;&#160;&#160;&#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; ServiceMetadataBehavior mBehave = new ServiceMetadataBehavior();        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost.Description.Behaviors.Add(mBehave);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBinding(), &quot;mex&quot;);<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; NetTcpBinding tcpb = new NetTcpBinding();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost.AddServiceEndpoint(typeof(IMathService), tcpb, strAdr);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost.Open();        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\n\\nService is Running as &gt;&gt; &quot; + strAdr );        <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; m_svcHost = null;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Service can not be started as &gt;&gt; [&quot; + strAdr + &quot;] \\n\\nError Message [&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; }<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160; private static void StartHTTPService( int nPort)       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; string strAdr = &quot;<\/strong><\/font><a href=\"http:\/\/localhost:&quot;\"><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">http:\/\/localhost:&quot;<\/font><\/a><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong> + nPort.ToString() + &quot;\/MathService&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; Uri adrbase = new Uri(strAdr);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost = new ServiceHost(typeof(MathService), adrbase);        <br \/>&#160;&#160;&#160;&#160;&#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; ServiceMetadataBehavior mBehave = new ServiceMetadataBehavior();        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost.Description.Behaviors.Add(mBehave);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), &quot;mex&quot;);<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; BasicHttpBinding httpb = new BasicHttpBinding();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost.AddServiceEndpoint(typeof(IMathService), httpb, strAdr);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost.Open();        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\n\\nService is Running as &gt;&gt; &quot; + strAdr );        <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; m_svcHost = null;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Service can not be started as &gt;&gt; [&quot; + strAdr + &quot;] \\n\\nError Message [&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; }<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160; private static void StopService()       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (m_svcHost != 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;&#160;&#160;&#160;&#160; m_svcHost.Close();        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; m_svcHost = null;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }        <br \/>&#160;&#160;&#160; }        <br \/>}<\/strong><\/font><\/p>\n<h3><span style=\"font-weight:bold;\">Third Part : Client (ConWCFMathClient.exe):<\/span><\/h3>\n<p>Client application has been also developed as console based application, parameters through command line in the following form.&#160; you need to supply <strong>6 parameters<\/strong> at the command line.<\/p>\n<p><strong>ConWCFMathClient &lt;Host Machine&gt; &lt;TCP\/HTTP&gt; &lt;Port#&gt; &lt;ADD\/SUB\/MUL\/DIV&gt; Num1 Num2<\/strong><\/p>\n<p><strong>Parameter 1 <\/strong>: name\/IP address of the machine, where service has been hosted.<\/p>\n<p><strong>Parameter 2 <\/strong>: Binding of the hosted service, accepted values are <strong>HTTP and TCP<\/strong><\/p>\n<p><strong>Parameter 3 : <\/strong>Port Number, and integer value specifyin the port value.<\/p>\n<p><strong>Parameter 4 : <\/strong>Operation Code (accepted values are <strong>ADD, SUB, MUL, DIV<\/strong>)<\/p>\n<p><strong>Parameter 5 : <\/strong>Operand 1, operand value 1 for the operation.<\/p>\n<p><strong>Parameter 6 : <\/strong>Operand 2, operand value 2 for the operation.<\/p>\n<h4>Importing the Interface&#160; definition<\/h4>\n<p>You can define the interface or just import the IMathService.cs file from the Service. this simply defines the interface, so that there is no error while compiling the client project<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>\/\/ Listing of IMathInterface.cs        <br \/>namespace ConWCFMathClient        <br \/>{        <br \/>&#160;&#160;&#160; [ServiceContract]        <br \/>&#160;&#160;&#160; public interface IMathService        <br \/>&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; [OperationContract]        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; double AddNumber(double dblX, double dblY);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; [OperationContract]        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; double SubtractNumber(double dblX, double dblY);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; [OperationContract]        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; double MultiplyNumber(double dblX, double dblY);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; [OperationContract]        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; double DivideNumber(double dblX, double dblY);        <br \/>&#160;&#160;&#160; }         <br \/>}<\/strong><\/font><\/p>\n<p><span style=\"font-family:&#039;color:#0000ff;\"><strong>&#160;&#160; <\/strong><\/span><\/p>\n<h4>Calling Methods of the Service<\/h4>\n<p>a function has been created to call&#160; methods of the Service, passing all the parameter to the method, after validating them. here is the mehod.<\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>private static void Evaluate(string strServer, string strBinding, int nPort, string strOper, double dblVal1, double dblVal2)       <br \/>{        <br \/>&#160;&#160;&#160; ChannelFactory&lt;IMathService&gt; channelFactory = null;        <br \/>&#160;&#160;&#160; EndpointAddress ep = null; <\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160; string strEPAdr = &quot;<\/strong><\/font><a href=\"http:\/\/&quot;\"><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">http:\/\/&quot;<\/font><\/a><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong> + strServer + &quot;:&quot; + nPort.ToString() + &quot;\/MathService&quot;;       <br \/>&#160;&#160;&#160; try        <br \/>&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; switch (strBinding)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; case &quot;TCP&quot;:        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; NetTcpBinding tcpb = new NetTcpBinding();        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; channelFactory = new ChannelFactory&lt;IMathService&gt;(tcpb);<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \/\/ End Point Address       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; strEPAdr = &quot;net.tcp:\/\/&quot; + strServer + &quot;:&quot; + nPort.ToString() + &quot;\/MathService&quot;;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; break; <\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; case &quot;HTTP&quot;:       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; BasicHttpBinding httpb = new BasicHttpBinding();        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; channelFactory = new ChannelFactory&lt;IMathService&gt;(httpb);        <br \/>&#160;&#160;&#160;&#160;&#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; \/\/ End Point Address        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; strEPAdr = &quot;<\/strong><\/font><a href=\"http:\/\/&quot;\"><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">http:\/\/&quot;<\/font><\/a><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong> + strServer + &quot;:&quot; + nPort.ToString() + &quot;\/MathService&quot;;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; break;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160; \/\/ Create End Point       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ep = new EndpointAddress(strEPAdr);<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160; \/\/ Create Channel       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; IMathService mathSvcObj = channelFactory.CreateChannel(ep);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; double dblResult = 0; <\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \/\/ Call Methods       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; switch (strOper)        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; case &quot;ADD&quot;: dblResult = mathSvcObj.AddNumber(dblVal1, dblVal2); break;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; case &quot;SUB&quot;: dblResult = mathSvcObj.SubtractNumber(dblVal1, dblVal2); break;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; case &quot;MUL&quot;: dblResult = mathSvcObj.MultiplyNumber(dblVal1, dblVal2); break;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; case &quot;DIV&quot;: dblResult = mathSvcObj.DivideNumber(dblVal1, dblVal2); break;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160; \/\/&#160; Display Results.       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Operation {0} &quot;, strOper );        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Operand 1 {0} &quot;, dblVal1.ToString ( &quot;F2&quot;));        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Operand 2 {0} &quot;, dblVal2.ToString(&quot;F2&quot;));        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Result {0} &quot;, dblResult.ToString(&quot;F2&quot;));        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; channelFactory.Close();        <br \/>&#160;&#160;&#160; }        <br \/>&#160;&#160;&#160; catch (Exception eX)        <br \/>&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; \/\/ Something unexpected happended ..        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Error while performing operation [&quot; + eX.Message + &quot;] \\n\\n Inner Exception [&quot; + eX.InnerException + &quot;]&quot;);        <br \/>&#160;&#160;&#160; }        <br \/>}<\/strong><\/font><\/p>\n<h4>Code Description<\/h4>\n<p>Before you can call any method, you need to do two things.<\/p>\n<p>Create a <strong>channel factory object<\/strong>, using the specified <strong>binding<\/strong> using .<\/p>\n<h5>for HTTP Bindng<\/h5>\n<p><span style=\"font-family:&#039;color:#0000ff;\"><strong>BasicHttpBinding httpb = new BasicHttpBinding();       <br \/>channelFactory = new ChannelFactory&lt;IMathService&gt;(httpb);<\/strong><\/span><\/p>\n<h5>for TCP Bindng<\/h5>\n<p><span style=\"color:#0000ff;\"><strong><span style=\"font-family:&#039;\">NetTcpBinding tcpb = new NetTcpBinding();         <br \/>channelFactory = new ChannelFactory&lt;IMathService&gt;(tcpb);<\/span>&#160; <\/strong><\/span><\/p>\n<p><span style=\"font-size:.83em;\">EndPoint address for HTTP binding<\/span><\/p>\n<p><span style=\"font-family:&#039;color:#0000ff;\"><strong>strEPAdr = &quot;<\/strong><\/span><a href=\"http:\/\/&quot;\"><span style=\"font-family:&#039;color:#0000ff;\">http:\/\/&quot;<\/span><\/a><span style=\"font-family:&#039;color:#0000ff;\"><strong> + strServer + &quot;:&quot; + nPort.ToString() + &quot;\/MathService&quot;;<\/strong><\/span><\/p>\n<h5>EndPoint address&#160;&#160; TCP binding<\/h5>\n<p><span style=\"font-family:&#039;color:#0000ff;\"><strong>strEPadr = strEPAdr = <span class=\"str\">&quot;net.tcp:\/\/&quot;<\/span> + strServer + <span class=\"str\">&quot;:&quot;<\/span> + nPort.ToString() + <span class=\"str\">&quot;\/MathService&quot;<\/span>;<\/strong><\/span><\/p>\n<h5>Create a chaneel through specified end point aadress<\/h5>\n<p><span style=\"color:#0000ff;\"><strong><span style=\"font-family:&#039;\"><span class=\"rem\">\/\/ Create End Point <\/span>ep = <span class=\"kwrd\">new<\/span> EndpointAddress(strEPAdr); \/\/ Create ChannelIMathService mathSvcObj = channelFactory.CreateChannel(ep);<\/span><\/strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <\/span><\/p>\n<h5>Invoke methods through channel and display output.<\/h5>\n<p><span style=\"font-family:&#039;color:#0000ff;\"><strong>double dblResult = 0; <\/strong><\/span><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\"><strong>\/\/ Call Methods       <br \/>switch (strOper)        <br \/>{        <br \/>&#160;&#160;&#160; case &quot;ADD&quot;: dblResult = mathSvcObj.AddNumber(dblVal1, dblVal2); break;        <br \/>&#160;&#160;&#160; case &quot;SUB&quot;: dblResult = mathSvcObj.SubtractNumber(dblVal1, dblVal2); break;        <br \/>&#160;&#160;&#160; case &quot;MUL&quot;: dblResult = mathSvcObj.MultiplyNumber(dblVal1, dblVal2); break;        <br \/>&#160;&#160;&#160; case &quot;DIV&quot;: dblResult = mathSvcObj.DivideNumber(dblVal1, dblVal2); break;        <br \/>}<\/strong><\/font><\/p>\n<p> <span style=\"font-family:&#039;color:#0000ff;\">   <\/p>\n<p><strong>\/\/&#160; Display Results.       <br \/>Console.WriteLine(&quot;Operation {0} &quot;, strOper );        <br \/>Console.WriteLine(&quot;Operand 1 {0} &quot;, dblVal1.ToString ( &quot;F2&quot;));        <br \/>Console.WriteLine(&quot;Operand 2 {0} &quot;, dblVal2.ToString(&quot;F2&quot;));        <br \/>Console.WriteLine(&quot;Result {0} &quot;, dblResult.ToString(&quot;F2&quot;)); <\/strong><\/p>\n<p> <\/span>  <\/p>\n<p><span style=\"font-family:&#039;color:#0000ff;\"><strong>\/\/ Close channel       <br \/>channelFactory.Close();<\/strong><\/span><span style=\"color:#000080;\">&#160;<\/span><\/p>\n<h4>Point of Interest<\/h4>\n<ul>\n<li>No configuration file, <\/li>\n<li>there is no proxy generation using SvcUtil <\/li>\n<\/ul>\n<h4>Client Application Complete Code<\/h4>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>\/\/ Program.cs       <br \/>using System;        <br \/>using System.Collections.Generic;        <br \/>using System.Linq;        <br \/>using System.Text;        <br \/>using System.ServiceModel;        <br \/>using System.ServiceModel.Description;<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>namespace ConWCFMathClient       <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; if (args.Count() !=6 )        <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;Insufficient arguments supplied&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Service Host must be started as ConWCFMathClient &lt;Host Machine&gt; &lt;TCP\/HTTP&gt; &lt;Port#&gt; &lt;ADD\/SUB\/MUL\/DIV&gt; Num1 Num2&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Argument 1 &gt;&gt; IP address or the Machine name, where Service is hosted\/running (localhost if running onm the same machine)&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Argument 2 &gt;&gt; Specifying the Binding type, which binding is used to Host the service. (Supported values are either HTTP or TCP),&#160; without quotes&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Argument 3 &gt;&gt; Port Number a numeric value&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Argument 4 &gt;&gt; Operation permissible values are ADD\/SUB\/MUL\/DIV without quotes&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Argument 5 &gt;&gt; Operand 1 for the operation &quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Argument 6 &gt;&gt; Operand 2 for the operation &quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\nExamples&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;&lt;Executable Name&gt; 192.168.1.1 TCP 9001 ADD 1000 2000&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;&lt;Executable Name&gt; 192.168.1.1 TCP 8001 SUB 500 1000&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;&lt;Executable Name&gt; 192.168.1.1 HTTP 8001 MUL 500 1000&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;&lt;Executable Name&gt; 192.168.1.1 HTTP 9001 DIV 3000 1000&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;&lt;Executable Name&gt; localhost TCP 9001 ADD 4000.0&#160; 500.0&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;&lt;Executable Name&gt; localhost TCP 8001 SUB 600.0 700.0&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;&lt;Executable Name&gt; localhost HTTP 8001 MUL 1200.0 300.0&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;&lt;Executable Name&gt; localhost HTTP 9001 DIV 2000.0 90.0&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return;        <br \/>&#160;&#160;&#160;&#160;&#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;&#160;&#160;&#160;&#160; string strAdr = args[0];       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; string strBinding = args[1].ToUpper();        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bool bSuccess = ((strBinding == &quot;TCP&quot;) || (strBinding == &quot;HTTP&quot;));        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (bSuccess == false)        <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;\\nBinding argument is invalid, should be either TCP or HTTP)&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return;        <br \/>&#160;&#160;&#160;&#160;&#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;&#160;&#160;&#160;&#160; int nPort = 0;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bSuccess = int.TryParse(args[2], out nPort);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (bSuccess == false)        <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;\\nPort number must be a numeric value&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return;        <br \/>&#160;&#160;&#160;&#160;&#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;&#160;&#160;&#160;&#160; string strOper = args[3].ToUpper();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bSuccess = ((strOper == &quot;ADD&quot;) || (strOper == &quot;SUB&quot;) || (strOper == &quot;MUL&quot;) || (strOper == &quot;DIV&quot;));        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (bSuccess == false)        <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;\\nOperation argument is invalid, should be ADD\/SUB\/MUL\/DIV)&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return;        <br \/>&#160;&#160;&#160;&#160;&#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;&#160;&#160;&#160;&#160; \/\/&#160; Determine operand 1       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; double dblNum1 = 0;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bSuccess = double.TryParse(args[4], out dblNum1);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (bSuccess == false)        <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;\\nOperand 1 must be a numeric value&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return;        <br \/>&#160;&#160;&#160;&#160;&#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;&#160;&#160;&#160;&#160; \/\/&#160; Determine operand 2       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; double dblNum2 = 0;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bSuccess = double.TryParse(args[5], out dblNum2);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (bSuccess == false)        <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;\\nnOperand 2 must be a numeric value&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return;        <br \/>&#160;&#160;&#160;&#160;&#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;&#160;&#160;&#160;&#160; Evaluate(strAdr, strBinding, nPort, strOper, dblNum1, dblNum2);       <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; private static void Evaluate(string strServer, string strBinding, int nPort, string strOper, double dblVal1, double dblVal2)       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ChannelFactory&lt;IMathService&gt; channelFactory = null;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; EndpointAddress ep = null;<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; string strEPAdr = &quot;<\/strong><\/font><a href=\"http:\/\/&quot;\"><font color=\"#0000ff\" face=\"Courier New\">http:\/\/&quot;<\/font><\/a><font color=\"#0000ff\" face=\"Courier New\"><strong> + strServer + &quot;:&quot; + nPort.ToString() + &quot;\/MathService&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; switch (strBinding)        <br \/>&#160;&#160;&#160;&#160;&#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;&#160;&#160;&#160;&#160; case &quot;TCP&quot;:        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; NetTcpBinding tcpb = new NetTcpBinding();        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; channelFactory = new ChannelFactory&lt;IMathService&gt;(tcpb);<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \/\/ End Point Address       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; strEPAdr = &quot;net.tcp:\/\/&quot; + strServer + &quot;:&quot; + nPort.ToString() + &quot;\/MathService&quot;;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; break;<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; case &quot;HTTP&quot;:       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; BasicHttpBinding httpb = new BasicHttpBinding();        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; channelFactory = new ChannelFactory&lt;IMathService&gt;(httpb);<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \/\/ End Point Address       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; strEPAdr = &quot;<\/strong><\/font><a href=\"http:\/\/&quot;\"><font color=\"#0000ff\" face=\"Courier New\">http:\/\/&quot;<\/font><\/a><font color=\"#0000ff\" face=\"Courier New\"><strong> + strServer + &quot;:&quot; + nPort.ToString() + &quot;\/MathService&quot;;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; break;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#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;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \/\/ Create End Point       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ep = new EndpointAddress(strEPAdr);<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \/\/ Create Channel       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; IMathService mathSvcObj = channelFactory.CreateChannel(ep);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; double dblResult = 0;<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \/\/ Call Methods       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; switch (strOper)        <br \/>&#160;&#160;&#160;&#160;&#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;&#160;&#160;&#160;&#160; case &quot;ADD&quot;: dblResult = mathSvcObj.AddNumber(dblVal1, dblVal2); break;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; case &quot;SUB&quot;: dblResult = mathSvcObj.SubtractNumber(dblVal1, dblVal2); break;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; case &quot;MUL&quot;: dblResult = mathSvcObj.MultiplyNumber(dblVal1, dblVal2); break;        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; case &quot;DIV&quot;: dblResult = mathSvcObj.DivideNumber(dblVal1, dblVal2); break;        <br \/>&#160;&#160;&#160;&#160;&#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;&#160;&#160;&#160;&#160; \/\/&#160; Display Results.        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Operation {0} &quot;, strOper );        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Operand 1 {0} &quot;, dblVal1.ToString ( &quot;F2&quot;));        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Operand 2 {0} &quot;, dblVal2.ToString(&quot;F2&quot;));        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Result {0} &quot;, dblResult.ToString(&quot;F2&quot;));<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \/\/ Close channel       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; channelFactory.Close();        <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; \/\/ Something happended ..        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Error while performing operation [&quot; + eX.Message + &quot;] \\n\\n Inner Exception [&quot; + eX.InnerException + &quot;]&quot;);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }        <br \/>&#160;&#160;&#160; }        <br \/>}<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>\/\/&#160;&#160;&#160; Listing of IMathInterface.cs<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>using System;       <br \/>using System.Collections.Generic;        <br \/>using System.Linq;        <br \/>using System.Text;        <br \/>using System.ServiceModel;<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>namespace ConWCFMathClient       <br \/>{        <br \/>&#160;&#160;&#160; [ServiceContract]        <br \/>&#160;&#160;&#160; public interface IMathService        <br \/>&#160;&#160;&#160; {        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; [OperationContract]        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; double AddNumber(double dblX, double dblY);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; [OperationContract]        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; double SubtractNumber(double dblX, double dblY);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; [OperationContract]        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; double MultiplyNumber(double dblX, double dblY);        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; [OperationContract]        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; double DivideNumber(double dblX, double dblY);        <br \/>&#160;&#160;&#160; }        <br \/>}<\/strong><\/font><\/p>\n<h4>Output<\/h4>\n<h5>Running the Host Application as a TCP Service<\/h5>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/09\/image23.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\/09\/image_thumb23.png\" width=\"641\" height=\"84\" \/><\/a><\/p>\n<h5>Running the Client Application<\/h5>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/09\/image24.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\/09\/image_thumb24.png\" width=\"663\" height=\"294\" \/><\/a><\/p>\n<h5>Running the Host Application as a HTTP Service<\/h5>\n<p><span style=\"font-size:small;\"><strong>Note<\/strong>:&#160; <strong><span style=\"color:#ff0000;\">while running the Service in HTTP Mode, you need to open command prompt in administrator mode.<\/span><\/strong><\/span><\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/09\/image25.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\/09\/image_thumb26.png\" width=\"651\" height=\"78\" \/><\/a><\/p>\n<h5>Running the Client Application<\/h5>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/09\/image26.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\/09\/image_thumb27.png\" width=\"649\" height=\"277\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction This article explains how to create a simple WCF Service Host it on a specified port according to specified binding. all this you can do on the fly. Background Normally when we develop WCF Services, we are in habit of using Configuration files. (web.config\/app.config depending on the environment). it is indeed very good idea&hellip; <a class=\"more-link\" href=\"https:\/\/praveenkatiyar.in\/blog\/index.php\/2013\/09\/12\/creating-and-consuming-a-wcf-service-without-configuration-files\/\">Continue reading <span class=\"screen-reader-text\">Creating and Consuming a WCF Service without configuration files.<\/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-181","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\/181","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=181"}],"version-history":[{"count":0,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/posts\/181\/revisions"}],"wp:attachment":[{"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}