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