Web services WCF服务不遵守超时配置
我正在尝试测试WCF服务中的超时配置。我希望服务根据配置或代码中的设置超时请求。WCF客户端(例如web应用程序)具有与预期类似的配置超时,但我希望服务本身遵守设置和超时 通过两种方法对此进行了测试。 1。)web.config中列出了IIS托管的WCF服务超时时间Web services WCF服务不遵守超时配置,web-services,wcf,Web Services,Wcf,我正在尝试测试WCF服务中的超时配置。我希望服务根据配置或代码中的设置超时请求。WCF客户端(例如web应用程序)具有与预期类似的配置超时,但我希望服务本身遵守设置和超时 通过两种方法对此进行了测试。 1。)web.config中列出了IIS托管的WCF服务超时时间 <bindings> <basicHttpBinding> <binding name="Service1Binding" closeTimeout="00:00:10" openTim
<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);
}
使用(var-host=new-ServiceHost(typeof(Service1),baseAddress))
{
var smb=new serviceMataDatabehavior{HttpGetEnabled=true,MetadataExporter={PolicyVersion=PolicyVersion.Policy15};
var endpoint=host.AddServiceEndpoint(typeof(IService1),new BasicHttpBinding(),baseAddress);
endpoint.Binding.OpenTimeout=新的时间跨度(00,00,00,10);
endpoint.Binding.CloseTimeout=新的时间跨度(00,00,00,10);
endpoint.Binding.SendTimeout=新的时间跨度(00,00,00,10);
endpoint.Binding.ReceiveTimeout=新的时间跨度(00,00,00,10);
host.Description.Behaviors.Add(smb);
host.Open();
WriteLine(“服务在{0}处准备就绪”,基地址);
控制台。WriteLine(“按以停止服务”);
Console.ReadLine();
host.Close();
}
[服务合同]
公共接口IService1
{
[经营合同]
字符串GetData(int值);
}
使用SoapUI客户端测试了这一点。确保方法GetData完成执行所需的时间比配置的超时时间长。因此服务可以使请求超时
-->但服务不接受超时,即使在达到超时设置后,客户端也会收到wcf响应对象。有什么想法吗?
注意到web应用程序上的类似行为,其中服务即使在达到配置时间后也不会超时
-->欢迎任何反馈您的web.config超时指的是客户端的操作。您所做的是设置web服务对客户的态度 根据您的配置,这意味着如果您的客户端在两个web服务请求之间的间隔时间超过10秒,您的客户端将出现超时异常,因为您的web服务会说“嘿!您在my web.config中超过了超时时间。您迟到了,我不会回答!” 在客户端的配置中设置相同的超时并重复实验,延迟GetData的响应:然后客户端将抛出异常并放弃web服务的响应
现在,如果您正在寻找一种方法来设置超时服务端,以便您的服务在超过时间限制时停止处理请求 有人有机会看看这个吗?