{"id":329,"date":"2013-10-10T10:49:20","date_gmt":"2013-10-10T10:49:20","guid":{"rendered":"https:\/\/praveenkatiyar.wordpress.com\/?p=329"},"modified":"2013-10-10T10:49:20","modified_gmt":"2013-10-10T10:49:20","slug":"understanding-contracts-in-wcf","status":"publish","type":"post","link":"https:\/\/praveenkatiyar.in\/blog\/index.php\/2013\/10\/10\/understanding-contracts-in-wcf\/","title":{"rendered":"Understanding Contracts in WCF"},"content":{"rendered":"<h3>Introduction <\/h3>\n<p>Contracts in WCF, provide interoperability they need to communicate with the client. In this article i am going to explain the type of contracts, and how these contracts can be used in a real life application. in this article i have tried to explain all these things, using a simple example, in this example i have taken a real world cuboid, which has 3 properties (length, width and height), our service calculates volume and total surface area of the cuboid. demonstrating both way, using message contract and data contract.&#160; <\/p>\n<h3>Background<\/h3>\n<p>it is contracts that that client and service agree as to the type of operation and structure they will use during communication. it is a formal agreement between a client and service to define a platform-neutral and standard way of describing what the service does. WCF defines four types of contracts<\/p>\n<p>&#160; to defines four types of contracts. <\/p>\n<ul>\n<li>Service Contract <\/li>\n<li>Data Contract <\/li>\n<li>Message Contract <\/li>\n<li>Fault Contract <\/li>\n<\/ul>\n<h3>Service Contract<\/h3>\n<p>Service contract <strong>describes the operations<\/strong>, or methods, <strong>that are available on the service endpoint<\/strong>, and exposed to the outside world. A Service contract describes the client-callable operations (functions) exposed by the service, apart from that it also describes.&#160; <\/p>\n<ul>\n<li>location of operations, interface and methods of your service to a platform-independent description <\/li>\n<li>message exchange patterns that the service can have with another party. might be one-way\/request-reply\/duplex. <\/li>\n<\/ul>\n<p>To create a service contract you define an interface with related methods representative of a collection of service operations, and then decorate the interface\/class with the <i><strong>ServiceContract<\/strong><\/i> Attribute to indicate it is a service contract. Methods in the interface that should be included in the service contract are decorated with the <i><strong>OperationContract<\/strong><\/i> Attribute. <\/p>\n<h5><font color=\"#0000ff\" face=\"Courier New\">[ServiceContract]      <br \/>interface ICuboidService       <br \/>{       <br \/>&#160;&#160;&#160; [OperationContract]       <br \/>&#160;&#160;&#160; CuboidDetail CalculateDetails2(CuboidInfo cInfo);       <br \/>}<\/font><\/h5>\n<h3>Data Contract<\/h3>\n<p>In one line, data contract <strong>describes the data to be exchanged<\/strong>. it is formal agreement between service and client, that <strong>contains information about the data they will be exchanging<\/strong>. the important point, which needs to be mentioned here is that the two parties don&#8217;t have to share the same data types to communicate, they only need the share the same data contracts. Data contract defines which parameter &amp; return type will be serialized\/de-serialized to and from (Binary &lt;==&gt; XML) in order to be transmitted between one party to another.&#160; Data contracts can be defined by annotating a class, enumeration, or even a structure, but not an interface.<\/p>\n<p>to define a data contract, you simply decorate a class or enumeration with <strong>[DataContract]<\/strong> attribute, as shown below.<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>[DataContract]        <br \/>public class CuboidInfo         <br \/>{         <br \/>}<\/strong><\/font><\/p>\n<h3>Message Contract<\/h3>\n<p>WCF uses SOAP message for communication. Most of the time developer concentrates more on developing the <strong>DataContract<\/strong>, Serializing the data, etc. Some time developer will also require control over the SOAP message format. In that case WCF provides Message Contract to customize the message as per requirement.<\/p>\n<p>A <strong>Message Contract<\/strong> is used to control the structure of a message body and serialization process. It is also used to send \/ access information in SOAP headers. By default WCF takes care of creating SOAP messages according to service <strong>DataContracts<\/strong> and <strong>OperationContracts<\/strong>. <\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image8.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\/10\/image_thumb8.png\" width=\"488\" height=\"155\" \/><\/a><\/p>\n<p>So when you need full control on SOAP messages structure and how serialization happens specially when your service needs to be interoperable for consuming by different types of clients or service needs to provide extra layer of security on messages and message parts, A message is nothing but a packet and WCF uses this packet to transfer information from source to destination. This message contains an <strong>envelope<\/strong>, <strong>header <\/strong>and <strong>body<\/strong>. There are some rules, which one needs to follow, while working with&#160; message contract.<\/p>\n<ol>\n<li>When using Message contract type as parameter, Only <strong>one parameter can be used in Operation<\/strong>. <\/li>\n<li>Service operation either <strong>should return MessageContract<\/strong> type <strong>or<\/strong> it <strong>should not return any value<\/strong>. <\/li>\n<li>Operation will <strong>accept and return only message contract type<\/strong>. Other data types are not allowed. <\/li>\n<\/ol>\n<h3>Choosing between DataContract and MessageContract.<\/h3>\n<p>90 % of the time, <strong>DataContract will be sufficient<\/strong>, You&#8217;ll only need message contracts if you need to very closely and very specifically control the layout of your SOAP messages. In most of the time,&#160; you don&#8217;t need to.<\/p>\n<p>A message contract allows you to specifically say which elements (scalar types or compound types as <strong>DataContracts<\/strong>) will be in the SOAP header, and which will be in the SOAP body.<\/p>\n<p>You might need this if you have a communication partner, with whom you have agreed to a very specific format and you have to tweak your SOAP messages to match that given layout exactly. That&#8217;s just about the <strong>only valid scenario <\/strong>when <strong>you&#8217;ll need<\/strong> to and <strong>should use message contracts<\/strong>.<\/p>\n<p>However, sometimes complete control over the structure of a SOAP message is just as important as control over its contents. This is especially true when <strong>interoperability is important or to specifically control security issues at the level of the message or message part<\/strong>. In these cases, you can create a <em>message contract<\/em> that enables you to use a type for a parameter or return value <strong>that serializes directly into the precise SOAP message that you need<\/strong>.<\/p>\n<p>So, to making the long story short: <strong>always<\/strong> use <strong>data contracts<\/strong>, practically <strong>never use message contracts <\/strong>(unless you really have to). <\/p>\n<h3>Fault Contract<\/h3>\n<p>Fault Contract <b>provides documented view for error accorded in the service to client<\/b>. This help as to easy identity the what error has occurred, and where. By default when we throw any exception from service, it will not reach the client side. The less the client knows about what happened on the server side, the more dissociated the interaction will be, this phenomenon (not allowing the actual cause of error to reach client). is known as error masking. By default all exceptions thrown on the service side always reach the client as <strong>FaultException,<\/strong> as by having all service exceptions indistinguishable from one another, WCF decouples the client from service. <\/p>\n<p>While the default policy of error-masking is best practice of WCF, but there are times when <strong>client is required to respond to these exceptions in a prescribed and meaningful way<\/strong>. WCF provides the option to handle and convey the error message to client from service using <strong>SOAP Fault <\/strong>contract<strong>.&#160; SOAP <\/strong>faults are based on industry standard that is independent of any technology specific exceptions, it is a way to map technology specific exceptions to some neutral error information. So when service meets as unexpected error, instead of throwing a raw CLR exception (technology specific), service can throw an instance of the <strong>FaultException &lt;T&gt;<\/strong> class.&#160;&#160;&#160;&#160; <\/p>\n<h3>Using the code<\/h3>\n<p>This article has been divided into 4 modules: <\/p>\n<ul>\n<li><strong>WCF Service Library (<em>ContractLib.dll<\/em>)<\/strong>: Actual Service logic, which defines and implements the service, and exposes few functions to the world to use them <\/li>\n<li><strong>Console based Host Application to host the WCF Service Library (ContractLibHost.exe<\/strong>): Host the WCF library <\/li>\n<li><strong>Console Client Application (Contract<em>Client.exe<\/em>):<\/strong> Client Application which will use this service <\/li>\n<li><strong>Web Client&#160; (ContractWebClient)<\/strong> Web site which will use this service <\/li>\n<\/ul>\n<h3>First Module: WCF Service Library (ContractLib.dll) <\/h3>\n<p>To create this project, you can simply take a &quot;<strong>Class Library&quot; <\/strong>project, while choosing from project wizard option. let&#8217;s name it &quot;<code><strong>ContractLib<\/strong><\/code>&quot;, it is the actual service which implements the business logic. The project already contains a file <em>Class1.cs<\/em>, let us do some house keeping, before we write any code for the service library&#160;&#160; <\/p>\n<h4>Little House Keeping<\/h4>\n<ul>\n<li>Delete the file<strong> <\/strong><em>Class1.cs<\/em> from the project workspace. <\/li>\n<li>Add a new <strong>Interface<\/strong> named <code><font size=\"2\"><strong>ICuboidService<\/strong><\/font><\/code> to the project, a new file <em><code><strong><font size=\"2\">ICuboidService.cs<\/font><\/strong><\/code><\/em> will be added to the project. <\/li>\n<li>Add a new <strong>Class<\/strong> named <code><font size=\"2\"><strong>CuboidService<\/strong><\/font><\/code>, to the project. that will implement the <code><font size=\"2\"><strong>ICuboidService<\/strong><\/font><\/code> interface, a new file <strong><font face=\"Courier New\"><code><font size=\"2\">CuboidService.<\/font><\/code><\/font><em>cs<\/em><\/strong> will be added to the project. <\/li>\n<\/ul>\n<h4>Defining Service Interface &#8211; Data Contract(s) <\/h4>\n<h5>Definition of CuboidFaulltException<\/h5>\n<p><font color=\"#0000ff\"><font face=\"Courier New\"><strong>[DataContract]          <br \/><\/strong>public class CuboidFaultException         <br \/>{         <br \/>&#160;&#160;&#160;&#160;&#160; private string _reason;         <br \/>&#160;&#160;&#160;&#160;&#160; private string _source;         <br \/>&#160;&#160;&#160;&#160;&#160; private string _detail;         <br \/>&#160;&#160;&#160;&#160;&#160; private string _helpLink;<\/font><\/font><\/p>\n<p><font color=\"#0000ff\"><font face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160; [DataMember]          <br \/><\/strong>&#160;&#160;&#160;&#160;&#160; public string Reason         <br \/>&#160;&#160;&#160;&#160;&#160; {         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; get { return _reason; }         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; set { _reason = value; }         <br \/>&#160;&#160;&#160;&#160;&#160; }<\/font><\/font><\/p>\n<p><font color=\"#0000ff\"><font face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160; [DataMember]<\/strong>         <br \/>&#160;&#160;&#160;&#160;&#160; public string Source         <br \/>&#160;&#160;&#160;&#160;&#160; {         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; get { return _source; }         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; set { _source = value; }         <br \/>&#160;&#160;&#160;&#160;&#160; }<\/font><\/font><\/p>\n<p><font color=\"#0000ff\"><font face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160; [DataMember]          <br \/><\/strong>&#160;&#160;&#160;&#160;&#160; public string Detail         <br \/>&#160;&#160;&#160;&#160;&#160; {         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; get { return _detail; }         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; set { _detail = value; }         <br \/>&#160;&#160;&#160;&#160;&#160; }<\/font><\/font><\/p>\n<p> <font color=\"#0000ff\"><font face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160; [DataMember]        <br \/><\/strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public string HelpLink       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; get { return _helpLink; }       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; set { _helpLink = value; }       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<\/font><\/font>   <\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">}<\/font><\/p>\n<h6>Explanation<\/h6>\n<p>This <strong>DataContract<\/strong> defines the data the data to be exchanged when a <strong>CuboidFaultException <\/strong>is thrown from service. As the service is also implementing Fault contract, this information is sent to client from the service. I have defined 4 fields, to send the error information to the client, you can define more fields you you need to to send some other contextual information to client. <\/p>\n<p><strong>Reason: <\/strong>The actual cause of the exception, why the service has thrown an <strong>CuboidFaultException<\/strong>.<\/p>\n<p><strong>Source : <\/strong>The source information, which has thrown the exception, in this field you can Send the name of the function, or line number where exception occurred, or what ever information you think will fit as source field of the error.<\/p>\n<p><strong>Detail:<\/strong> here you can pack the information regarding, the actual detail of the error.&#160;&#160;&#160;&#160;&#160; <\/p>\n<p><strong>HelpLink:<\/strong> a web link about the documentation about this kind of error, any thing which you can think can be a help.<\/p>\n<h5>Definition of CuboidDimension<\/h5>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160; <strong>[DataContract]<\/strong>       <br \/>&#160; public class <strong>CuboidDimension<\/strong>       <br \/>&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160; [DataMember]&#160;&#160;&#160; public int Length;       <br \/>&#160;&#160;&#160;&#160;&#160; [DataMember]&#160;&#160;&#160; public int Width;       <br \/>&#160;&#160;&#160;&#160;&#160; [DataMember]&#160;&#160;&#160; public int Height;       <br \/>&#160; }<\/font><\/p>\n<h6>Explanation<\/h6>\n<p>This Data contract simply defines the 3 dimensions of a cuboid, which is length, width and height.<\/p>\n<h5>Definition of CuboidInfo<\/h5>\n<p><strong>&#160;<\/strong><font color=\"#0000ff\" face=\"Courier New\"><strong> [DataContract]<\/strong>       <br \/>&#160; public class <strong>CuboidInfo<\/strong>       <br \/>&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160; [DataMember] public int ID;       <br \/>&#160;&#160;&#160;&#160;&#160; [DataMember] public <strong>CuboidDimension<\/strong> Dimension = new <strong>CuboidDimension<\/strong>();       <br \/>&#160; }<\/font><\/p>\n<h6>Explanation<\/h6>\n<p>This Data contract simply defines a class which contains two fields, first field is the ID of the Cuboid and second field is an object of <strong>CuboidDimension <\/strong>class, which was defined previously, that contains the dimensions (length, width and height) of the cuboid.&#160; <\/p>\n<h5>Definition of CuboidDetail<\/h5>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160; [DataContract]<\/strong>       <br \/>&#160; public class <strong>CuboidDetail<\/strong>       <br \/>&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160; [DataMember]&#160;&#160;&#160;&#160;&#160;&#160;&#160; public int ID;       <br \/>&#160;&#160;&#160;&#160;&#160; [DataMember]&#160;&#160;&#160;&#160;&#160;&#160;&#160; public double SurfaceArea;       <br \/>&#160;&#160;&#160;&#160;&#160; [DataMember]&#160;&#160;&#160;&#160;&#160;&#160;&#160; public double Volume;       <br \/>&#160; }<\/font><\/p>\n<h6>Explanation<\/h6>\n<p>This Data contract simply defines a class which contains 3&#160; fields, first field is the ID of the Cuboid and second field is a double, that will hold the value of surface area of the Cuboid, and the 3rd field is a double that will contain the Volume of the cuboid.&#160; <\/p>\n<h4>Defining Service Interface &#8211; Message Contract<\/h4>\n<h5>Defining CuboidInfoRequest<\/h5>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160; <strong>[MessageContract]<\/strong>       <br \/>&#160; public class CuboidInfoRequest       <br \/>&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160; private int m_nID ;       <br \/>&#160;&#160;&#160;&#160;&#160; private CuboidDimension m_Dims = new CuboidDimension();<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160; <\/font><font face=\"Courier New\"><font color=\"#0000ff\"><strong>&#160; [MessageHeader]          <br \/><\/strong>&#160;&#160;&#160;&#160;&#160; public int ID         <br \/>&#160;&#160;&#160;&#160;&#160; {         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; get { return m_nID; }         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; set { m_nID = value; }         <br \/>&#160;&#160;&#160;&#160;&#160; }<\/font><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160; <strong>&#160; [MessageBodyMember]<\/strong>       <br \/>&#160;&#160;&#160;&#160;&#160; public CuboidDimension Dimension       <br \/>&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; get { return m_Dims; }       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; set { m_Dims = value; }       <br \/>&#160;&#160;&#160;&#160;&#160; }       <br \/>&#160; }<\/font><\/p>\n<h6>Explanation<\/h6>\n<p>This Message contract simply defines a class which contains two fields, first field is the ID of the Cuboid, which has been defined as Message Header. In the message body contains a single member <strong>CuboidDimension<\/strong>, that is details (dimensions) of the cuboid. <\/p>\n<h5>Defining CuboidDetailResponse<\/h5>\n<p>&#160; <font color=\"#0000ff\" face=\"Courier New\">[MessageContract]      <br \/>&#160; public class CuboidDetailResponse       <br \/>&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160; private int m_nID;       <br \/>&#160;&#160;&#160;&#160;&#160; private double m_dblArea;       <br \/>&#160;&#160;&#160;&#160;&#160; private double m_dblVolume;<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160; [MessageHeader]      <br \/>&#160;&#160;&#160;&#160;&#160; public int ID       <br \/>&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; get { return m_nID; }       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; set { m_nID = value; }       <br \/>&#160;&#160;&#160;&#160;&#160; }<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160; [MessageBodyMember]      <br \/>&#160;&#160;&#160;&#160;&#160; public double SurfaceArea       <br \/>&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; get { return m_dblArea ; }       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; set { m_dblArea = value ; }       <br \/>&#160;&#160;&#160;&#160;&#160; }<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160; [MessageBodyMember]      <br \/>&#160;&#160;&#160;&#160;&#160; public double Volume       <br \/>&#160;&#160;&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; get { return m_dblVolume; }       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; set { m_dblVolume = value; }       <br \/>&#160;&#160;&#160;&#160;&#160; }       <br \/>&#160; }<\/font><\/p>\n<h6>Explanation<\/h6>\n<p>This Message contract defines a class which contains 3&#160; fields, ID of the cuboid has been defined as Message Header. Message body contains a two members, that is the <strong>Volume <\/strong>and<strong> Area <\/strong>of the Cuboid.     <\/p>\n<h4>Defining Service Interface &#8211; Service Contract, Operation Contract, Fault Contract<\/h4>\n<h5>Defining ServiceContract ICuboidService <\/h5>\n<p><font color=\"#0000ff\"><strong>[ServiceContract]        <br \/><\/strong>interface ICuboidService       <br \/>{       <br \/>&#160;&#160;&#160; <strong>[OperationContract]        <br \/><\/strong>&#160;&#160;&#160; [<strong>FaultContract<\/strong>(typeof(<strong>CuboidFaultException<\/strong>))]       <br \/>&#160;&#160;&#160; CuboidDetailResponse CalculateDetails1(CuboidInfoRequest cInfo);       <br \/>&#160;&#160;&#160; <br \/>&#160;&#160;&#160; <strong>[OperationContract]        <br \/><\/strong>&#160;&#160;&#160; [<strong>FaultContract<\/strong>(typeof(<strong>CuboidFaultException<\/strong>))]       <br \/>&#160;&#160;&#160; CuboidDetail CalculateDetails2(CuboidInfo cInfo);       <br \/>}<\/font><\/p>\n<h6>Explanation<\/h6>\n<p>Service defines two methods as Exposed Operation(s) of the service. <\/p>\n<p>The first method <strong><font color=\"#0000ff\">CalculateDetails1<\/font><\/strong> of the service takes a Message Contract type <strong><font color=\"#0000ff\">CuboidInfoRequest<\/font><\/strong>&#160; as an input parameter, and returns a Message Contract type <strong><font color=\"#0000ff\">CuboidDetailResponse<\/font><\/strong> , abiding by the rules.<\/p>\n<ol>\n<ol>\n<li>When using Message contract type as parameter, Only <strong>one parameter can be used in Operation<\/strong>. <\/li>\n<li>Service operation either <strong>should return MessageContract<\/strong> type <strong>or<\/strong> it <strong>should not return any value<\/strong>. <\/li>\n<li>Operation will <strong>accept and return only message contract type<\/strong>. Other data types are not allowed. <\/li>\n<\/ol>\n<\/ol>\n<p>implements a <strong><font color=\"#0000ff\">FaultContract<\/font><\/strong>, which raises <strong><font color=\"#0000ff\">CuboidFaultException<\/font>, <\/strong>if there is something not the way, as it supposed to be.<\/p>\n<p>The second method <strong><font color=\"#0000ff\">CalculateDetails2<\/font><\/strong> of the service takes a Data Contract type <strong><font color=\"#0000ff\">CuboidInfo<\/font><\/strong>&#160; as an input parameter, and returns a Data Contract type <font color=\"#0000ff\"><strong>CuboidDetail.<\/strong><\/font> although method takes only one parameter. <\/p>\n<p>implements a <strong><font color=\"#0000ff\">FaultContract<\/font><\/strong>, which raises <strong><font color=\"#0000ff\">CuboidFaultException<\/font>, <\/strong>if there is something not the way, as it supposed to be.<\/p>\n<h4>Implementing Service Interface <\/h4>\n<h5>Implementing method CalculateDetails1<\/h5>\n<p><font color=\"#0000ff\" face=\"Courier New\">public CuboidDetailResponse CalculateDetails1(CuboidInfoRequest cInfo)      <br \/>{       <br \/>&#160;&#160;&#160; if ((cInfo.Dimension.Length&lt;=0)||(cInfo.Dimension.Width&lt;=0)||(cInfo.Dimension.Height &lt;= 0))       <br \/>&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; CuboidFaultException faultEx = new CuboidFaultException ();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; faultEx.Reason = &quot;Any dimension of Cuboid (length\/width\/height) can not be zero or negative value&quot;;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; faultEx.Source = &quot;CalculateDetails1()&quot;;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; faultEx.HelpLink = &quot;<\/font><a href=\"http:\/\/praveenkatiyar.wordpress.com&quot;;\"><font color=\"#0000ff\" face=\"Courier New\">http:\/\/praveenkatiyar.wordpress.com&quot;;<\/font><\/a>     <br \/><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160; StringBuilder sbDetail = new StringBuilder (&quot;&quot;);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (cInfo.Dimension.Length &lt;= 0) sbDetail.Append ( &quot;[Length is &lt;= 0] &quot;);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (cInfo.Dimension.Width &lt;= 0) sbDetail.Append ( &quot;[Width is &lt;= 0] &quot;);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (cInfo.Dimension.Height &lt;= 0) sbDetail.Append ( &quot;[Height is &lt;= 0]&quot;) ;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; faultEx.Detail = sbDetail.ToString();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw new FaultException&lt;CuboidFaultException&gt;(faultEx);       <br \/>&#160;&#160;&#160; }<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160; CuboidDetailResponse dInfo = new CuboidDetailResponse();      <br \/>&#160;&#160;&#160; dInfo.ID = cInfo.ID ;       <br \/>&#160;&#160;&#160; dInfo.Volume = (cInfo.Dimension.Length * cInfo.Dimension.Width * cInfo.Dimension.Height);       <br \/>&#160;&#160;&#160; dInfo.SurfaceArea = 2 * ( (cInfo.Dimension.Length * cInfo.Dimension.Width) +&#160; <\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (cInfo.Dimension.Width * cInfo.Dimension.Height) +&#160; <\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (cInfo.Dimension.Length * cInfo.Dimension.Height ));      <br \/>&#160;&#160;&#160; return dInfo;       <br \/>}<\/font><\/p>\n<h6>Explanation<\/h6>\n<p>Operation takes a MessageContrat (<strong><font color=\"#0000ff\">CuboidInfoRequest<\/font><\/strong>) type parameter, checks whether the attributes (length, width, height) of the cuboid is not zero or negative. if yes then simply creates and raises a <strong><font color=\"#0000ff\">FaultException<\/font><\/strong> of type <strong><font color=\"#0000ff\">CuboidFaultExeception<\/font><\/strong>, assigning the values for the field of <strong><font color=\"#0000ff\">CuboidFaultExeception<\/font><\/strong>.<\/p>\n<p>and if everything is in place, calculates the desired values, creates a new <strong>MessageContract <\/strong>object <strong>(<\/strong><strong>CuboidDetailResponse)<\/strong> and assigns its field and returns that object.<\/p>\n<h5>Implementing method CalculateDetails2<\/h5>\n<p><font color=\"#0000ff\" face=\"Courier New\">public CuboidDetail CalculateDetails2(CuboidInfo cInfo)      <br \/>{       <br \/>&#160;&#160;&#160; if ((cInfo.Dimension.Length&lt;=0)||(cInfo.Dimension.Width&lt;=0)||(cInfo.Dimension.Height &lt;= 0))       <br \/>&#160;&#160;&#160; {       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; CuboidFaultException faultEx = new CuboidFaultException ();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; faultEx.Reason = &quot;Any dimension of Cuboid (length\/width\/height) can not be zero or negative value&quot;;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; faultEx.Source = &quot;CalculateDetails2()&quot;;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; faultEx.HelpLink = &quot;<\/font><a href=\"http:\/\/praveenkatiyar.wordpress.com&quot;;\"><font color=\"#0000ff\" face=\"Courier New\">http:\/\/praveenkatiyar.wordpress.com&quot;;<\/font><\/a>     <br \/><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160; StringBuilder sbDetail = new StringBuilder (&quot;&quot;);      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (cInfo.Dimension.Length &lt;= 0) sbDetail.Append ( &quot;[Length is &lt;= 0] &quot;);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (cInfo.Dimension.Width &lt;= 0) sbDetail.Append ( &quot;[Width is &lt;= 0] &quot;);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (cInfo.Dimension.Height &lt;= 0) sbDetail.Append ( &quot;[Height is &lt;= 0]&quot;) ;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; faultEx.Detail = sbDetail.ToString();       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw new FaultException&lt;CuboidFaultException&gt;(faultEx);       <br \/>&#160;&#160;&#160; }<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160; CuboidDetail dInfo = new CuboidDetail();      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dInfo.ID = cInfo.ID;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dInfo.Volume = (cInfo.Dimension.Length * cInfo.Dimension.Width * cInfo.Dimension.Height);       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dInfo.SurfaceArea = 2 * ((cInfo.Dimension.Length * cInfo.Dimension.Width) +&#160;&#160;&#160;&#160; <\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#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; (cInfo.Dimension.Width * cInfo.Dimension.Height) +&#160; <\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (cInfo.Dimension.Length * cInfo.Dimension.Height));      <br \/><\/font><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160; return dInfo;      <br \/>}<\/font><\/p>\n<h6>Explanation<\/h6>\n<p>Operation takes a DataContrat (<strong><font color=\"#0000ff\">CuboidInfo<\/font><\/strong>) type parameter, checks whether the attributes (length, width, height) of the cuboid is not zero or negative. if yes then simply creates and raises a <strong><font color=\"#0000ff\">FaultException<\/font><\/strong> of type <strong><font color=\"#0000ff\">CuboidFaultExeception<\/font><\/strong>, assigning the values for the field of <strong><font color=\"#0000ff\">CuboidFaultExeception<\/font><\/strong>. <\/p>\n<p>and if everything is in place, calculates the desired values, creates a new <strong>DataContract <\/strong>object <strong>(<\/strong><strong>CuboidDetail)<\/strong> and assigns its field and returns that object.<\/p>\n<p>build the project (library), this complete the first module<\/p>\n<h3>Second Module: Application to Host the WCF Service Library (ContractLibHost.exe) <\/h3>\n<p>To create this project, you can simply take a &quot;<strong>Console Application&quot; <\/strong>project, while choosing from project wizard option. let\u2019s name it &quot;<code><strong>ContractLibHost<\/strong><\/code>&quot;, this application will self host the service. let us do some house keeping, before we write any code for the host application. <\/p>\n<h4>Adding application configuration<\/h4>\n<ul>\n<li>Add an <strong>Application configuration (App.config)<\/strong> file to the project. <\/li>\n<\/ul>\n<h4>Defining configuration<\/h4>\n<p>before we write any code for the host, let\u2019s define the configuration.<\/p>\n<h4>Assumption<\/h4>\n<p>The Host application will expose the following endpoints for the service.<\/p>\n<ul>\n<li>CuboidService will expose <strong>HTTP endpoint at Port 9011<\/strong> <\/li>\n<li>Corresponding <strong>mex <\/strong>End Point <strong>(IMetadatExchange)<\/strong> for the HTTP end point. <\/li>\n<\/ul>\n<h5>Defining configuration for <strong>CuboidService<\/strong><\/h5>\n<h5>Defining Endpoints<\/h5>\n<p><font color=\"#0000ff\">&lt;service name=&quot;<strong>ContractLib<\/strong>.<strong>CuboidService<\/strong>&quot; behaviorConfiguration=&quot;<strong>CuboidServiceBehavior<\/strong>&quot;&gt;<\/font><\/p>\n<p><font color=\"#0000ff\">&#160;&#160;&#160;&#160;&#160; &lt;host&gt;      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;baseAddresses&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;add baseAddress=&quot;<strong>http:\/\/localhost:9011\/CuboidService<\/strong>&quot;\/&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/baseAddresses&gt;       <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/host&gt;<\/font><\/p>\n<p><font color=\"#0000ff\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;<strong>endpoint <\/strong>address=&quot;<strong>http:\/\/localhost:9011\/CuboidService<\/strong>&quot; binding=&quot;<strong>wsHttpBinding<\/strong>&quot; contract=&quot;<strong>ContractLib.ICuboidService<\/strong>&quot;\/&gt;       <br \/>&#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; &lt;\/service&gt;<\/font><\/p>\n<h6>Explanation<\/h6>\n<p>The service defines, one <strong>endpoint<\/strong> with <strong>wsHttpBinding<\/strong>,&#160; another endpoint is defined as <strong>mex<\/strong>, are defined for publication of metadata, <strong>IMetadataExchange<\/strong> is standard contract for <strong>mex<\/strong> endpoints.<\/p>\n<ul><\/ul>\n<h5>Defining Behavior<\/h5>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&lt;behaviors&gt;        <br \/>&#160;&#160;&#160;&#160; &lt;serviceBehaviors&gt;         <br \/>&#160;&#160;&#160;&#160;&#160;&#160; &lt;!&#8211; CalcService Behavior &#8211;&gt;         <br \/>&#160;&#160;&#160;&#160;&#160;&#160; &lt;behavior name=&quot;CuboidServiceBehavior&quot;&gt;         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;serviceMetadata httpGetEnabled=&quot;true&quot;\/&gt;         <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;serviceDebug includeExceptionDetailInFaults=&quot;true &quot;\/&gt;         <br \/>&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/behavior&gt;         <br \/>&#160;&#160;&#160;&#160; &lt;\/serviceBehaviors&gt;         <br \/>&lt;\/behaviors&gt;<\/strong><\/font><\/p>\n<h6>Explanation<\/h6>\n<p>service behaviour defines two attributes,&#160;&#160; <\/p>\n<pre><strong><font color=\"#0000ff\">&lt;serviceMetadata httpGetEnabled=&quot;true&quot; \/&gt;<\/font> <\/strong><\/pre>\n<p>Gets or sets a value that indicates whether to publich service medtadata for retrieval using an HTTP\/GET request, true means yes, metadata is available for retrieval using a HTTP\/GET request.<\/p>\n<pre><strong><font color=\"#0000ff\">&lt;serviceDebug includeExceptionDetailInFaults=&quot;true &quot;\/&gt;<\/font><\/strong><\/pre>\n<p>Set <strong><code><font color=\"#0000ff\">IncludeExceptionDetailsInFaults<\/font><\/code> <\/strong>to <code>true<\/code><strong> <\/strong>to enable clients to obtain information about internal service method exceptions; it is only recommended as a way of temporarily debugging a service application. this property <strong>must be set to false on production servers<\/strong>. <\/p>\n<h4>Hosting Service<\/h4>\n<p>As we have defined the configuration for service, before we write any code <\/p>\n<ul>\n<li>add reference of <strong>System.ServiceModel<\/strong> to the project. <\/li>\n<\/ul>\n<p>Let\u2019s write code to host the service.<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">\/\/ Listing of Program.cs<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">using System;<br \/>\n    <br \/>using System.ServiceModel; <\/p>\n<p>using System.Text;<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">namespace ContractLibHost<br \/>\n    <br \/>{ <\/p>\n<p>&#160;&#160;&#160; class Program <\/p>\n<p>&#160;&#160;&#160; { <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; static void Main(string[] args) <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; { <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ServiceHost host = new ServiceHost(typeof(ContractLib.CuboidService)); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; host.Open(); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Service is Hosted as <\/font><a href=\"http:\/\/localhost:9011\/CuboidService&quot;);\"><font color=\"#0000ff\" face=\"Courier New\">http:\/\/localhost:9011\/CuboidService&quot;);<\/font><\/a> <\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\nPress&#160; key to stop the service.&quot;);<br \/>\n    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.ReadKey(); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; host.Close(); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; catch (Exception eX) <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;There was en error while Hosting Service [&quot; + eX.Message + &quot;]&quot;); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\nPress&#160; key to close.&quot;); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.ReadKey(); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } <\/p>\n<p>&#160;&#160;&#160; } <\/p>\n<p>}<\/font><\/p>\n<h6>Explanation<\/h6>\n<p><code><\/code>ServiceHost class provides a host for services. <\/p>\n<p>Build and Execute the Host.<\/p>\n<p>Open a command prompt in administrator mode and execute the host. here is the output. <\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image9.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border-width:0;\" border=\"0\" alt=\"image\" src=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image_thumb9.png\" width=\"667\" height=\"70\" \/><\/a><\/p>\n<h3>Creating Client (ContractClient.exe)<\/h3>\n<h4>Creating the base project <\/h4>\n<p>Take a console based application. name it <strong>ContractClient<\/strong>.<\/p>\n<h4>Generating proxies <\/h4>\n<p>while the host application is running, right click on the client application project, click on <\/p>\n<p><strong>References \u2013&gt; Add Service Reference<\/strong> <\/p>\n<p>in the address bar type the address of the <strong>mex<\/strong> endpoint address of <strong>CuboidService<\/strong> as shown below.<\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/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\/10\/image_thumb10.png\" width=\"586\" height=\"389\" \/><\/a><\/p>\n<p>this will <\/p>\n<ul>\n<li>Add <strong>Service References<\/strong> Node in the project workspace, and add an item <strong>CuboidServiceReference <\/strong>in that node. <\/li>\n<li>add <strong>app.config<\/strong> files to your client project. <\/li>\n<\/ul>\n<p>before we write any code, let&#8217;s examine the app.config file.<\/p>\n<pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;\n&lt;configuration&gt;\n    &lt;system.serviceModel&gt;\n        <strong>&lt;bindings&gt;\n\t\t. . . .\n        &lt;\/bindings&gt;<\/strong>\n        <strong>&lt;client&gt;\n\t\t. . . .\n        &lt;\/client&gt;<\/strong>\n    &lt;\/system.serviceModel&gt;\n&lt;\/configuration&gt;<\/pre>\n<p>&#160;<\/p>\n<p>The binding section holds the collection of standard and custom bindings. Each entry is a binding element that can be identified by its unique name. <\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&lt;bindings&gt;<br \/>\n    <br \/>&#160;&#160;&#160; &lt;wsHttpBinding&gt; <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;binding name=&quot;WSHttpBinding_ICuboidService&quot; \/&gt; <\/p>\n<p>&#160;&#160;&#160; &lt;\/wsHttpBinding&gt; <\/p>\n<p>&lt;\/bindings&gt;<\/font> <\/p>\n<p><\/p>\n<p>The client section contains a list of endpoints a client uses to connect to a service. <\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&lt;client&gt;<br \/>\n    <br \/>&#160;&#160;&#160; &lt;endpoint address=&quot;<\/font><a href=\"http:\/\/localhost:9011\/CuboidService&quot;\"><font color=\"#0000ff\" face=\"Courier New\">http:\/\/localhost:9011\/CuboidService&quot;<\/font><\/a><font color=\"#0000ff\" face=\"Courier New\"> binding=&quot;wsHttpBinding&quot;<br \/>\n    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bindingConfiguration=&quot;WSHttpBinding_ICuboidService&quot; contract=&quot;CuboidServiceReference.ICuboidService&quot; <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; name=&quot;WSHttpBinding_ICuboidService&quot;&gt; <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;identity&gt; <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;userPrincipalName value=&quot;PRAVEEN-WIN7\\BriskTech&quot; \/&gt; <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;\/identity&gt; <\/p>\n<p>&#160;&#160;&#160; &lt;\/endpoint&gt; <\/p>\n<p>&lt;\/client&gt;<\/font> <\/p>\n<p>The client section contains a list of endpoints a client uses to connect to a service. <\/p>\n<p><strong>Note<\/strong>: Identity might be different on your machine. <\/p>\n<p>Calling the service, using the Proxy<\/p>\n<p>Open <em>programs.cs<\/em> file of the client project and write code to use the service, using the generated proxy class, as shown below:<\/p>\n<p>Listing of Client Program (<em>Program.cs<\/em>): <\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">using System;<br \/>\n    <br \/>using System.Text; <\/p>\n<p>using System.ServiceModel ;<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">namespace ContractClient<br \/>\n    <br \/>{ <\/p>\n<p>&#160;&#160;&#160; class Program <\/p>\n<p>&#160;&#160;&#160; { <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; static void Main(string[] args) <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; { <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; int nID = 0; <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; int nLength = 0; <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; int nWidth = 0; <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; int nHeight = 0; <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.Write(&quot;Enter ID : &quot;); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; string strID = Console.ReadLine(); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bool bID = int.TryParse(strID, out nID); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.Write(&quot;Enter Length : &quot;); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; string strLength = Console.ReadLine(); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bool bLength = int.TryParse(strLength, out nLength);<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine();<br \/>\n    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.Write(&quot;Enter Width : &quot;); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; string strWidth = Console.ReadLine(); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bool bWidth = int.TryParse(strWidth, out nWidth); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.Write(&quot;Enter Height : &quot;); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; string strHeight = Console.ReadLine(); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bool bHeight = int.TryParse(strHeight, out nHeight);<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bool bValid = ((bID) &amp;&amp; (bWidth) &amp;&amp; (bLength) &amp;&amp; (bHeight));<br \/>\n    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (bValid) <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CuboidServiceReference.CuboidServiceClient objClient = null; <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; objClient = new CuboidServiceReference.CuboidServiceClient(); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; catch (Exception eX) <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; objClient = null; <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\nFailed while creating Service proxy &#8230;..&quot;); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return; <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } <\/p>\n<p>&#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; Issue Request <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CuboidServiceReference.CuboidInfoRequest msgRequest = new CuboidServiceReference.CuboidInfoRequest(); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; msgRequest. Dimension = new CuboidServiceReference.CuboidDimension();<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; msgRequest.ID = nID;<br \/>\n    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; msgRequest.Dimension.Length = nLength; <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; msgRequest.Dimension.Width = nWidth; <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; msgRequest.Dimension.Height = nHeight;<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\nMessage Request &quot;);<br \/>\n    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Cube ID &#8230;&#8230;&#8230;&#8230;. : {0:D2}&quot;, msgRequest.ID); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Cube Length &#8230;&#8230;&#8230; : {0:F2}&quot;, msgRequest.Dimension.Length); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Cube Width &#8230;&#8230;&#8230;. : {0:F2}&quot;, msgRequest.Dimension.Width); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Cube Height &#8230;&#8230;&#8230; : {0:F2}&quot;, msgRequest.Dimension.Height);<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CuboidServiceReference.CuboidDetailResponse msgResponse = new CuboidServiceReference.CuboidDetailResponse();<br \/>\n    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; msgResponse.SurfaceArea = objClient.CalculateDetails1 ( ref msgRequest.ID, msgRequest.Dimension, out msgResponse.Volume&#160; );<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\nMessage Response&quot;);<br \/>\n    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Total Surface Area .. : {0:F2}&quot;, msgResponse.SurfaceArea); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Total Volume &#8230;&#8230;.. : {0:F2}&quot;, msgResponse.Volume); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; catch (FaultException&lt;CuboidServiceReference.CuboidFaultException&gt; eX) <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\nThere was an error while fetching details . . .&quot;); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Reason &#8230;&#8230;&#8230;&#8230;.. : &quot; + eX.Detail.Reason); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Source &#8230;&#8230;&#8230;&#8230;.. : &quot; + eX.Detail.Source); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Details &#8230;&#8230;&#8230;&#8230;. : &quot; + eX.Detail.Detail); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Help Link &#8230;&#8230;&#8230;.. : &quot; + eX.Detail.HelpLink); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<\/font><\/p>\n<p>\n  <br \/><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \/\/&#160; Issue Request<br \/>\n    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CuboidServiceReference.CuboidInfo dataRequest = new CuboidServiceReference.CuboidInfo(); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dataRequest.Dimension = new CuboidServiceReference.CuboidDimension();<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dataRequest.ID = nID;<br \/>\n    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dataRequest.Dimension.Length = nLength; <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dataRequest.Dimension.Width = nWidth; <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dataRequest.Dimension.Height = nHeight;<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\nData Request &quot;);<br \/>\n    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Cube ID &#8230;&#8230;&#8230;&#8230;. : {0:D2}&quot;, dataRequest.ID); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Cube Length &#8230;&#8230;&#8230; : {0:F2}&quot;, dataRequest.Dimension.Length); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Cube Width &#8230;&#8230;&#8230;. : {0:F2}&quot;, dataRequest.Dimension.Width); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Cube Height &#8230;&#8230;&#8230; : {0:F2}&quot;, dataRequest.Dimension.Height);<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CuboidServiceReference.CuboidDetail dataResponse = new CuboidServiceReference.CuboidDetail();<br \/>\n    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dataResponse = objClient.CalculateDetails2(dataRequest);<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\nData Response&quot;);<br \/>\n    <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Total Surface Area .. : {0:F2}&quot;, dataResponse.SurfaceArea); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Total Volume &#8230;&#8230;.. : {0:F2}&quot;, dataResponse.Volume); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; catch (FaultException&lt;CuboidServiceReference.CuboidFaultException&gt; eX) <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\nThere was an error while fetching details . . .&quot;); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Reason &#8230;&#8230;&#8230;&#8230;.. : &quot; + eX.Detail.Reason); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Source &#8230;&#8230;&#8230;&#8230;.. : &quot; + eX.Detail.Source); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Details &#8230;&#8230;&#8230;&#8230;. : &quot; + eX.Detail.Detail); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;Help Link &#8230;&#8230;&#8230;.. : &quot; + eX.Detail.HelpLink); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; else <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (bID == false) Console.WriteLine(&quot;ID should be a positive&#160; numeric value&quot;); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (bLength == false) Console.WriteLine(&quot;Length should be a positive numeric value&quot;); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (bWidth == false) Console.WriteLine(&quot;Width should be a positive numeric value&quot;); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (bHeight == false) Console.WriteLine(&quot;Height should be a positive numeric value&quot;); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.WriteLine(&quot;\\nPress any key to close . . . &quot;); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Console.ReadKey(); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } <\/p>\n<p>&#160;&#160;&#160; } <\/p>\n<p>}<\/font> <\/p>\n<p><\/p>\n<h5>Explanation <\/h5>\n<p>Creates the proxy object for the service<\/p>\n<p><strong><font color=\"#0000ff\" face=\"Courier New\">CuboidServiceReference.CuboidInfoRequest msgRequest = new CuboidServiceReference.CuboidInfoRequest();<\/font><\/strong><\/p>\n<p>Prompt user to enter the ID and dimensions of the cuboid in interactive way, and validate, that he has entered a numeric value as well. <\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">Console.Write(&quot;Enter ID : &quot;);<br \/>\n    <br \/>string strID = Console.ReadLine(); <\/p>\n<p>bool bID = int.TryParse(strID, out nID); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/>Console.WriteLine(); <\/p>\n<p>Console.Write(&quot;Enter Length : &quot;); <\/p>\n<p>string strLength = Console.ReadLine(); <\/p>\n<p>bool bLength = int.TryParse(strLength, out nLength);<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">Console.WriteLine();<br \/>\n    <br \/>Console.Write(&quot;Enter Width : &quot;); <\/p>\n<p>string strWidth = Console.ReadLine(); <\/p>\n<p>bool bWidth = int.TryParse(strWidth, out nWidth); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/>Console.WriteLine(); <\/p>\n<p>Console.Write(&quot;Enter Height : &quot;); <\/p>\n<p>string strHeight = Console.ReadLine(); <\/p>\n<p>bool bHeight = int.TryParse(strHeight, out nHeight);<\/font><\/p>\n<p>check if all values are numeric, (0 and negative values are allowed).<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">bool bValid = ((bID) &amp;&amp; (bWidth) &amp;&amp; (bLength) &amp;&amp; (bHeight));<\/font><\/p>\n<p>Create a proxy object for the service.<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">CuboidServiceReference.CuboidServiceClient objClient = null;<br \/>\n    <br \/>try <\/p>\n<p>{ <\/p>\n<p>&#160;&#160;&#160; objClient = new CuboidServiceReference.CuboidServiceClient(); <\/p>\n<p>} <\/p>\n<p>catch (Exception eX) <\/p>\n<p>{ <\/p>\n<p>&#160;&#160;&#160; objClient = null; <\/p>\n<p>&#160;&#160;&#160; Console.WriteLine(&quot;\\nFailed while creating Service proxy &#8230;..&quot;); <\/p>\n<p>&#160;&#160;&#160; return; <\/p>\n<p>}<\/font><\/p>\n<p>if object has been created successfully. <\/p>\n<p>put everything inside a try block .<br \/>\n  <br \/><font color=\"#0000ff\" face=\"Courier New\">try<br \/>\n    <br \/>{ <\/font><\/p>\n<p>C<font color=\"#0000ff\" face=\"Courier New\"><font color=\"#333333\" face=\"Tahoma\">reate&#160; Request Message <\/font><\/p>\n<p>CuboidServiceReference.CuboidInfoRequest msgRequest=new CuboidServiceReference.CuboidInfoRequest();&#160; <br \/><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><\/font><\/p>\n<p>Create a dimension data (Width, Length, and Height <\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">msgRequest. Dimension = new CuboidServiceReference.CuboidDimension();<\/font><\/p>\n<p>Assign values message request,&#160; or prepare input message to be sent.<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">msgRequest.ID = nID;&#160; <br \/>msgRequest.Dimension.Length = nLength;&#160; <br \/>msgRequest.Dimension.Width = nWidth;&#160; <br \/>msgRequest.Dimension.Height = nHeight;<\/font><\/p>\n<p>Display what is being sent.<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">Console.WriteLine(&quot;\\nMessage Request &quot;);<br \/>\n    <br \/>Console.WriteLine(&quot;Cube ID &#8230;&#8230;&#8230;&#8230;. : {0:D2}&quot;, msgRequest.ID); <\/p>\n<p>Console.WriteLine(&quot;Cube Length &#8230;&#8230;&#8230; : {0:F2}&quot;, msgRequest.Dimension.Length); <\/p>\n<p>Console.WriteLine(&quot;Cube Width &#8230;&#8230;&#8230;. : {0:F2}&quot;, msgRequest.Dimension.Width); <\/p>\n<p>Console.WriteLine(&quot;Cube Height &#8230;&#8230;&#8230; : {0:F2}&quot;, msgRequest.Dimension.Height);<\/font><\/p>\n<p>Create a Response object to hold the returned reponse from service. <\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><\/font><font color=\"#0000ff\" face=\"Courier New\">CuboidServiceReference.CuboidDetailResponse msgResponse=new CuboidServiceReference.CuboidDetailResponse(); <\/font><\/p>\n<p>Call the service, with the message request, and collect the message response.&#160; <\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">msgResponse.SurfaceArea = objClient.CalculateDetails1 ( ref msgRequest.ID, msgRequest.Dimension, out&#160;&#160; msgResponse.Volume&#160; );<\/font><\/p>\n<p>Display output.<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">Console.WriteLine(&quot;\\nMessage Response&quot;);<br \/>\n    <br \/>Console.WriteLine(&quot;Total Surface Area .. : {0:F2}&quot;, msgResponse.SurfaceArea); <\/p>\n<p>Console.WriteLine(&quot;Total Volume &#8230;&#8230;.. : {0:F2}&quot;, msgResponse.Volume); <\/p>\n<p>} <\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><font color=\"#333333\" face=\"Tahoma\">Something went wrong, catch the <strong>CuboidFaultExcepton<\/strong><\/font><\/p>\n<p>catch (FaultException&lt;CuboidServiceReference.CuboidFaultException&gt; eX) <\/p>\n<p>{ <\/font><\/p>\n<p>Display the custom values returned by implemented FaultContract from the service,<font color=\"#0000ff\" face=\"Courier New\"><font color=\"#333333\" face=\"Tahoma\"> why service has thrown CuboidFaultException. <\/font><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&#160;&#160;&#160; Console.WriteLine(&quot;\\nThere was an error while fetching details . . .&quot;);<br \/>\n    <br \/>&#160;&#160;&#160; Console.WriteLine(&quot;Reason &#8230;&#8230;&#8230;&#8230;.. : &quot; + eX.Detail.Reason); <\/p>\n<p>&#160;&#160;&#160; Console.WriteLine(&quot;Source &#8230;&#8230;&#8230;&#8230;.. : &quot; + eX.Detail.Source); <\/p>\n<p>&#160;&#160;&#160; Console.WriteLine(&quot;Details &#8230;&#8230;&#8230;&#8230;. : &quot; + eX.Detail.Detail); <\/p>\n<p>&#160;&#160;&#160; Console.WriteLine(&quot;Help Link &#8230;&#8230;&#8230;.. : &quot; + eX.Detail.HelpLink); <\/p>\n<p>}<\/font><\/p>\n<p>Call Service again, this time with the object of Data Contract<\/p>\n<p>\/\/&#160; Issue Request<br \/>\n  <br \/>try<\/p>\n<p>{<\/p>\n<p>Create the object for data to be sent to the service.<br \/>\n  <br \/><font color=\"#0000ff\" face=\"Courier New\">CuboidServiceReference.CuboidInfo dataRequest = new CuboidServiceReference.CuboidInfo();<br \/>\n    <br \/>dataRequest.Dimension = new CuboidServiceReference.CuboidDimension();<\/font><\/p>\n<p>Assign values. <\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">dataRequest.ID = nID;<br \/>\n    <br \/>dataRequest.Dimension.Length = nLength;<\/p>\n<p>dataRequest.Dimension.Width = nWidth;<\/p>\n<p>dataRequest.Dimension.Height = nHeight;<\/font><\/p>\n<p>Display what is being sent.<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">Console.WriteLine(&quot;\\nData Request &quot;);<br \/>\n    <br \/>Console.WriteLine(&quot;Cube ID &#8230;&#8230;&#8230;&#8230;. : {0:D2}&quot;, dataRequest.ID);<\/p>\n<p>Console.WriteLine(&quot;Cube Length &#8230;&#8230;&#8230; : {0:F2}&quot;, dataRequest.Dimension.Length);<\/p>\n<p>Console.WriteLine(&quot;Cube Width &#8230;&#8230;&#8230;. : {0:F2}&quot;, dataRequest.Dimension.Width);<\/p>\n<p>Console.WriteLine(&quot;Cube Height &#8230;&#8230;&#8230; : {0:F2}&quot;, dataRequest.Dimension.Height);<\/font><\/p>\n<p>Create object which will hold the returned value.<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">CuboidServiceReference.CuboidDetail dataResponse = new CuboidServiceReference.CuboidDetail();<\/font><\/p>\n<p>Call the service and save the returned value.<br \/>\n  <br \/><font color=\"#0000ff\" face=\"Courier New\">dataResponse = objClient.CalculateDetails2(dataRequest);<\/font><\/p>\n<p>Display output, the values inside, returned object <\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">Console.WriteLine(&quot;\\nData Response&quot;);<br \/>\n    <br \/>Console.WriteLine(&quot;Total Surface Area .. : {0:F2}&quot;, dataResponse.SurfaceArea);<\/p>\n<p>Console.WriteLine(&quot;Total Volume &#8230;&#8230;.. : {0:F2}&quot;, dataResponse.Volume);<\/p>\n<p>}<\/font><\/p>\n<p>If some went wrong, catch the CuboidFaultException.<br \/>\n  <br \/><font color=\"#0000ff\" face=\"Courier New\">catch (FaultException&lt;CuboidServiceReference.CuboidFaultException&gt; eX)<br \/>\n    <br \/>{<\/font><\/p>\n<p>Display the custom values returned by implemented FaultContract from service,<font color=\"#0000ff\" face=\"Courier New\"><font color=\"#333333\" face=\"Tahoma\"> why service has thrown CuboidFaultException. <\/font><\/font><font color=\"#0000ff\" face=\"Courier New\">Console.WriteLine(&quot;\\nThere was an error while fetching details . . .&quot;);<br \/>\n    <br \/>Console.WriteLine(&quot;Reason &#8230;&#8230;&#8230;&#8230;.. : &quot; + eX.Detail.Reason);<\/p>\n<p>Console.WriteLine(&quot;Source &#8230;&#8230;&#8230;&#8230;.. : &quot; + eX.Detail.Source);<\/p>\n<p>Console.WriteLine(&quot;Details &#8230;&#8230;&#8230;&#8230;. : &quot; + eX.Detail.Detail);<\/p>\n<p>Console.WriteLine(&quot;Help Link &#8230;&#8230;&#8230;.. : &quot; + eX.Detail.HelpLink);<\/p>\n<p>}<\/font><\/p>\n<h3>Output <\/h3>\n<p>and here is the output&#160; with difference conditions.<\/p>\n<h4>Output when you provide all valid inputs.<\/h4>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image11.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top:0;border-right:0;background-image:none;border-bottom:0;padding-top:0;padding-left:0;border-left:0;display:inline;padding-right:0;\" border=\"0\" alt=\"image\" src=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image_thumb11.png\" width=\"623\" height=\"218\" \/><\/a><\/p>\n<h4>Output when you one or more invalid input.<\/h4>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image12.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top:0;border-right:0;background-image:none;border-bottom:0;padding-top:0;padding-left:0;border-left:0;display:inline;padding-right:0;\" border=\"0\" alt=\"image\" src=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image_thumb12.png\" width=\"627\" height=\"287\" \/><\/a><\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image13.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top:0;border-right:0;background-image:none;border-bottom:0;padding-top:0;padding-left:0;border-left:0;display:inline;padding-right:0;\" border=\"0\" alt=\"image\" src=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image_thumb13.png\" width=\"634\" height=\"275\" \/><\/a><\/p>\n<h3>Creating Web Client <\/h3>\n<h4>Creating the base project <\/h4>\n<p>Create a web site.<\/p>\n<h4>Generating proxies <\/h4>\n<p>while the host application is running, right click on the client application project, right click on the website<\/p>\n<p><strong>Add Service Reference<\/strong> <\/p>\n<p>in the address bar type the address of the <strong>mex<\/strong> endpoint address of <strong>CuboidService<\/strong> as shown below.<\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image14.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top:0;border-right:0;background-image:none;border-bottom:0;padding-top:0;padding-left:0;border-left:0;display:inline;padding-right:0;\" border=\"0\" alt=\"image\" src=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image_thumb14.png\" width=\"555\" height=\"363\" \/><\/a><\/p>\n<h4>Designing UI for web client<\/h4>\n<p>Add some controls to the page as shown below.<\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image15.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top:0;border-right:0;background-image:none;border-bottom:0;padding-top:0;padding-left:0;margin:0;border-left:0;display:inline;padding-right:0;\" border=\"0\" alt=\"image\" src=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image_thumb15.png\" width=\"244\" height=\"203\" \/><\/a><\/p>\n<p>Input <\/p>\n<p>&#160;<\/p>\n<table cellspacing=\"0\" cellpadding=\"2\" width=\"500\" border=\"0\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"121\"><strong>ID<\/strong><\/td>\n<td valign=\"top\" width=\"119\"><strong>Type<\/strong><\/td>\n<td valign=\"top\" width=\"258\"><strong>Text<\/strong><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\">lblID<\/td>\n<td valign=\"top\" width=\"119\">Label<\/td>\n<td valign=\"top\" width=\"258\">Label<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\"><strong><font color=\"#9b00d3\">txtID<\/font><\/strong><\/td>\n<td valign=\"top\" width=\"119\">TextBox<\/td>\n<td valign=\"top\" width=\"258\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\">lblLength<\/td>\n<td valign=\"top\" width=\"119\">Label<\/td>\n<td valign=\"top\" width=\"258\">Length :<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\"><strong>txtLength<\/strong><\/td>\n<td valign=\"top\" width=\"119\">TextBox<\/td>\n<td valign=\"top\" width=\"258\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\">lblWidth<\/td>\n<td valign=\"top\" width=\"119\">Label<\/td>\n<td valign=\"top\" width=\"258\">Width :<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\"><strong><font color=\"#9b00d3\">txtWidth<\/font><\/strong><\/td>\n<td valign=\"top\" width=\"119\">TextBox<\/td>\n<td valign=\"top\" width=\"258\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\">lblHeight<\/td>\n<td valign=\"top\" width=\"119\">Label<\/td>\n<td valign=\"top\" width=\"258\">Height :<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\"><strong><font color=\"#9b00d3\">txtHeight<\/font><\/strong><\/td>\n<td valign=\"top\" width=\"119\">TextBox<\/td>\n<td valign=\"top\" width=\"258\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\">lblCap1<\/td>\n<td valign=\"top\" width=\"119\">Label<\/td>\n<td valign=\"top\" width=\"258\">Calling using Message Contract<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\"><font color=\"#c0504d\"><strong>lblStatus1<\/strong><\/font><\/td>\n<td valign=\"top\" width=\"119\">Label<\/td>\n<td valign=\"top\" width=\"258\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\"><font color=\"#c0504d\"><strong>lblArea1<\/strong><\/font><\/td>\n<td valign=\"top\" width=\"119\">Label<\/td>\n<td valign=\"top\" width=\"258\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\"><font color=\"#c0504d\"><strong>lblVolume1<\/strong><\/font><\/td>\n<td valign=\"top\" width=\"119\">Label<\/td>\n<td valign=\"top\" width=\"258\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\">lblCap2<\/td>\n<td valign=\"top\" width=\"119\">Label<\/td>\n<td valign=\"top\" width=\"258\">Calling using Data Contract<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\"><font color=\"#c0504d\"><strong>lblStatus2<\/strong><\/font><\/td>\n<td valign=\"top\" width=\"119\">Label<\/td>\n<td valign=\"top\" width=\"258\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\"><font color=\"#c0504d\"><strong>lblArea2<\/strong><\/font><\/td>\n<td valign=\"top\" width=\"119\">Label<\/td>\n<td valign=\"top\" width=\"258\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\"><font color=\"#c0504d\"><strong>lblVolume2<\/strong><\/font><\/td>\n<td valign=\"top\" width=\"119\">Label<\/td>\n<td valign=\"top\" width=\"258\">&nbsp;<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"121\"><strong>btnCalc<\/strong><\/td>\n<td valign=\"top\" width=\"119\">Button<\/td>\n<td valign=\"top\" width=\"258\">Call Service<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Calling Service.<\/p>\n<p>Service is called, when the Call Service button is clicked. handler for Click event of <strong>btnCalc<\/strong> is given below.<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>protected void btnCalc_Click(object sender, EventArgs e)<br \/>\n      <br \/>{<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160; int nID = 0;<br \/>\n      <br \/>&#160;&#160;&#160;&#160; bool bID = int.TryParse ( txtID.Text,&#160; out nID); <\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160; int nLength = 0;<br \/>\n      <br \/>&#160;&#160;&#160;&#160; bool bLength = int.TryParse ( txtLength.Text,&#160; out nLength ); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160; int&#160; nWidth = 0 ;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160; bool bWidth = int.TryParse ( txtWidth.Text,&#160; out nWidth ); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160; int nHeight = 0 ;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160; bool bHeight= int .TryParse ( txtHeight.Text,&#160; out nHeight);<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160; bool bValid = ((bID) &amp;&amp; (bWidth) &amp;&amp; (bLength) &amp;&amp; (bHeight));<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160; StringBuilder sbTmp= new StringBuilder () ;<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160; if ( bValid )<br \/>\n      <br \/>&#160;&#160;&#160;&#160;&#160;&#160; {<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Session[&quot;ID&quot;] = nID.ToString () ;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Session[&quot;Length&quot;] = nLength .ToString ();<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Session[&quot;Width&quot;] = nWidth .ToString ();<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Session[&quot;Height&quot;] = nHeight.ToString () ;<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bool bObjCreated = true ;<br \/>\n      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CuboidServiceReference.CuboidServiceClient objClient = null ;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; objClient = new CuboidServiceReference.CuboidServiceClient();<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; catch ( Exception eX)<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; objClient = null ;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblVolume2.Text = &quot;&lt;Font color=#ff0000&gt;Failed while creating Service proxy &#8230;.. &lt;\/font&gt;&quot; ;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; bObjCreated = false ;<\/p>\n<p>&#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; if ( bObjCreated == false ) return ;<br \/>\n      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \/\/&#160; Issue Request 1<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CuboidServiceReference.CuboidInfoRequest msgRequest = new CuboidServiceReference.CuboidInfoRequest ();<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; msgRequest.Dimension = new CuboidServiceReference.CuboidDimension();<\/p>\n<p>&#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; msgRequest.ID = nID ;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; msgRequest.Dimension.Length = nLength ;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; msgRequest.Dimension.Width = nWidth ;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; msgRequest.Dimension.Height = nHeight ;<\/p>\n<p>&#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; <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CuboidServiceReference.CuboidDetailResponse msgResponse = new CuboidServiceReference.CuboidDetailResponse ();<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; msgResponse.SurfaceArea = objClient.CalculateDetails1 ( ref msgRequest.ID, msgRequest.Dimension, out msgResponse.Volume );<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblCap1.Text = &quot;&lt;font Color=#0000ff&gt;Calling using Message Contract &lt;\/font&gt;&quot;;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblStatus1.Text = &quot;&lt;font Color=#008000&gt;Status : Success &lt;\/font&gt;&quot;;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblArea1.Text = &quot;&lt;Font color=#000080&gt;Total Surface Area .. : &quot; +&#160; msgResponse.SurfaceArea.ToString (&quot;F2&quot;) + &quot;&lt;\/font&gt;&quot; ;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblVolume1.Text = &quot;&lt;Font color=#000080&gt;Total Volume .. : &quot; +&#160; msgResponse.Volume.ToString (&quot;F2&quot;) + &quot;&lt;\/font&gt;&quot; ;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; catch (FaultException&lt;CuboidServiceReference.CuboidFaultException&gt; eX)<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; StringBuilder sbErr = new StringBuilder (&quot;&lt;font Color=#ff0000&gt;Status : Error &quot;);<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sbErr .Append ( &quot;&lt;br&gt;Reason&#160;&#160; : &quot; ); sbErr.Append ( eX.Detail.Reason );<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sbErr .Append ( &quot;&lt;br&gt;Source&#160;&#160; : &quot; ); sbErr.Append ( eX.Detail.Source );<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sbErr .Append ( &quot;&lt;br&gt;Details&#160; : &quot; ); sbErr.Append ( eX.Detail.Detail&#160; );<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sbErr .Append ( &quot;&lt;br&gt;HelpLink : &quot; ); sbErr.Append ( eX.Detail.HelpLink );<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sbErr .Append ( &quot;&lt;\/Font&gt;&quot;);<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblCap2.Text = &quot;&lt;font Color=#0000ff&gt;Calling using Message Contract &lt;\/font&gt;&quot;;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblStatus1.Text = sbErr.ToString(); ;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblArea1.Text = &quot;&quot; ;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblVolume1.Text = &quot;&quot;; <\/p>\n<p>&#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; Issue Request 2<br \/>\n      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CuboidServiceReference.CuboidInfo dataRequest = new CuboidServiceReference.CuboidInfo();<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dataRequest.Dimension = new CuboidServiceReference.CuboidDimension();<\/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; dataRequest.ID = nID;<br \/>\n      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dataRequest.Dimension.Length = nLength;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dataRequest.Dimension.Width = nWidth;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dataRequest.Dimension.Height = nHeight;<\/strong><\/font><\/p>\n<p>\n  <br \/><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CuboidServiceReference.CuboidDetail dataResponse = new CuboidServiceReference.CuboidDetail();<br \/>\n      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dataResponse = objClient.CalculateDetails2(dataRequest);<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblCap2.Text = &quot;&lt;font Color=#0000ff&gt;Calling using Data Contract &lt;\/font&gt;&quot;;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblStatus2.Text = &quot;&lt;font Color=#008000&gt;Status : Success &lt;\/font&gt;&quot;;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblArea2.Text = &quot;&lt;Font color=#000080&gt;Total Surface Area .. : &quot; + dataResponse.SurfaceArea.ToString(&quot;F2&quot;) + &quot;&lt;\/font&gt;&quot;;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblVolume2.Text = &quot;&lt;Font color=#000080&gt;Total Volume .. : &quot; + dataResponse.Volume.ToString(&quot;F2&quot;) + &quot;&lt;\/font&gt;&quot;;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; catch (FaultException&lt;CuboidServiceReference.CuboidFaultException&gt; eX)<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; StringBuilder sbErr = new StringBuilder(&quot;&lt;font Color=#ff0000&gt;Status : Error &quot;);<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sbErr.Append(&quot;&lt;br&gt;Reason&#160;&#160; : &quot;); sbErr.Append(eX.Detail.Reason);<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sbErr.Append(&quot;&lt;br&gt;Source&#160;&#160; : &quot;); sbErr.Append(eX.Detail.Source);<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sbErr.Append(&quot;&lt;br&gt;Details&#160; : &quot;); sbErr.Append(eX.Detail.Detail);<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sbErr.Append(&quot;&lt;br&gt;HelpLink : &quot;); sbErr.Append(eX.Detail.HelpLink);<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sbErr.Append(&quot;&lt;\/Font&gt;&quot;);<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblCap2.Text = &quot;&lt;font Color=#0000ff&gt;Calling using Data Contract &lt;\/font&gt;&quot;;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblStatus2.Text = sbErr.ToString();<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblArea2.Text = &quot;&quot;;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblVolume2.Text = &quot;&quot;;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160; }<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160; else <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160; {<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sbTmp.Append ( &quot;&lt;Font Color=#ff0000&gt;&quot;);<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if ( bID ) sbTmp.Append ( &quot;&lt;p&gt;&lt;Font Color=#ff0000&gt; ID should be a positive&#160; numeric value&quot;);<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if ( bLength ) sbTmp.Append ( &quot;&lt;p&gt;&lt;Font Color=#ff0000&gt; Length should be a positive numeric value&quot;);<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if ( bWidth ) sbTmp.Append ( &quot;&lt;p&gt;&lt;Font Color=#ff0000&gt; Width should be a positive numeric value&quot;);<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if ( bHeight ) sbTmp.Append ( &quot;&lt;p&gt;&lt;Font Color=#ff0000&gt; Height should be a positive numeric value&quot;);<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; sbTmp.Append ( &quot;&lt;\/Font&gt;&quot;);<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; lblVolume2.Text = sbTmp.ToString (); <\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160; }<\/p>\n<p>&#160;&#160; }<\/strong><\/font><\/p>\n<p>Parse all inputs, from their respective&#160; text box.<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>int nID = 0;<br \/>\n      <br \/>bool bID = int.TryParse ( txtID.Text,&#160; out nID); <\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>int nLength = 0;<br \/>\n      <br \/>bool bLength = int.TryParse ( txtLength.Text,&#160; out nLength );&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/>int&#160; nWidth = 0 ;<\/p>\n<p>bool bWidth = int.TryParse ( txtWidth.Text,&#160; out nWidth );&#160; <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/>int nHeight = 0 ;<\/p>\n<p>bool bHeight= int .TryParse ( txtHeight.Text,&#160; out nHeight);<\/strong><\/font><\/p>\n<p>Make sure that all inputs are valid. <\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>bool bValid = ((bID) &amp;&amp; (bWidth) &amp;&amp; (bLength) &amp;&amp; (bHeight));<\/strong><\/font><\/p>\n<p>if everything is good, store valid values to session, this is useful, to retain values, during post back<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>StringBuilder sbTmp= new StringBuilder () ;<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>if ( bValid )<br \/>\n      <br \/>{<\/p>\n<p>&#160;&#160;&#160; Session[&quot;ID&quot;] = nID.ToString () ;<\/p>\n<p>&#160;&#160;&#160; Session[&quot;Length&quot;] = nLength .ToString ();<\/p>\n<p>&#160;&#160;&#160; Session[&quot;Width&quot;] = nWidth .ToString ();<\/p>\n<p>&#160;&#160;&#160; Session[&quot;Height&quot;] = nHeight.ToString () ;<\/strong><\/font><\/p>\n<p>Create service proxy, display error message, it failed, and set a flag.<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>bool bObjCreated = true ;<br \/>\n      <br \/>CuboidServiceReference.CuboidServiceClient objClient = null ;<\/p>\n<p>try<\/p>\n<p>{<\/p>\n<p>&#160;&#160;&#160; objClient = new CuboidServiceReference.CuboidServiceClient();<\/p>\n<p>}<\/p>\n<p>catch ( Exception eX)<\/p>\n<p>{<\/p>\n<p>&#160;&#160;&#160; objClient = null ;<\/p>\n<p>&#160;&#160;&#160; lblVolume2.Text = &quot;&lt;Font color=#ff0000&gt;Failed while creating Service proxy &#8230;.. &lt;\/font&gt;&quot; ;<\/p>\n<p>&#160;&#160;&#160; bObjCreated = false ;<\/p>\n<p>}<\/strong><\/font><\/p>\n<p>Return if failed. <\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>if ( bObjCreated == false ) return ;<br \/>\n      <br \/>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/>\/\/&#160; Issue Request 1<\/strong><\/font><\/p>\n<p>\/\/&#160; Issue Request 2, this time using MessageContract<font color=\"#0000ff\" face=\"Courier New\"><strong><br \/>\n      <br \/>try<\/p>\n<p>{<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><font color=\"#333333\" face=\"Tahoma\">Prepare Message Request<\/font><\/p>\n<p><strong>&#160;&#160;&#160; CuboidInfoRequest msgRequest=new CuboidInfoRequest ();<br \/>\n      <br \/>&#160;&#160;&#160; msgRequest.Dimension = new CuboidDimension();<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><font color=\"#333333\" face=\"Tahoma\"><\/font><\/font><\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><font color=\"#0000ff\" face=\"Courier New\"><font color=\"#333333\" face=\"Tahoma\">Assign values to Message Request<\/font><\/font>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/><strong>&#160;&#160;&#160; msgRequest.ID = nID ;<br \/>\n      <br \/>&#160;&#160;&#160; msgRequest.Dimension.Length = nLength ;<\/p>\n<p>&#160;&#160;&#160; msgRequest.Dimension.Width = nWidth ;<\/p>\n<p>&#160;&#160;&#160; msgRequest.Dimension.Height = nHeight ;<\/p>\n<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br \/>&#160;&#160;&#160; CuboidDetailResponse msgResponse = new&#160; CuboidDetailResponse ();<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><font color=\"#0000ff\" face=\"Courier New\"><font color=\"#333333\" face=\"Tahoma\">Call Service and collect Message Response.<\/font><\/font><\/p>\n<p><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160; msgResponse.SurfaceArea = objClient.CalculateDetails1 ( ref msgRequest.ID, msgRequest.Dimension, out msgResponse.Volume );<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><font color=\"#0000ff\" face=\"Courier New\"><font color=\"#333333\" face=\"Tahoma\"><\/font><\/font><\/font><font color=\"#0000ff\" face=\"Courier New\"><font color=\"#333333\" face=\"Tahoma\">Display output.<\/font><\/p>\n<p><strong>lblCap1.Text = &quot;&lt;font Color=#0000ff&gt;Calling using Message Contract &lt;\/font&gt;&quot;;<br \/>\n      <br \/>lblStatus1.Text = &quot;&lt;font Color=#008000&gt;Status : Success &lt;\/font&gt;&quot;;<\/p>\n<p>lblArea1.Text = &quot;&lt;Font color=#000080&gt;Total Surface Area .. : &quot; +&#160; msgResponse.SurfaceArea.ToString (&quot;F2&quot;) + &quot;&lt;\/font&gt;&quot; ;<\/p>\n<p>lblVolume1.Text = &quot;&lt;Font color=#000080&gt;Total Volume .. : &quot; +&#160; msgResponse.Volume.ToString (&quot;F2&quot;) + &quot;&lt;\/font&gt;&quot; ;<\/p>\n<p>}<\/p>\n<p>catch (FaultException&lt;CuboidFaultException&gt; eX)<\/p>\n<p>{<\/strong><\/font><\/p>\n<p>if something was wrong, <font color=\"#0000ff\" face=\"Courier New\"><font color=\"#333333\" face=\"Tahoma\">display error information, passed through FaultContract<\/font><\/font><font color=\"#0000ff\" face=\"Courier New\"><strong><br \/>\n      <br \/>&#160;&#160;&#160; StringBuilder sbErr = new StringBuilder (&quot;&lt;font Color=#ff0000&gt;Status : Error &quot;);<\/p>\n<p>&#160;&#160;&#160; sbErr .Append ( &quot;&lt;br&gt;Reason&#160;&#160; : &quot; ); sbErr.Append ( eX.Detail.Reason );<\/p>\n<p>&#160;&#160;&#160; sbErr .Append ( &quot;&lt;br&gt;Source&#160;&#160; : &quot; ); sbErr.Append ( eX.Detail.Source );<\/p>\n<p>&#160;&#160;&#160; sbErr .Append ( &quot;&lt;br&gt;Details&#160; : &quot; ); sbErr.Append ( eX.Detail.Detail&#160; );<\/p>\n<p>&#160;&#160;&#160; sbErr .Append ( &quot;&lt;br&gt;HelpLink : &quot; ); sbErr.Append ( eX.Detail.HelpLink );<\/p>\n<p>&#160;&#160;&#160; sbErr .Append ( &quot;&lt;\/Font&gt;&quot;);<\/p>\n<p>&#160;&#160;&#160; lblCap1.Text = &quot;&lt;font Color=#0000ff&gt;Calling using Message Contract &lt;\/font&gt;&quot;;<\/p>\n<p>&#160;&#160;&#160; lblStatus1.Text = sbErr.ToString(); ;<\/p>\n<p>&#160;&#160;&#160; lblArea1.Text = &quot;&quot; ;<\/p>\n<p>&#160;&#160;&#160; lblVolume1.Text = &quot;&quot;; <\/p>\n<p>}<\/strong><\/font><\/p>\n<p>\/\/&#160; Issue Request 2, this time using DataContract<\/p>\n<p><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>try<br \/>\n      <br \/>{<\/strong><\/font><\/p>\n<p>\/\/ Prepare Data object to be passed<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160; CuboidInfo dataRequest = new CuboidInfo();<br \/>\n      <br \/>&#160;&#160;&#160; dataRequest.Dimension = new CuboidDimension();<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160; dataRequest.ID = nID;<br \/>\n      <br \/>&#160;&#160;&#160; dataRequest.Dimension.Length = nLength;<\/p>\n<p>&#160;&#160;&#160; dataRequest.Dimension.Width = nWidth;<\/p>\n<p>&#160;&#160;&#160; dataRequest.Dimension.Height = nHeight;<\/strong><\/font><\/p>\n<p>\/\/ Collect&#160; the returned Data object.<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160; CuboidDetail dataResponse = new CuboidServiceReference.CuboidDetail();<br \/>\n      <br \/>&#160;&#160;&#160; dataResponse = objClient.CalculateDetails2(dataRequest);<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>\/\/ Display Output<br \/>\n      <br \/>&#160;&#160;&#160; lblCap2.Text = &quot;&lt;font Color=#0000ff&gt;Calling using Data Contract &lt;\/font&gt;&quot;;<\/p>\n<p>&#160;&#160;&#160; lblStatus2.Text = &quot;&lt;font Color=#008000&gt;Status : Success &lt;\/font&gt;&quot;;<\/p>\n<p>&#160;&#160;&#160; lblArea2.Text = &quot;&lt;Font color=#000080&gt;Total Surface Area .. : &quot; + dataResponse.SurfaceArea.ToString(&quot;F2&quot;) + &quot;&lt;\/font&gt;&quot;;<\/p>\n<p>&#160;&#160;&#160; lblVolume2.Text = &quot;&lt;Font color=#000080&gt;Total Volume .. : &quot; + dataResponse.Volume.ToString(&quot;F2&quot;) + &quot;&lt;\/font&gt;&quot;;<\/p>\n<p>}<\/p>\n<p>catch (FaultException&lt;CuboidFaultException&gt; eX)<\/p>\n<p>{<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><font color=\"#333333\" face=\"Tahoma\">\/\/&#160;&#160;&#160;&#160; if something was wrong, display error information, passed through FaultContract<\/font><font color=\"#0000ff\" face=\"Courier New\"><br \/>\n      <br \/><\/font><strong>&#160;&#160;&#160; StringBuilder sbErr = new StringBuilder(&quot;&lt;font Color=#ff0000&gt;Status : Error &quot;);<br \/>\n      <br \/>&#160;&#160;&#160; sbErr.Append(&quot;&lt;br&gt;Reason&#160;&#160; : &quot;); sbErr.Append(eX.Detail.Reason);<\/p>\n<p>&#160;&#160;&#160; sbErr.Append(&quot;&lt;br&gt;Source&#160;&#160; : &quot;); sbErr.Append(eX.Detail.Source);<\/p>\n<p>&#160;&#160;&#160; sbErr.Append(&quot;&lt;br&gt;Details&#160; : &quot;); sbErr.Append(eX.Detail.Detail);<\/p>\n<p>&#160;&#160;&#160; sbErr.Append(&quot;&lt;br&gt;HelpLink : &quot;); sbErr.Append(eX.Detail.HelpLink);<\/p>\n<p>&#160;&#160;&#160; sbErr.Append(&quot;&lt;\/Font&gt;&quot;);<\/p>\n<p>&#160;&#160;&#160; lblCap2.Text = &quot;&lt;font Color=#0000ff&gt;Calling using Data Contract &lt;\/font&gt;&quot;;<\/p>\n<p>&#160;&#160;&#160; lblStatus2.Text = sbErr.ToString();<\/p>\n<p>&#160;&#160;&#160; lblArea2.Text = &quot;&quot;;<\/p>\n<p>&#160;&#160;&#160; lblVolume2.Text = &quot;&quot;;<\/p>\n<p>}<\/p>\n<p><\/strong><\/font><font color=\"#0000ff\" face=\"Courier New\"><strong>else<br \/>\n      <br \/>{<\/strong><\/font><\/p>\n<p>\/\/ Input field validation failed, show error message(s)<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><strong>&#160;&#160;&#160; sbTmp.Append ( &quot;&lt;Font Color=#ff0000&gt;&quot;);<br \/>\n      <br \/>&#160;&#160;&#160; if ( bID ) sbTmp.Append ( &quot;&lt;p&gt;ID should be a positive&#160; numeric value&quot;);<\/p>\n<p>&#160;&#160;&#160; if ( bLength ) sbTmp.Append ( &quot;&lt;p&gt;Length should be a positive numeric value&quot;);<\/p>\n<p>&#160;&#160;&#160; if ( bWidth ) sbTmp.Append ( &quot;&lt;p&gt;Width should be a positive numeric value&quot;);<\/p>\n<p>&#160;&#160;&#160; if ( bHeight ) sbTmp.Append ( &quot;&lt;p&gt;Height should be a positive numeric value&quot;);<\/p>\n<p>&#160;&#160;&#160; sbTmp.Append ( &quot;&lt;\/Font&gt;&quot;);<\/p>\n<p>&#160;&#160;&#160; lblVolume2.Text = sbTmp.ToString (); <\/p>\n<p>}<\/strong><\/font><\/p>\n<h3>Output <\/h3>\n<p>Build the web site, and execute,<\/p>\n<h4>Output when you provide all valid inputs.<\/h4>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image16.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top:0;border-right:0;background-image:none;border-bottom:0;padding-top:0;padding-left:0;border-left:0;display:inline;padding-right:0;\" border=\"0\" alt=\"image\" src=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image_thumb16.png\" width=\"214\" height=\"189\" \/><\/a><font color=\"#0000ff\" face=\"Courier New\"><strong><br \/>\n      <br \/><\/strong><\/font><\/p>\n<h4>Output when you one or more invalid input.<\/h4>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/weboutput2.jpg\"><img loading=\"lazy\" decoding=\"async\" title=\"webOutput2\" style=\"border-top:0;border-right:0;background-image:none;border-bottom:0;padding-top:0;padding-left:0;border-left:0;display:inline;padding-right:0;\" border=\"0\" alt=\"webOutput2\" src=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/weboutput2_thumb.jpg\" width=\"659\" height=\"290\" \/><\/a><\/p>\n<p><a href=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image17.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" style=\"border-top:0;border-right:0;background-image:none;border-bottom:0;padding-top:0;padding-left:0;border-left:0;display:inline;padding-right:0;\" border=\"0\" alt=\"image\" src=\"http:\/\/praveenkatiyar.wordpress.com\/wp-content\/uploads\/2013\/10\/image_thumb17.png\" width=\"658\" height=\"271\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Contracts in WCF, provide interoperability they need to communicate with the client. In this article i am going to explain the type of contracts, and how these contracts can be used in a real life application. in this article i have tried to explain all these things, using a simple example, in this example&hellip; <a class=\"more-link\" href=\"https:\/\/praveenkatiyar.in\/blog\/index.php\/2013\/10\/10\/understanding-contracts-in-wcf\/\">Continue reading <span class=\"screen-reader-text\">Understanding Contracts in WCF<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[17,33],"class_list":["post-329","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\/329","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=329"}],"version-history":[{"count":0,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/posts\/329\/revisions"}],"wp:attachment":[{"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}