Skip to content

Hosting a WCF Service in IIS with Net Tcp binding

July 10, 2011

I started experimenting with different bindings on a WCF service because an appilcation we hosted for a customer had some performance issues. This application transfered massive loads of data with a standard httpBinding, in others words, all your objects is serialized on the Service, transfered as text (XML), and then recreated on the client that consumes the service. With a net.tcp binding instead the data transfer will be a lot smaller because the transferred would be binary!

I tried a couple of tutorials on the internet but I struggled so I want to make my own here. Here is how make a simple service on localhost with a net.tcp binding:

I have Windows 7 Professional and IIS7 and for making a nettcp binding possible through you have to enable Non-HTTP Activation. (Sorry for the Norwegian language)

image

Then start a new WCF Service application project ‘WCFService1’ in Visual Studio and compile it. NOTHING ELSE! Just keep the original sample code.

Then we test it with the defautl httpBinding. Open IIS Manager and click on your “Default Web Site”. Then set the path for this website to your newly created WCFService1

image

Open up WcfTestClient.exe (in your Microsoft SDK folder) and add service http://localhost/Service1.svc
The service should appear like this
image 

So far, so good. But what about that net.tcp binding?

Add another binding to your website through IIS Manager with net.tcp and binding info: “808:*”. This means that localhost will listen on port 808 which is default for net.tcp connections.

image

Go to Default Web Site –> Manage Website –> Advanced Settings and make sure that Activated protocols are “http, net.tcp”

image

Now you are almost done!
We have to modify our web.config for the WCFService application and change the bindings configured to nettcp instead of http. Make sure you have these lines

<endpoint address="" binding="netTcpBinding" contract="WcfService1.IService1">

and this one

<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>

Voila! Try now to open up WcfTestClient.exe (in your Microsoft SDK folder) and add service net.tcp://localhost/Service1.svc

If you have some trouble with connecting, maybe you can temporary turn off your firewall. The firefwall can sometimes be blocking your port

From → .Net

Leave a Comment

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: