Thursday, August 19, 2010

net.tcp - The message could not be dispatched because the service at the endpoint address is unavailable for the protocol



Yesterday I was transitioning our wcf services previously hosted in a windows service and exposed via net.tcp binding to the brand new shiny windows 2008 r2 server and IIS 7. The plan was to host the service in IIS but still use net.tcp binding so the performance would hopefully be the same as in windows service, but a hell lot easier to deploy and maintain and scale.

But boy! Aren't wcf error messages cryptic? Look for instance the following error when I try to access the service from an asp.net website client.
error
(Click to enlarge)

My heads were spinning as to why the protocol is being denied. I immediately went through checking the basics

  1. Is net.tcp enabled for the hosting website? It was!
  2. Have I given a proper net.tcp binding port for the hosting website? Yes I did. It was port 1002
  3. Am I calling the correct binding and port from my client? Yes I did.
Hmm. What the heck! Then out of the deep blue sky, this wild thought struck my mind. What about Permissions. Has it got anything to do with that? YES IT DID. It turned out the folder in which the service files reside (.svc and dlls) did not have read/write permissions for "network service" account, which is the account under which the app pool for this website is configured to run. So I added network service account on the folder and Bingo! the service was up and running. error2 Shouldn't WCF give me some sort of security error message? I wondered, but crashed to bed peacefully charged up enough the next morning to write this blog and hopefully help other troubled souls out there!


In a different instance where I installed VS 2010 and .Net 4.0 first and then enabled ".NET 3.5" in add/remove programs, the same issue showed up with the exact error message. The solution to that is
1. Open a command prompt
2. Navigate to c:\windows\microsoft.net\framework64\v4.0.30319
3. Register the service model using the command "ServiceModelReg.exe -r"