WCF Web Service Hosting Part 2 – netTcpBinding and IIS

This post is about how to host WCF services in IIS with netTcpBinding. I use the same test service and test client as in the previous post.

WCF Service Host

First, let us try it with the WCF Service Host.

1. Add a new endpoint to the service App.config.

<endpoint address=”net.tcp://localhost:8732/Design_Time_Addresses/TestService/Service1/” binding=”netTcpBinding” contract=”TestService.IService1″ />

If you want to expose a metadata exchange endpoint via netTcp, I suggest you add a base address, and have two endpoints with addresses relative to the base:

<add baseAddress=”net.tcp://localhost:8732/Design_Time_Addresses/TestService/Service1/”/>

<endpoint address=”” binding=”netTcpBinding” contract=”TestService.IService1″/>
<endpoint address=”mex” binding=”mexTcpBinding” contract=”IMetadataExchange”/>

2. Add the new endpoint to the client app.config and modify Program.cs:

<endpoint address=”net.tcp://localhost:8732/Design_Time_Addresses/TestService/Service1/”
binding=”netTcpBinding”
contract=”ServiceReference1.IService1″
name=”NetTcpBinding_IService1″ />

Service1Client client = new Service1Client(“NetTcpBinding_IService1”);

IIS

Now about IIS 7.

1. You must add the Non-HTTP Activation feature. Here is a screen-shot from Windows Server 2008:

image

2. You might have to add the net.tcp binding to IIS. Start IIS Manager, select your web site and click on Bindings under Actions. Add a new binding of type net.tcp. Specify “<port number>:*” (without the quotes) as binding information. I chose port 808.

image

3. Enable net.tcp for your application. Select WcfTest (my test application) and click on Advanced Settings. In enabled protocols, specify both http and net.tcp.

image

4. If you are running Windows Firewall, look for an inbound rule called “Windows Communication Foundation Net.TCP Listener Adapter (TCP-In)” which allows traffic on the selected port. If you don’t have it you are going to get an error messages like this:

Could not connect to net.tcp://localhost:808/WcfTest/TestService.Service1.svc. The connection attempt lasted for a time span of 00:00:02.0727927. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:808.

If this is the case, create the rule manually:

image

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s