Change timeout for each WCF method or call

浪子不回头ぞ 提交于 2019-12-30 06:35:13

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/12954680/change-timeout-for-each-wcf-method-or-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!