3
votes

I am trying to test time out configuration in WCF Service. I want the service to timeout a request based on the settings in config or code. WCF client (i.e. example a web application) with similar configuration timeouts as expected, but I want the service itself to honor the setting and timeout.

Tested this in couple of ways.

1.) IIS hosted WCF service with timeout listed in web.config

<bindings>
   <basicHttpBinding>
     <binding name="Service1Binding" closeTimeout="00:00:10" openTimeout="00:00:10" receiveTimeout="00:00:10" sendTimeout="00:00:10">
      <security mode="TransportWithMessageCredential">
        <message clientCredentialType="UserName"/>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service name="Service1">
    <endpoint address="Service1" binding="basicHttpBinding" bindingConfiguration="Service1Binding" name="IService1" contract="TestWcfTimeout.IService1" />
  </service>
</services>

2.) Self hosted WCF service with timeout listed in code

            using (var host = new ServiceHost(typeof(Service1), baseAddress))
            {
                var smb = new ServiceMetadataBehavior{ HttpGetEnabled = true, MetadataExporter = { PolicyVersion = PolicyVersion.Policy15 }};

                var endpoint = host.AddServiceEndpoint(typeof(IService1), new BasicHttpBinding(), baseAddress);
                endpoint.Binding.OpenTimeout = new TimeSpan(00, 00, 00, 10);
                endpoint.Binding.CloseTimeout = new TimeSpan(00, 00, 00, 10);
                endpoint.Binding.SendTimeout = new TimeSpan(00, 00, 00, 10);
                endpoint.Binding.ReceiveTimeout = new TimeSpan(00, 00, 00, 10);
                host.Description.Behaviors.Add(smb);
                host.Open();

                Console.WriteLine("The service is ready at {0}", baseAddress);
                Console.WriteLine("Press <Enter> to stop the service.");
                Console.ReadLine();

                host.Close();
            }

     [ServiceContract]
     public interface IService1
     {
        [OperationContract]
        string GetData(int value);
     }

Tested this using SoapUI client. Made sure the method GetData takes more time to complete execution than the configured time out. So the service can timeout the request.

--> But the service does not honor the timeout and client receives wcf response object even after reaching the timeout setting. Any idea?

Noticed similar behavior on a web application, where the service does not timeout even after reaching configuration time.

--> Any feedback is appreciated

1
Anyone got a chance to look at this? - Balwant

1 Answers

0
votes

Your web.config timeouts refer to the client's operations. What you were doing was setting your web service's attitude toward your client.

Based on your configuration, this means that if your client takes more than 10 seconds between e.g. two requests to your web service, your client will get a timeout exception because your web service will say "Hey! You exceeded the timeout in my web.config. You are late and I won't answer!".

Set the same timeouts in your client's config and repeat your experiment, delaying GetData's response: then your client will throw an exception and discard your web service's response.

Now, if you are looking for a way to set a timeout service-side, so that your service stops processing a request if it exceeds a time limit... you will have to implement it yourself.