.NET Web Service(asmx)超时问题

6

我正在连接一个供应商提供的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小时以确保安全。然而,网络服务调用仍然在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分钟时完全相同? - John Saunders
1个回答

4

首先:关于超时问题,请查看Steven Cheng[MSFT]的回复这里。您可以为httpRuntime设置执行超时时间。之后他说了一些有趣的话:“而且,请确保将编译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)

完成的事件处理程序将具有特定的事件参数param,其中将包含结果。对于事件参数e,当它完成时,e.Result应该包含您需要的内容。

客户端的web.config文件没有httpRuntime元素,因此我添加了一个具有非常长超时时间的元素,然后再次启动它。谢谢!一个小时后再看看吧。 - James Orr
关于async选项,我可以打开引擎盖并将调用更改为async。它们通常对超时更容忍吗?它们执行方式不同吗?数据量不是太大,但必须在返回结果之前在另一端进行处理,而编写处理代码的人没有考虑过某个数据大小以外的性能问题。 - James Orr
@BarryFandango:嗨,Barry,你是怎么解决这个问题的?我已经将httpRuntime超时时间设置为很大的值,并将编译调试设置为false。但仍然在1小时后出现相同的错误。 - MichaelS
1
MichaelS,很抱歉我没有任何指导给你。我继续努力解决这个问题,但最终我们成功地让供应商感到羞耻并修复了他们的网络服务,使其运行时间更加合理。 - James Orr
+1 for "shaming the vendor." 如果我能让这种策略在SAP/Crystal Reports上奏效,那就太好了。 - RLH

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接