简体   繁体   English

设置WCF数据服务超时

[英]Setting timeout for WCF Dataservice

I was struggling with some timeouts for an OData service. 我为OData服务的某些超时而苦苦挣扎。 My first idea was to change the timeout property but I could not find the correct place to do this. 我的第一个想法是更改timeout属性,但是我找不到正确的位置。 Where should be the request timeout set and how?, is there any best practice?. 请求超时应该在哪里设置?如何设置?有没有最佳实践?

If you are using the ODataClient (DataServiceContext), it has a Timeout property that one can set. 如果您使用的是ODataClient(DataServiceContext),则它具有一个可以设置的Timeout属性。 If you are using your own client, then it depends on what technology you are using to send the request - HttpWebClient, HttpListener, HttpClient, etc. They all have properties to set appropriate Timeout. 如果您使用自己的客户端,则取决于您使用哪种技术发送请求-HttpWebClient,HttpListener,HttpClient等。它们都具有设置适当超时的属性。

Hope this helps. 希望这可以帮助。 Thanks Pratik 感谢Pratik

Not sure about an OData service, but normally the send and receive timeout properties are set on the binding itself. 不确定OData服务,但通常在绑定本身上设置发送和接收超时属性。 I use BasicHTTPBinding for my web service and, on the host, the binding is set this way (in code): 我将BasicHTTPBinding用于我的Web服务,并且在主机上,以这种方式(在代码中)设置绑定:

BasicHttpBinding b = default(BasicHttpBinding);
b = new BasicHttpBinding(BasicHttpSecurityMode.None);
dynamic specialTimeSpan = new TimeSpan(0, 30, 0);
b.CloseTimeout = specialTimeSpan;
b.ReceiveTimeout = specialTimeSpan;
b.SendTimeout = specialTimeSpan;
b.OpenTimeout = specialTimeSpan;

So that would set the close, open, receive and send timeouts to 30 minutes. 这样可以将关闭,打开,接收和发送超时设置为30分钟。

In a config file deployment, it would be something like this: 在配置文件部署中,将如下所示:

<basicHttpBinding>
  <binding 
   closeTimeout="00:30:00" 
   openTimeout="00:30:00" 
   receiveTimeout="00:30:00"
   sendTimeout="00:30:00"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM