locked
Client unable to connect self hosted wcf service in console through nettcp binding RRS feed

  • Question

  • Hi,

    I have a wcf service self hosted in console app using nettcp binding. My client is able to connect to the wcf service when run in a single machine. When run in a distributed system (client in machine1 and service in machine2) lost with the below time out exception.

    Open timed out after 00:00:00 while establishing a transport session to net.tcp://10.228.68.75:200/service/tcp. The time allotted to this operation may have been a portion of a longer timeout. 

    I checked and changed all the timeout values to 10 mins but still facing the same problem. I have custom logging in my client and service, but no other error/exception is logged except the above one. I believe that the request is not reaching the server but no clue why its not reaching.

    Request to provide any help in this aspect.

    Monday, March 9, 2015 12:55 PM

Answers

  • If I host my Service on Http ports like 80/8080 and use WSDualHttpBinding instead NetTcpBinding and declare a HTTP EndPoint for my Client, will all the problems w.r.t Port opening or firewalls will be resolved?

    No it won't be resloved. A firewall blocks unsolicited inbound traffic. What that means to you is that a program running on a machine behind a firewall that sends outbound traffic to a program on another machine on a network, that is a solicitation for traffic from the program that sent the traffic from behind the firewall. A firewall blocks unsolicited inbound traffic, and the firewall allows solicited inbound traffic through it back to the program that made the solicitation for traffic.

    My doubt is like, Will the Client Request and Callback use the same communication channel with the same ports defined or a different ports/channel will be created for Callback?

    First off, the WCF client must make the initial contact with the WCF service on the other machine, which is unsolicited inbound traffic to a firewall if a firewall is in play on the machine that is hosting the WCF service. The firewall is going to block the initial inbound traffic from the WCF client, becuase the WCF service sitting behind the firewall on the machine hosting the WCF service never made the solicitation for traffic by it sending outbound traffic to the WCF client.

    In order for unsolicited inbound traffic from the WCF client to reach the WCF service on the port that the WCF service is listening on for inbound traffic, then a firewall rule must be created that is going to open the port on the firewall and leave it open so that the WCF client can make the initial contact with the WCF service. Once that is done the intial conatact between the clent and the service is done, the firewall will allow the WCF client and WCF service to send traffic to each other.

    That's how a firewall works. The firewall blocks unsolicited inbound traffic, and it allows solicited inbound traffic through it. The only way  unsolicited inbound traffic makes it past the firewall, there must be a firewall rule created that opens the required port that the WCF service hosted on the machine is listening on so that is can receive the initial  unsolicited inbound traffic sent by the client. If there is a router or a firewall appliance sittiing there protecting a network, then it's called port forwading, which opens the port on those two devices so that unsolicited inbound traffic is forwared to the machine that has a program listening on the port for unsolicited inbound traffic.

    What should I do to make my self hosted wcf service a complete Http based including Client call backs and doesn't result in any Port Opening problems or Firewall Problems.

    If a host based firewall is running on machines, a router or firewall appliance is in play, then I have given you the basics on how things work, you are going to have to run with it and figure out what you need to do.

    As far as what is happening on outbound port traffic, there is an algorithm that is used by the O/S that is going to pick the outbound port to use, which is going to be any high port 1024 to 66535 that doesn't have a port in use by another program running on the machine. You shouldn't be using any well known ports, which are ports below 1024 for any  program to be listening on.

    http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

    • Marked as answer by Shawn Zhao Tuesday, March 17, 2015 1:58 AM
    Thursday, March 12, 2015 2:39 PM

