【发布时间】:2018-03-30 10:30:07
【问题描述】:
我正在尝试在 WCF 服务中测试超时配置。我希望服务根据配置或代码中的设置使请求超时。 WCF 客户端(即 Web 应用程序示例)具有与预期类似的配置超时,但我希望服务本身遵守设置和超时。
以多种方式对此进行了测试。
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 应用程序上的类似行为,即使在达到配置时间后服务也不会超时。
-->感谢任何反馈
【问题讨论】:
-
有人有机会看看这个吗?
标签: web-services wcf