C# WCF 中的超时问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1341114/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Time out issue in WCF
提问by priyanka.sarkar
I am having time out issue in WCF.
我在 WCF 中遇到超时问题。
The following is the error:
以下是错误:
{"The request channel timed out while waiting for a reply after 00:00:59.9843744. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout."}
{"请求通道在 00:00:59.9843744 之后等待回复时超时。增加传递给请求调用的超时值或增加绑定上的 SendTimeout 值。分配给此操作的时间可能是更长的超时时间。"}
After searching in google, I found the solution
在谷歌搜索后,我找到了解决方案
from this site
从这个网站
http://social.msdn.microsoft.com/Forums/en-US/peertopeer/thread/38306972-3128-4f0c-937b-5d162d4d8e74
http://social.msdn.microsoft.com/Forums/en-US/peertopeer/thread/38306972-3128-4f0c-937b-5d162d4d8e74
So I changed accordingly my app.config file
所以我相应地改变了我的 app.config 文件
<behavior name="ContactServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="1000000000"/>
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="100"
maxConcurrentSessions="100"
maxConcurrentInstances="100"/>
</behavior>
What is the solution?
解决办法是什么?
采纳答案by Andrew Harry
The forum post you mention is a red herring. The error message clearly states that you need to increase the timeout property in the WCF client and service. (if you change it in the service I have found that it doesn't always get picked up by the client when it is updated)
你提到的论坛帖子是一个红鲱鱼。该错误消息明确指出您需要增加 WCF 客户端和服务中的超时属性。(如果您在服务中更改它,我发现它在更新时并不总是被客户端接收)
In Visual studio goto the Tools menu, there you will find the 'WCF Service Configuration Editor'. Load your projects web.config and define a new Binding for your service.
在 Visual Studio 中,转到“工具”菜单,您将在那里找到“WCF 服务配置编辑器”。加载您的项目 web.config 并为您的服务定义一个新的绑定。
The setting to change is the SendTimeout value. It is 60 seconds by default.
要更改的设置是 SendTimeout 值。默认为 60 秒。
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WCFBinding" sendTimeout="00:02:00">
</binding>
</basicHttpBinding>
</bindings>
回答by ShawnFeatherly
If you want to handle the timeout, you can wrap the client side call of the WCF service in a try/catch block.
如果要处理超时,可以将 WCF 服务的客户端调用包装在 try/catch 块中。
There's a trick here, if you don't have a debugger attached, a timeout will cause the catch block to be executed. However, if you do have a debugger attached, the debugger intercepts the error before it gets to the catch block.
这里有一个技巧,如果您没有附加调试器,超时将导致执行 catch 块。但是,如果您确实附加了调试器,则调试器会在错误到达 catch 块之前拦截错误。