Could not connect to net.tcp://

While learning to use the ServiceBus, I wrote a small application that sends messages to a queue and retrieves based on filters. Initially the application was working fine. But when I wanted to demo it to my collegue, it just wouldn’t send or receive messages. I constantly saw the exception

Could not connect to net.tcp:// The connection attempt lasted for a time span of 00:00:21.0254249. TCP error code 10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

After some investigation, I figured out that the issue was due to change in environment. When I had initially developed the application, I was working on a network which had no restrictions. But my demo was on my office network that had a firewall with ports locked down. To communicate with the ServiceBus, the SDK uses tcp port 9354.

You can open this port and make the application work. Or if you are going to run your application in an environment where IT will not open ports for your application, you can communicate with the ServiceBus using HTTP.

To communicate using HTTP, before you perform any operations, set the connectivity mode to http.

Microsoft.ServiceBus.ServiceBusEnvironment.SystemConnectivity.Mode = ConnectivityMode.Http;

This mode setting applies to all endpoints being used by your application.

Using Http mode has a performance downside compared to Tcp. I will update this post soon with some performance numbers comparing the 2 modes.


Leave a Reply

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

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