Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change timeout for each WCF method or call

I have a quite large "old" WCF Service with many different methods.

The most of these methods are "normal" so they should answer in less than 10 seconds but there are several methods (8 or 9) that are long processes so they can take a long time to get a response.

The receivetimeout and sendtimeout were set to 00:40:00 to ensure they had time enought to accomplish these processes.

The problem is sometimes we have connection issues and the "normal" methods take a really long time to crash...

They are all in the same service because they use a really big model and they wanted to reuse the model from the service in every call (not having a PersonsService.User and a RobotsService.User... because they are the same class in different services).

The first solution I imagine is to make a different Service with those long processes and set a short timeout to the normal service... but I should have to make a lot of changes because of Model use...

Is there any way to set a different timeout in each call? Or by service method? Should I chunk the Service anyway?

Thanks in advance!!

like image 236
zapico Avatar asked Oct 18 '12 12:10

zapico


People also ask

How to set timeout in WCF service?

OpenTimeout = new TimeSpan(0, 10, 0); binding. CloseTimeout = new TimeSpan(0, 10, 0); binding. SendTimeout = new TimeSpan(0, 10, 0); binding. ReceiveTimeout = new TimeSpan(0, 10, 0); serviceHost.

How can I increase my response time in WCF?

Under the Tools menu in Visual Studio 2008 (or 2005 if you have the right WCF stuff installed) there is an options called 'WCF Service Configuration Editor'. From there you can change the binding options for both the client and the services, one of these options will be for time-outs.

What is the default timeout for WCF service?

The default is 00:10:00. This setting is only used on the server-side and has no effect on client-side.

What is SendTimeout?

SendTimeout – used to initialize the OperationTimeout, which governs the whole process of sending a message, including receiving a reply message for a request/reply service operation. This timeout also applies when sending reply messages from a callback contract method.


Video Answer


1 Answers

First of all, the timeout to configure in your case is OperationTimeout, which allows the time limit to wait for the service to reply before timing out. You can modify the operation timeout before making a call from the client side.

To set the OperationTimeout on the channel, you can type case your proxy/channel instance as IContextChannel and set OperationTimeout.

For example:

IClientChannel contextChannel = channel as IClientChannel;
contextChannel.OperationTimeout = TimeSpan.FromMinutes(10);

HTH, Amit

like image 165
amit Avatar answered Sep 24 '22 20:09

amit