none
Understanding receiveTimeout in WCF RRS feed

  • Question

  • I am trying to understand "receiveTimeout" binding property in WCF by following code:

    Server side:

        ServiceHost serviceHostForStrong = new ServiceHost(typeof(Service), new Uri("http://localhost:8887/Service"));
                BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
                basicHttpBinding.ReceiveTimeout = new TimeSpan(0, 0, 5);
                EndpointAddress endpointAddress = new EndpointAddress("http://localhost:8887/Service/");
                ServiceEndpoint serviceEndpoint =
                    new ServiceEndpoint(ContractDescription.GetContract(typeof(IServiceContract)),
                        basicHttpBinding,
                        endpointAddress);
                serviceHostForStrong.AddServiceEndpoint(serviceEndpoint);
                serviceHostForStrong.Open();

                Console.WriteLine("Service is running....Press any key to exit");
                Console.ReadKey();

    Client side:

        EndpointAddress endpointAddress = new EndpointAddress("http://localhost:8887/Service/");

                BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
                ChannelFactory<IServiceContract> channelFactory = new ChannelFactory<IServiceContract>(basicHttpBinding, endpointAddress);

                IServiceContract proxy = channelFactory.CreateChannel(endpointAddress);
                Console.WriteLine("Data received: " + proxy.GetData());
                Thread.Sleep(new TimeSpan(0, 0, 10));
                Console.WriteLine("Data received after 10 seconds: " + proxy.GetData());
                Console.WriteLine("Press any key to exit.....");
                Console.ReadKey();

    Please note:

     1. The receiveTimeout property set on server side is 5 seconds.
     2. I'm waiting for 20 seconds in GetData() method on server side before returning the data.
     3. I'm waiting for 10 seconds on client side before sending another request.

    The application works fine without any exception. Ideally, in my opinion, it should throw an exception (as per my understanding from the definition of MSDN for receiveTimeout).

    Thoughts anyone?

    Thanks!
    Sunday, April 13, 2014 5:16 AM

Answers

  • Hi,

    The receiveTimeout means that gets or sets the interval of time that a connection can remain inactive, during which no application messages are received, before it is dropped.

    For example if the receiveTimeout is 10min , then if the client and server are in a connection, but during a time, the client and the server has no data transfer. Then the connection will remain 10min, after the 10min if the client and server still has no data transfer, then the server will drop the connection. So the callback time should in 10min, or it will cause a timeoutException.

    But one thing you should remember is that it will always use in the WSDualHttpBinding, NetTcpBinding, NetNamedPipeBinding, because the it is suitable for the callback service and client.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 21, 2014 8:23 AM
    Moderator
  • Thank you Amy.
    Saturday, May 10, 2014 1:37 PM

All replies

  • the way you are trying to "simulate" time out is wrong. you are simply sleeping in-between calls to the service & not blocking the service itself!

    in fact, this call should timeout:

    proxy.GetData()

    hope this helps!


    Sunday, April 13, 2014 5:48 AM
  • Thank you for your response Shreeharsh. 

    The call doesn't timeout. Do you have any pointers how I can simulate this to understand if what I have done is incorrect?

    Sunday, April 13, 2014 6:25 AM
  • try putting a break point at the service side & do not continue execution - I mean let it just "stay" for some time in that method itself, this should do it.

    hope this helps!

    Sunday, April 13, 2014 7:13 AM
  • I'm afraid, it doesn't work.

    I searched through some of the forums and it seems I got it all wrong!

    "When client initiates the call to server, the client side sendTimeout and server side receiveTimeout are in effect. The client has to send(or push) all the data before receiveTimeout set on server expires. The server has to complete its operation and return the results back to client before the sendTimeout set on the client expires."

    So to simulate this, I need to pass a large amount of data to server side and decrease the receiveTimeout. This should do the trick.

    What do you think?

    Sunday, April 13, 2014 11:56 AM
  • Hi,

    The receiveTimeout means that gets or sets the interval of time that a connection can remain inactive, during which no application messages are received, before it is dropped.

    For example if the receiveTimeout is 10min , then if the client and server are in a connection, but during a time, the client and the server has no data transfer. Then the connection will remain 10min, after the 10min if the client and server still has no data transfer, then the server will drop the connection. So the callback time should in 10min, or it will cause a timeoutException.

    But one thing you should remember is that it will always use in the WSDualHttpBinding, NetTcpBinding, NetNamedPipeBinding, because the it is suitable for the callback service and client.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 21, 2014 8:23 AM
    Moderator
  • Thank you Amy.
    Saturday, May 10, 2014 1:37 PM