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"

10 comments:

  1. "ServiceModelReg.exe -r": This won't work on Server 2012

    ReplyDelete
  2. Thanks very much,
    I gave all permissions for the service files and folders to the account under which the app pool for the website is configured to run,
    and everything now works.
    But it was a tricky problem.

    ReplyDelete
  3. You sir are a life saver, i took me a good 5 hours to wrestle with this issue .. but a simple ServiceModelReg.exe -r did it ... Thanks

    ReplyDelete
  4. Thanks dude. It helps me to consume wcf service locally using net tcp binding.

    ReplyDelete
  5. anybody ever found why this happened , i mean why we should we run ServiceModelReg.exe -r command , how to solve this on server ?

    ReplyDelete
  6. Thanks a lot, this was terribly useful! :D My saviour!

    ReplyDelete