Today, we will learn about creating the WCF Service using netTcpBinding and hosting it on IIS Server. If you are new to WCF, then please read my previous article (Create Simple WCF Service And Host It On Console Application).
Now, let's make simple WCF Service which gives the sum of two numbers.
- Start the Visual Studio with administrator rights and create one class library project named as 'WCFAddition'.

- This will generate default class file automatically. So, we have to delete it and add one new item as 'WCF Service' with the same name, 'WCFAddition'. This will generate one class file and one interface (WCFAddition.cs and IWCFAddition.cs).
- Open the interface file and create method 'SumOfTwoNumber'.
- [ServiceContract]
- public interface IWCFAddition {
- [OperationContract]
- void DoWork();
- [OperationContract]
- int SumOfTwoNumber(int num1, int num2);
- }

- Now, implement this interface on class file.
- public class WCFAddition: IWCFAddition {
- public void DoWork() {}
- public int SumOfTwoNumber(int num1, int num2) {
- return num1 + num2;
- }
- }

- Now, let's build the project solution and then add new web site in same solution for IIS hosting.

- Give reference of WCF Service to this new website, as shown below.

- Now, open Service.svc file and modify it as below.
- <%@ ServiceHost Language="C#" Debug="true" Service="WCFAddition.WCFAddition"%>

- The main part will start now and we have to make changes in web.config file. So here, first we have defined endpoint with netTcpBinding and then defined the base address for the same, as show below.
- <services>
- <service name="WCFAddition.WCFAddition">
- <endpoint binding="netTcpBinding" bindingConfiguration="ultra" contract="WCFAddition.IWCFAddition" />
- <host>
- <baseAddresses>
- <add baseAddress="net.tcp://localhost:5050/implementclass" />
- <add baseAddress="http://localhost:5051/implementclass" /> </baseAddresses>
- </host>
- </service>
- </services>
- Define the behavior for the netTcpBinding.
- <behaviors>
- <serviceBehaviors>
- <behavior>
- <serviceMetadata httpGetEnabled="true" />
- <serviceDebug includeExceptionDetailInFaults="true" /> </behavior>
- </serviceBehaviors>
- </behaviors>










Heeyong LeePosted Apr 28, 2019, 2:34 AM
Could you show me how to use this service at client web site ?