【问题标题】:.NET Web Service (asmx) Timeout Problem.NET Web 服务 (asmx) 超时问题
【发布时间】:2011-03-05 02:42:09
【问题描述】:

我正在连接到供应商提供的 Web ASMX 服务并通过网络发送一组数据。当您向项目添加服务引用时,我的第一次尝试达到了 Visual Studio 默认在 app.config 文件中引发的 1 分钟超时。我把它增加到 10 分钟,又一次超时。 1 小时,又一次超时:

Error: System.TimeoutException: The request channel timed out while waiting for
a reply after 00:59:59.6874880. 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. ---> System.TimeoutE
xception: The HTTP request to 'http://servername/servicename.asmx' has exceeded the allotted timeout of 01:00:00. The time allotted to this
operation may have been a portion of a longer timeout. ---> System.Net.WebExcept
ion: The operation has timed out
   at System.Net.HttpWebRequest.GetResponse() [... lengthly stacktrace follows]

我联系了供应商。他们确认通话可能需要一个多小时(不要问,他们是我存在的祸根。)为了安全起见,我将超时时间增加到 10 小时。但是,Web 服务调用在 1 小时后继续超时。相关的 app.config 部分现在如下所示:

   <basicHttpBinding>
    <binding name="BindingName" closeTimeout="10:00:00"
                    openTimeout="10:00:00" receiveTimeout="10:00:00" sendTimeout="10:00:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
     <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="2147483647"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
     <security mode="None">
      <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
      <message clientCredentialType="UserName" algorithmSuite="Default" />
     </security>
    </binding>
   </basicHttpBinding>

相当荒谬,但无论如何超时仍然在 1 小时开始。不幸的是,每次更改都需要至少额外的一个小时来测试。我是否遇到了一些内部限制 - 另一个超时设置要在某处更改?对这些设置的所有更改最长一小时都达到了预期效果。

感谢您提供的任何帮助!

【问题讨论】:

  • 当它在一小时内启动时,它与您在设置超时时间为 1 分钟时遇到的异常完全相同吗?

标签: .net wcf web-services timeout wcf-client


【解决方案1】:

首先: 请参阅 Steven Cheng[MSFT] 回复 here 关于超时。您可以为 httpRuntime 设置执行超时。之后他说了一些有趣的话,那就是“另外,请确保您已将 'compilation debug="false"' 设置为 使超时正常工作

除了它们可能出现严重错误(或者返回的数据如此庞大/我不打算判断 - 可能是一个很好的理由)之外,您是否尝试过异步调用它们的操作?结果一样吗?我想这需要一个小时

YourVendor.WebService ws = new YourVendor.WebService();
ws.LongRunningOperationCompleted += new YourVendor.LongRunningOperationEventHandler(ws_LongRunningOperationCompleted);

ws.LongRunningOperationAsync();

// Implement the ws_LongRunningOperationCompleted handler (stub will auto generate)

完成的事件处理程序将有一个特定的事件args参数,其中将包含结果,对于事件args e,e.Result应该在它完成时具有你所需要的。

【讨论】:

  • 客户端的 web.config 文件没有 httpRuntime 元素,所以我添加了一个超时非常大的文件,然后再次启动它。一个小时后见,谢谢!
  • 至于异步选项,我可以打开引擎盖并将调用更改为异步。那些通常更能容忍超时,它们的执行方式不同吗?数据量不是很大,但在返回结果之前必须在另一端进行处理,而编写处理代码的人并没有关注超过一定数据大小的性能。
  • @BarryFandango:嗨,Barry,你是如何解决这个问题的?我已将 httpRuntime 超时设置为一个较大的值,并将编译调试设置为 false。 1 小时后仍然出现相同的错误
  • MichaelS,很遗憾,我对你没有任何指导。我又为这个问题苦苦挣扎,但没有任何结果,但我们最终让供应商感到羞愧,修复了他们的 Web 服务,因此它在更合理的时间内运行。
  • +1 表示“羞辱供应商”。如果我能将这种策略与 SAP/Crystal Reports 一起使用就好了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-23
  • 1970-01-01
  • 2012-02-26
  • 2011-12-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多