简体   繁体   中英

Setting timeout for WCF Dataservice

I was struggling with some timeouts for an OData service. My first idea was to change the timeout property but I could not find the correct place to do this. 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. 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.

Hope this helps. Thanks Pratik

Not sure about an OData service, but normally the send and receive timeout properties are set on the binding itself. I use BasicHTTPBinding for my web service and, on the host, the binding is set this way (in code):

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.

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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