6

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!!

zapico
  • 2,396
  • 1
  • 21
  • 45
  • 1
    are you recreating the proxy object for each call? if yes, see this link for a possible solution: http://stackoverflow.com/questions/1826392/programatically-set-wcf-timeout-in-debug-mode – wal Oct 18 '12 at 13:18
  • No I'm not, I've a singleton for the proxy. – zapico Oct 18 '12 at 14:24

1 Answers1

10

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

gotnull
  • 26,454
  • 22
  • 137
  • 203
amit
  • 2,093
  • 16
  • 10
  • And how do I configure this OperationTimeout?? Thanks for your answer :) – zapico Oct 18 '12 at 22:56
  • 3
    How do you do that in a thread-safe manner in the face of concurrent usage of the channel? Setting `client.InnerChannel.OperationTimeout` and then invoking the service from multiple threads does not work. But I know that the OperationTimeout setting gets read once at the start of the operation, and then that value remains constant for that invocation even though you change the channel's OperationTimeout. I just don't know where the right spot would be - if there is one - to make it work across threads. – Evgeniy Berezovsky Oct 29 '15 at 06:52