C# 为 .NET Web 服务设置超时值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/711311/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 14:22:40  来源:igfitidea点击:

Setting Timeout Value For .NET Web Service

c#.netweb-servicestimeout

提问by

I have a web service written in C# that is living on a SharePoint site. I have modified the web.config with the following code:

我有一个用 C# 编写的 Web 服务,它存在于 SharePoint 网站上。我使用以下代码修改了 web.config:

<configuration>
  <system.web>
    <httpRuntime executionTimeout="360" />

...

...

for the IIS Inetpub file, the SP ISAPI web.config file and the SP layouts web.config. I have also modified the machine.config file with the same code and tried to bump any timeouts that I see in IIS.

对于 IIS Inetpub 文件、SP ISAPI web.config 文件和 SP 布局 web.config。我还使用相同的代码修改了 machine.config 文件,并尝试改变我在 IIS 中看到的任何超时。

When I call this web service from a Windows C# application I can step into the web method and start debugging the variable but after a short time (~1 minute, maybe less) the variable values are no longer present because this gets returned:

当我从 Windows C# 应用程序调用此 Web 服务时,我可以进入 Web 方法并开始调试变量,但在很短的时间(约 1 分钟,可能更短)后,变量值不再存在,因为它被返回:

System.Net.WebException "The request was aborted: The operation has timed out."

System.Net.WebException “请求已中止:操作已超时。”

I am trying to figure out where the correct timeout values needs to be set and how. I restart IIS after I have made every change but nothing changes to give different results.

我想弄清楚需要在哪里设置正确的超时值以及如何设置。我在进行了所有更改后重新启动 IIS,但没有任何更改以产生不同的结果。

Thanks

谢谢

回答by Michael Kniskern

Try setting the timeout value in your web service proxy class:

尝试在您的 Web 服务代理类中设置超时值:

WebReference.ProxyClass myProxy = new WebReference.ProxyClass();
myProxy.Timeout = 100000; //in milliseconds, e.g. 100 seconds

回答by p_champ

After creating your client specifying the binding and endpoint address, you can assign an OperationTimeout,

创建指定绑定和端点地址的客户端后,您可以分配一个 OperationTimeout,

client.InnerChannel.OperationTimeout = new TimeSpan(0, 5, 0);