{"id":155,"date":"2013-09-09T16:15:13","date_gmt":"2013-09-09T16:15:13","guid":{"rendered":"https:\/\/praveenkatiyar.wordpress.com\/?p=155"},"modified":"2013-09-09T16:15:13","modified_gmt":"2013-09-09T16:15:13","slug":"creating-a-wcf-service-with-self-hosted","status":"publish","type":"post","link":"https:\/\/praveenkatiyar.in\/blog\/index.php\/2013\/09\/09\/creating-a-wcf-service-with-self-hosted\/","title":{"rendered":"Creating a Self Hosted WCF Service"},"content":{"rendered":"<p><font color=\"#000080\">In this post I am going to explain how to create a simple WCF Service, with Self Hosting and consume it, there will be 4 parts of the project. <\/font><\/p>\n<ol>\n<li><font color=\"#000080\"><strong>A Class Library (MyMathServiceLib.dll): <\/strong>which will implement our business logic. <\/font><\/li>\n<li><font color=\"#000080\"><strong>Service Host Application (MathServiceHost.exe):<\/strong> Application which will host this class library as a WCF Service.<\/font> <\/li>\n<li><font color=\"#000080\"><strong>A Windows Client Application (MyMathService<strong>Client<\/strong>.exe):<\/strong> Client Application which will use this service.<\/font> <\/li>\n<li><font color=\"#000080\"><strong>A Web Client, <\/strong><\/font><font color=\"#000080\">that will use this Service.<\/font> <\/li>\n<\/ol>\n<h4><font style=\"font-weight:bold;\">Note:<\/font><\/h4>\n<h3><\/h3>\n<p><font color=\"#000080\">part 1 and 2 can be merged into one, if one like so, but, for the sake of portability, keep them as separate modules. let\u2019s start with creating the Class Library.<\/font><\/p>\n<h3><font style=\"font-weight:bold;\">Part 1: Creating the Class Library<\/font><\/h3>\n<p><font color=\"#000080\">Start the Visual Studio, and click <strong>File-&gt;New-&gt;Project <\/strong>. Select the project template <strong>&#8216;Class Library<\/strong>&quot; click OK. <\/font><\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/09\/image8.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_thumb8.png\" width=\"614\" height=\"359\" \/><\/a><\/p>\n<p><font color=\"#000080\">Now let&#8217;s analyse the project created by wizard for us, and do little house keeping, before we write any code.<\/font><\/p>\n<ul>\n<li><font color=\"#000080\">Class1.cs (The default class, created by wizard).<\/font> <\/li>\n<\/ul>\n<h4>Assumption<\/h4>\n<p><font color=\"#000080\">We are going to create a Service as per following assumptions.<\/font><\/p>\n<ul>\n<li><font color=\"#000080\">Interface will named as IMyMathService (<strong>IMyMathService.cs<\/strong>)<\/font> <\/li>\n<li><font color=\"#000080\">Service will be implemented as MyMathService (<strong>MyMathService.cs<\/strong>)<\/font> <\/li>\n<\/ul>\n<h4>Little house keeping. (just to keep things organized)<\/h4>\n<ul>\n<li><font color=\"#000080\">Delete <strong>Class1.cs <\/strong>the project workspace.<\/font> <\/li>\n<li><font color=\"#000080\">Add an <strong>Interface<\/strong> (<strong>IMyMathService<\/strong>) <strong>IMyMathService.cs<\/strong> to the project.<\/font> <\/li>\n<li><font color=\"#000080\">Add an <strong>Class<\/strong> (<strong>MyMathService<\/strong>) <strong>MyMathService.cs<\/strong> to the project.<\/font> <\/li>\n<li><font color=\"#000080\">Add reference of <strong>System.ServiceModel<\/strong> to the&#160; project.<\/font> <\/li>\n<\/ul>\n<p><font color=\"#000080\">Now, let&#8217;s define the Interface and its implementation of our old familiar class Library.<\/font><\/p>\n<p><font color=\"#000080\"><strong>\/\/&#160; Listing of IMyMathService.cs, <\/strong><\/font><\/p>\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 MyMathServiceLib      <br \/>{       <br \/>&#160;&#160;&#160; [ServiceContract]       <br \/>&#160;&#160;&#160; public interface IMyMathService       <br \/>&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; [OperationContract]       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; double Add(double dblNum1, double dblNum2);<\/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 Subtract(double dblNum1, double dblNum2);<\/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 Multiply(double dblNum1, double dblNum2);<\/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 Divide(double dblNum1, double dblNum2);       <br \/>&#160;&#160;&#160; }       <br \/>}       <br \/><\/font><\/p>\n<p><font color=\"#000080\"><strong>\/\/&#160; Listing of MyMathService.cs, <\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">using System;      <br \/>using System.ServiceModel;       <br \/>using System.Text;       <br \/>using System.ServiceModel;<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">namespace MyMathServiceLib      <br \/>{       <br \/>&#160;&#160;&#160; public class MyMathService : IMyMathService       <br \/>&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public double Add(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; }<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160; public double Subtract(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 &#8211; dblNum2);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160; public double Multiply(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; }<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160; public double Divide(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 ((dblNum2 == 0) ? 0 : (dblNum1 \/ dblNum2));       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }       <br \/>&#160;&#160;&#160; }       <br \/>}<\/font><\/p>\n<h3><font style=\"font-weight:bold;\">Part 2: Creating the Host Application <\/font><\/h3>\n<p><font color=\"#000080\">Our class library is ready, let&#8217;s write an Host application, which will expose this facility to the world as a WCF Service. lets&#8217; Create a Console based application, for the sake of simplicity, name it <strong>MyMathServiceHost<\/strong>, as shown below.<\/font><\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/09\/image9.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"background-image:none;float:none;padding-top:0;padding-left:0;margin-left:auto;display:block;padding-right:0;margin-right:auto;border-width:0;\" border=\"0\" alt=\"image\" src=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/09\/image_thumb9.png\" width=\"613\" height=\"396\" \/><\/a><\/p>\n<p><font color=\"#000080\">a new Project <strong>MyMathServiceHost<\/strong> will be added to the workspace.<\/font> <\/p>\n<h4>Assumption<\/h4>\n<p><font color=\"#000080\">The Host application will expose the following endpoints for the service.<\/font><\/p>\n<ul>\n<li><font color=\"#000080\">Service will implement <strong>HTTP endpoint at Port 9001<\/strong><\/font> <\/li>\n<li><font color=\"#000080\"><font color=\"#000080\">Corresponding <strong>mex <\/strong>End Point&#160; <strong>(IMetadatExchange)<\/strong> for the HTTP end point.<\/font>&#160;<\/font>&#160; <\/li>\n<li><font color=\"#000080\">Service will implement <strong>TCP endpoint at Port 9002<\/strong><\/font> <\/li>\n<li><font color=\"#000080\"><font color=\"#000080\">Corresponding <strong>mex <\/strong>End Point&#160; <strong>(IMetadatExchange)<\/strong> for the TCP end point.<\/font>&#160;<\/font>&#160; <\/li>\n<\/ul>\n<h4>Adding reference of the class library to the Host project <\/h4>\n<ul>\n<li><font color=\"#000080\">Add reference of the class library to the console project,as shown below.<\/font> <\/li>\n<\/ul>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/09\/image10.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_thumb10.png\" width=\"619\" height=\"316\" \/><\/a><\/p>\n<ul>\n<li><font color=\"#000080\">Add reference of <strong>System.ServiceModel<\/strong> to the&#160; project.<\/font> <\/li>\n<\/ul>\n<h4>Creating the Service Configuration <\/h4>\n<p><font color=\"#000080\">Add a Application configuration file (<strong>App.config<\/strong>) to the Host Project. define the End Points and bindings according to the assumptions made at the start of the project.<\/font><\/p>\n<ul>\n<li><font color=\"#000080\">will expose an end point with HTTP Binding at 9001<\/font> <\/li>\n<li><font color=\"#000080\">will expose an end point with TCP Binding at 9002<\/font> <\/li>\n<li><font color=\"#000080\">will expose, required <strong>mex<\/strong> (one for each binding) end points<\/font> <\/li>\n<\/ul>\n<p><font color=\"#0000ff\">below is he listing of the app.config file.<\/font><\/p>\n<p><font color=\"#0000ff\">&lt;?xml versio=&quot;1.0&quot;?&gt;      <br \/>&lt;configuration&gt;<\/font><\/p>\n<p><font color=\"#0000ff\">&#160;&#160;&#160; &lt;system.serviceModel&gt;      <br \/>&#160;&#160;&#160;&#160;&#160; &lt;services&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;service name=&quot;MyMathServiceLib.MyMathService&quot; behaviorConfiguration=&quot;<strong>myMathServiceBehave<\/strong>&quot;&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;host&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;baseAddresses&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;add baseAddress=&quot;<strong>http:\/\/localhost:9001\/MyMathService<\/strong>&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;add baseAddress=&quot;<strong>net.tcp:\/\/localhost:9002\/MyMathService<\/strong>&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/baseAddresses&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/host&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;endpoint address=&quot;<strong>http:\/\/localhost:9001\/MyMathService<\/strong>&quot; binding=&quot;<strong>basicHttpBinding<\/strong>&quot; contract=&quot;MyMathServiceLib.IMyMathService&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;endpoint address=&quot;<strong>net.tcp:\/\/localhost:9002\/MyMathService<\/strong>&quot; binding=&quot;<strong>netTcpBinding<\/strong>&quot; contract=&quot;MyMathServiceLib.IMyMathService&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;endpoint 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;&#160;&#160; &lt;endpoint 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;&#160;&#160; &lt;\/service&gt;       <br \/>&#160;&#160;&#160;&#160;&#160; &lt;\/services&gt;       <br \/>&#160;&#160;&#160;&#160;&#160; &lt;behaviors&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;serviceBehaviors&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;behavior name=&quot;<strong>myMathServiceBehave<\/strong>&quot;&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;serviceMetadata <strong>httpGetEnabled<\/strong>=&quot;true&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/behavior&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/serviceBehaviors&gt;       <br \/>&#160;&#160;&#160;&#160;&#160; &lt;\/behaviors&gt;       <br \/>&#160;&#160;&#160; &lt;\/system.serviceModel&gt;       <br \/>&lt;\/configuration&gt;<\/font><\/p>\n<h5>Description<\/h5>\n<ul>\n<li><font color=\"#000080\">Application configuration files defines 2 endpoints, one for TCP and one for HTTP. and 1 <strong>mex<\/strong> end point for each.<\/font> <\/li>\n<li><font color=\"#000080\">Service behavior define, <\/font><font color=\"#0000ff\">&lt;serviceMetadata <strong>httpGetEnabled<\/strong>=&quot;true&quot;\/&gt;<\/font> <font color=\"#000080\">that meta data should be available through a HTTP get request.<\/font> <\/li>\n<\/ul>\n<h4>Write code to Host the Service. <\/h4>\n<p><font color=\"#000080\">Write the code to Host the Service in the Main function of the Open Program.cs, and let&#8217;s write the code.<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Verdana\">using System;      <br \/>using System.Collections.Generic;       <br \/>using System.Linq;       <br \/>using System.Text;       <br \/>using System.ServiceModel;       <br \/>using System.ServiceModel.Description;<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Verdana\">namespace CalcServiceHost      <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 svcHost = null;       <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; <strong>svcHost = new ServiceHost(typeof(MyMathServiceLib.MyMathService));        <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; svcHost.Open();         <br \/><\/strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\n\\nService is Running&#160; at following address&quot; );       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\nhttp:\/\/localhost:9001\/MyMathService&quot;);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\nnet.tcp:\/\/localhost:9002\/MyMathService&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; 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; 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 \\n\\nError Message [&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=\"Verdana\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (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; svcHost.Close();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 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 \/>}<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"1\" face=\"Verdana\"><\/font><\/p>\n<p><font color=\"#0000ff\"><\/font><\/p>\n<h5>explanation<\/h5>\n<p><font color=\"#000080\">as you can see from the above code, <\/font><\/p>\n<ul>\n<li><font color=\"#000080\">Class Library is simply hosted inside a <strong>ServiceHost<\/strong> object, as all the End Points are defined in <strong>App.config file.<\/strong><\/font><strong> <\/strong><\/li>\n<\/ul>\n<h3><font style=\"font-weight:bold;\">Part 3: Creating the Windows Client<\/font><\/h3>\n<p><font color=\"#000080\">Now when our service is self hosted and running, let us write a client Application, which can use this Service. lets&#8217; Create a Console based application, for the sake of simplicity, name it <strong>MyMathServiceClient<\/strong>, as shown below.<\/font><\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/09\/image11.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_thumb11.png\" width=\"628\" height=\"401\" \/><\/a><\/p>\n<p><font color=\"#000080\">newly created project will be added to the work space.<\/font><\/p>\n<h4>Generating proxy and config file.<font color=\"#000080\"><\/font><font color=\"#000080\"><\/font> <\/h4>\n<p><font color=\"#000080\">Before we write the Client application, we need to generate the proxy for our Service, open a command prompt in <strong>Administrator mode<\/strong>. and execute the Host Application. <\/font><\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/09\/image12.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"background-image:none;padding-top:0;padding-left:0;margin:0;display:inline;padding-right:0;border-width:0;\" border=\"0\" alt=\"image\" src=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/09\/image_thumb12.png\" width=\"653\" height=\"128\" \/><\/a><\/p>\n<p><font color=\"#000080\">Open <strong>another command prompt<\/strong>, <strong>switch to the folder<\/strong>, where client project has been created, and generate the <strong>proxy and configuration file<\/strong> using the SVCUtil.exe utility. as shown below.<\/font><\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/09\/image13.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_thumb13.png\" width=\"654\" height=\"150\" \/><\/a><\/p>\n<p><font color=\"#000080\">add both these files to the client project.<\/font><\/p>\n<p><font color=\"#000080\"><\/font><\/p>\n<p> <font color=\"#000080\"><font color=\"#000080\">     <\/p>\n<h3><font style=\"font-weight:bold;\">Calling the Service<\/font><\/h3>\n<p>   <\/font><\/font><font color=\"#000080\"><\/font>  <\/p>\n<p><font color=\"#000080\">Now write the code to use the proxy and call the service, here is the listing of the <strong>Program.cs<\/strong>.<\/font><\/p>\n<p><font color=\"#0000ff\">using System;      <br \/>using System.Collections.Generic;       <br \/>using System.Linq;       <br \/>using System.Text;<\/font><\/p>\n<p><font color=\"#0000ff\">namespace MyMathClient      <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 dblX = 2000.0;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; double dblY = 100.0;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; double dblResult = 0;<\/font><\/p>\n<p><font color=\"#0000ff\">&#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; Console.WriteLine(&quot;Using TCP Binding&quot;, dblX, dblY, dblResult);<\/font><\/p>\n<p><font color=\"#0000ff\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; MyMathServiceClient mathClient1 = new MyMathServiceClient(&quot;NetTcpBinding_IMyMathService&quot;);<\/font><\/p>\n<p><font color=\"#0000ff\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dblResult = mathClient1.Add(dblX, dblY);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Calling Add &gt;&gt;&#160; X : {0:F2}&#160; Y : {1:F2}&#160; Result : {2:F2}&quot;, dblX, dblY, dblResult);<\/font><\/p>\n<p><font color=\"#0000ff\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dblResult = mathClient1.Subtract(dblX, dblY);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Calling Sub &gt;&gt;&#160; X : {0:F2}&#160; Y : {1:F2}&#160; Result : {2:F2}&quot;, dblX, dblY, dblResult);<\/font><\/p>\n<p><font color=\"#0000ff\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dblResult = mathClient1.Multiply(dblX, dblY);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Calling Mul &gt;&gt;&#160; X : {0:F2}&#160; Y : {1:F2}&#160; Result : {2:F2}&quot;, dblX, dblY, dblResult);<\/font><\/p>\n<p><font color=\"#0000ff\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dblResult = mathClient1.Divide(dblX, dblY);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Calling Sub &gt;&gt;&#160; X : {0:F2}&#160; Y : {1:F2}&#160; Result : {2:F2}&quot;, dblX, dblY, dblResult);<\/font><\/p>\n<p><font color=\"#0000ff\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Using Basic HTTP Binding&quot;, dblX, dblY, dblResult);<\/font><\/p>\n<p><font color=\"#0000ff\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; MyMathServiceClient mathClient2 = new MyMathServiceClient(&quot;BasicHttpBinding_IMyMathService&quot;);<\/font><\/p>\n<p><font color=\"#0000ff\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dblResult = mathClient2.Add(dblX, dblY);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Calling Add &gt;&gt;&#160; X : {0:F2}&#160; Y : {1:F2}&#160; Result : {2:F2}&quot;, dblX, dblY, dblResult);<\/font><\/p>\n<p><font color=\"#0000ff\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dblResult = mathClient2.Subtract(dblX, dblY);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Calling Sub &gt;&gt;&#160; X : {0:F2}&#160; Y : {1:F2}&#160; Result : {2:F2}&quot;, dblX, dblY, dblResult);<\/font><\/p>\n<p><font color=\"#0000ff\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dblResult = mathClient2.Multiply(dblX, dblY);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Calling Mul &gt;&gt;&#160; X : {0:F2}&#160; Y : {1:F2}&#160; Result : {2:F2}&quot;, dblX, dblY, dblResult);<\/font><\/p>\n<p><font color=\"#0000ff\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dblResult = mathClient2.Divide(dblX, dblY);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Calling Sub &gt;&gt;&#160; X : {0:F2}&#160; Y : {1:F2}&#160; Result : {2:F2}&quot;, dblX, dblY, dblResult);       <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;There was an error while calling 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; }       <br \/>&#160;&#160;&#160; }       <br \/>}<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Arial\"><\/font><\/p>\n<p>and here is the output.<\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/09\/image14.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_thumb14.png\" width=\"652\" height=\"163\" \/><\/a><\/p>\n<h3><font style=\"font-weight:bold;\">Part 4: Creating a Web Client<\/font><\/h3>\n<p><font color=\"#000080\">Create a New Web Site, using the File \u2013&gt; New Web Site as shown below. name it <strong>MyMathWebClient<\/strong>.<\/font><\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/09\/image15.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_thumb15.png\" width=\"657\" height=\"375\" \/><\/a><\/p>\n<p> <font color=\"#000080\"><font color=\"#000080\"><font color=\"#000080\">       <\/p>\n<p>&#160;<\/p>\n<p><font color=\"#000080\">Click OK, <\/font><\/p>\n<p>Now we need to add a reference to our service to this web site, right click on the newly created web site project, and click on Add Service Reference. a dialog box will pop up.<\/p>\n<ul>\n<li>Enter any (TCP\/HTTP) endpoint address in the address box. <\/li>\n<li>Name the namespace, where Service Proxy will be added to the project. <\/li>\n<\/ul>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/09\/image16.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_thumb16.png\" width=\"634\" height=\"386\" \/><\/a><\/p>\n<p>click OK, some changes will be made to your web.config file, and App_WebReferences folder will be added, under which a Service reference &quot;<strong>MathServiceReference<\/strong>&quot; will be added.<\/p>\n<ul>\n<li>a Service reference named <strong>MyMathServiceReference<\/strong> will be added in <strong>Service References node<\/strong> of the client project. <\/li>\n<li>some changes will be made to the web.config file, <\/li>\n<\/ul>\n<p>let&#8217;s analyse the changes made to web.config. open the web.config, you will find the changes at the end of the file, see the &lt;system.ServiceModel&gt; section, as shown below.<\/p>\n<p><font color=\"#0000ff\"><strong>&lt;system.serviceModel&gt;<\/strong>             <br \/>&#160;&#160;&#160; &lt;bindings&gt;             <br \/>&#160;&#160;&#160;&#160;&#160; &lt;basicHttpBinding&gt;             <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;binding name=&quot;<strong>BasicHttpBinding_IMyMathService<\/strong>&quot;\/&gt;             <br \/>&#160;&#160;&#160;&#160;&#160; &lt;\/basicHttpBinding&gt;             <br \/>&#160;&#160;&#160;&#160;&#160; &lt;netTcpBinding&gt;             <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;binding name=&quot;<strong>NetTcpBinding_IMyMathService<\/strong>&quot;\/&gt;             <br \/>&#160;&#160;&#160;&#160;&#160; &lt;\/netTcpBinding&gt;             <br \/>&#160;&#160;&#160; &lt;\/bindings&gt;             <br \/>&#160;&#160;&#160; &lt;client&gt;             <br \/><strong>&#160;&#160;&#160;&#160;&#160; &lt;endpoint<\/strong> address=&quot;<\/font><font color=\"#0000ff\">http:\/\/localhost:9001\/MyMathService&quot;<\/font><font color=\"#0000ff\"> binding=&quot;basicHttpBinding&quot; bindingConfiguration=&quot;BasicHttpBinding_IMyMathService&quot; contract=&quot;MathServiceReference.IMyMathService&quot; name=&quot;<strong>BasicHttpBinding_IMyMathService<\/strong>&quot;\/&gt;             <br \/>&#160;&#160;&#160;&#160;&#160; <strong>&lt;endpoint <\/strong>address=&quot;net.tcp:\/\/localhost:9002\/MyMathService&quot; binding=&quot;netTcpBinding&quot; bindingConfiguration=&quot;NetTcpBinding_IMyMathService&quot; contract=&quot;MathServiceReference.IMyMathService&quot; name=&quot;<strong>NetTcpBinding_IMyMathServic<\/strong>e&quot;&gt;             <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;identity&gt;<\/font><\/p>\n<p><font color=\"#0000ff\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color=\"#ff0000\"><strong>&lt;!\u2014this value will be different on your machine \u2013!&gt;                <br \/><\/strong><\/font>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;userPrincipalName value=&quot;PRAVEEN-WIN7\\BriskTech&quot;\/&gt;             <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/identity&gt;             <br \/>&#160;&#160;&#160;&#160;&#160; &lt;\/endpoint&gt;             <br \/>&#160;&#160;&#160; &lt;\/client&gt;             <br \/><strong>&lt;\/system.serviceModel&gt;<\/strong><\/font><\/p>\n<p>Open the Main page of the site (Default.aspx page), double click, that will create the Page_Load&#160; handler for the Page, lets call our service in the page load handler.<\/p>\n<p><font color=\"#0000ff\" size=\"1\" face=\"Verdana\"><strong>protected void Page_Load(object sender, EventArgs e)              <br \/>&#160;&#160;&#160; {               <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; double dblX = 10000.0 ;               <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; double dblY = 2000.0 ;               <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Response.Write ( &quot;&lt;p&gt;Value 1 : &quot; + dblX.ToString ( &quot;F2&quot;));               <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Response.Write ( &quot;&lt;br&gt;Value 2 : &quot; + dblY.ToString ( &quot;F2&quot;));<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"1\" face=\"Verdana\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160; try              <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {               <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Response.Write(&quot;&lt;p&gt;Using TCP Binding&quot;);<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"1\" face=\"Verdana\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; MathServiceReference.MyMathServiceClient mathProxy1 = new MathServiceReference.MyMathServiceClient(&quot;NetTcpBinding_IMyMathService&quot;);<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"1\" face=\"Verdana\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; double dblResult = mathProxy1.Add(dblX, dblY);              <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Response.Write(&quot;&lt;br&gt;Calling Add &gt;&gt;&#160; X : &quot; + dblX.ToString(&quot;F2&quot;) + &quot;&#160; Y : &quot; + dblY.ToString(&quot;F2&quot;) + &quot; Result : &quot; + dblResult.ToString(&quot;F2&quot;));<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"1\" face=\"Verdana\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dblResult = mathProxy1.Subtract(dblX, dblY);              <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Response.Write(&quot;&lt;br&gt;Calling Add &gt;&gt;&#160; X : &quot; + dblX.ToString(&quot;F2&quot;) + &quot;&#160; Y : &quot; + dblY.ToString(&quot;F2&quot;) + &quot; Result : &quot; + dblResult.ToString(&quot;F2&quot;));<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"1\" face=\"Verdana\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dblResult = mathProxy1.Multiply(dblX, dblY);              <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Response.Write(&quot;&lt;br&gt;Calling Add &gt;&gt;&#160; X : &quot; + dblX.ToString(&quot;F2&quot;) + &quot;&#160; Y : &quot; + dblY.ToString(&quot;F2&quot;) + &quot; Result : &quot; + dblResult.ToString(&quot;F2&quot;));<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"1\" face=\"Verdana\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dblResult = mathProxy1.Divide(dblX, dblY);              <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Response.Write(&quot;&lt;br&gt;Calling Add &gt;&gt;&#160; X : &quot; + dblX.ToString(&quot;F2&quot;) + &quot;&#160; Y : &quot; + dblY.ToString(&quot;F2&quot;) + &quot; Result : &quot; + dblResult.ToString(&quot;F2&quot;));<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"1\" face=\"Verdana\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Response.Write(&quot;&lt;p&gt;Using Basic HTTP Binding&quot;);<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"1\" face=\"Verdana\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; MathServiceReference.MyMathServiceClient mathProxy2 = new MathServiceReference.MyMathServiceClient(&quot;BasicHttpBinding_IMyMathService&quot;);<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"1\" face=\"Verdana\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dblResult = mathProxy2.Add(dblX, dblY);              <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Response.Write(&quot;&lt;br&gt;Calling Add &gt;&gt;&#160; X : &quot; + dblX.ToString(&quot;F2&quot;) + &quot;&#160; Y : &quot; + dblY.ToString(&quot;F2&quot;) + &quot; Result : &quot; + dblResult.ToString(&quot;F2&quot;));<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"1\" face=\"Verdana\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dblResult = mathProxy2.Subtract(dblX, dblY);              <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Response.Write(&quot;&lt;br&gt;Calling Add &gt;&gt;&#160; X : &quot; + dblX.ToString(&quot;F2&quot;) + &quot;&#160; Y : &quot; + dblY.ToString(&quot;F2&quot;) + &quot; Result : &quot; + dblResult.ToString(&quot;F2&quot;));<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"1\" face=\"Verdana\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dblResult = mathProxy2.Multiply(dblX, dblY);              <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Response.Write(&quot;&lt;br&gt;Calling Add &gt;&gt;&#160; X : &quot; + dblX.ToString(&quot;F2&quot;) + &quot;&#160; Y : &quot; + dblY.ToString(&quot;F2&quot;) + &quot; Result : &quot; + dblResult.ToString(&quot;F2&quot;));<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"1\" face=\"Verdana\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dblResult = mathProxy2.Divide(dblX, dblY);              <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Response.Write(&quot;&lt;br&gt;Calling Add &gt;&gt;&#160; X : &quot; + dblX.ToString(&quot;F2&quot;) + &quot;&#160; Y : &quot; + dblY.ToString(&quot;F2&quot;) + &quot; Result : &quot; + dblResult.ToString(&quot;F2&quot;));               <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }               <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; catch (Exception eX)               <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {               <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Response.Write(&quot;There was an error while calling Service &lt;p&gt; &lt;b&gt;[&quot; + eX.Message + &quot;] &lt;\/b&gt;&quot;);               <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }               <br \/>&#160;&#160;&#160; }<\/strong><\/font><\/p>\n<p>Build and run the web site, following output will be displayed.<\/p>\n<p>     <\/font><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/09\/image17.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_thumb17.png\" width=\"500\" height=\"242\" \/><\/a><\/font>     <\/p>\n<p>that&#8217;s all folks.<\/p>\n<p> <\/font><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post I am going to explain how to create a simple WCF Service, with Self Hosting and consume it, there will be 4 parts of the project. A Class Library (MyMathServiceLib.dll): which will implement our business logic. Service Host Application (MathServiceHost.exe): Application which will host this class library as a WCF Service. A&hellip; <a class=\"more-link\" href=\"https:\/\/praveenkatiyar.in\/blog\/index.php\/2013\/09\/09\/creating-a-wcf-service-with-self-hosted\/\">Continue reading <span class=\"screen-reader-text\">Creating a Self Hosted WCF Service<\/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":[3,12],"tags":[33],"class_list":["post-155","post","type-post","status-publish","format-standard","hentry","category-codeproject","category-soa","tag-wcf","entry"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/posts\/155","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=155"}],"version-history":[{"count":0,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/posts\/155\/revisions"}],"wp:attachment":[{"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}