我想在WCF服务中测试超时配置。我希望服务根据配置或代码中的设置超时请求。 WCF客户端(例如Web应用程序)具有与预期类似的配置超时,但我希望服务本身遵守设置和超时。WCF服务不遵守超时配置
以几种方式对此进行了测试。
1)IIS带超时承载WCF服务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.)自托管与超时WCF服务代码
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);
}
列出
使用SoapUI客户端进行测试。确保GetData方法比配置的超时花费更多的时间来完成执行。所以服务可以超时请求。
- >但是,该服务并未兑现超时,即使在达到超时设置后,客户端也会收到wcf响应对象。任何想法?
注意到Web应用程序中的类似行为,即使在达到配置时间后服务仍未超时。
- >任何意见表示赞赏
任何人都有机会看到这个? – Balwant