All replies

  • Did you check for the existance of a firewall that is port blocking?
    • Proposed as answer by BonnieBMVP Wednesday, March 11, 2015 4:42 AM
    Monday, March 9, 2015 2:48 PM
  • Hi,

    For this scenario, this exception is due to the open operation doesn’t complete before the timeout. You can set it in the code or configure it in the web.config file. You also need to set it in the client side. Then you can host your service again and try it from the client side.

          <netTcpBinding>

            <binding name="Binding1"  closeTimeout="00:01:00"

                 openTimeout="00:02:00"

                 receiveTimeout="00:45:00"

                 sendTimeout="00:45:00">

            </binding>

          </netTcpBinding>

    For more information, you could refer to:

    http://blogs.msdn.com/b/hongmeig/archive/2010/03/06/timeouts-in-wcf-and-their-default-values.aspx

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/9e627a1f-6fb9-4cb2-a3df-f2398aed9121/timeout-exception-that-seems-to-be-rather-random-35sp1?forum=wcf

    Regards

    Tuesday, March 10, 2015 2:16 AM
  • There exists a firewall at both the client and server, Yet to know if something is really blocking.

    Please clarify me regarding the below queries which I have:

    My Self Hosted Service (hosted in console) includes CallBack's to Client for multiple operations and is data intensive, the data will be streamed from Client to Server continuously.

    If I host my Service on Http ports like 80/8080 and use WSDualHttpBinding instead NetTcpBinding and declare a HTTP EndPoint for my Client, will all the problems w.r.t Port opening or firewalls will be resolved?

    My doubt is like, Will the Client Request and Callback use the same communication channel with the same ports defined or a different ports/channel will be created for Callback?

    What should I do to make my self hosted wcf service a complete Http based including Client call backs and doesn't result in any Port Opening problems or Firewall Problems.


    • Edited by ykbharat Thursday, March 12, 2015 12:52 PM edited
    Thursday, March 12, 2015 11:16 AM
  • If I host my Service on Http ports like 80/8080 and use WSDualHttpBinding instead NetTcpBinding and declare a HTTP EndPoint for my Client, will all the problems w.r.t Port opening or firewalls will be resolved?

    No it won't be resloved. A firewall blocks unsolicited inbound traffic. What that means to you is that a program running on a machine behind a firewall that sends outbound traffic to a program on another machine on a network, that is a solicitation for traffic from the program that sent the traffic from behind the firewall. A firewall blocks unsolicited inbound traffic, and the firewall allows solicited inbound traffic through it back to the program that made the solicitation for traffic.

    My doubt is like, Will the Client Request and Callback use the same communication channel with the same ports defined or a different ports/channel will be created for Callback?

    First off, the WCF client must make the initial contact with the WCF service on the other machine, which is unsolicited inbound traffic to a firewall if a firewall is in play on the machine that is hosting the WCF service. The firewall is going to block the initial inbound traffic from the WCF client, becuase the WCF service sitting behind the firewall on the machine hosting the WCF service never made the solicitation for traffic by it sending outbound traffic to the WCF client.

    In order for unsolicited inbound traffic from the WCF client to reach the WCF service on the port that the WCF service is listening on for inbound traffic, then a firewall rule must be created that is going to open the port on the firewall and leave it open so that the WCF client can make the initial contact with the WCF service. Once that is done the intial conatact between the clent and the service is done, the firewall will allow the WCF client and WCF service to send traffic to each other.

    That's how a firewall works. The firewall blocks unsolicited inbound traffic, and it allows solicited inbound traffic through it. The only way  unsolicited inbound traffic makes it past the firewall, there must be a firewall rule created that opens the required port that the WCF service hosted on the machine is listening on so that is can receive the initial  unsolicited inbound traffic sent by the client. If there is a router or a firewall appliance sittiing there protecting a network, then it's called port forwading, which opens the port on those two devices so that unsolicited inbound traffic is forwared to the machine that has a program listening on the port for unsolicited inbound traffic.

    What should I do to make my self hosted wcf service a complete Http based including Client call backs and doesn't result in any Port Opening problems or Firewall Problems.

    If a host based firewall is running on machines, a router or firewall appliance is in play, then I have given you the basics on how things work, you are going to have to run with it and figure out what you need to do.

    As far as what is happening on outbound port traffic, there is an algorithm that is used by the O/S that is going to pick the outbound port to use, which is going to be any high port 1024 to 66535 that doesn't have a port in use by another program running on the machine. You shouldn't be using any well known ports, which are ports below 1024 for any  program to be listening on.

    http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

    • Marked as answer by Shawn Zhao Tuesday, March 17, 2015 1:58 AM
    Thursday, March 12, 2015 2:39 PM