【问题标题】:CLR webservice call times out at 100 secondsCLR Web 服务调用超时 100 秒
【发布时间】:2011-04-08 23:20:27
【问题描述】:

我在任何地方都没有找到答案。我有一个 CLR 函数,可以执行我的 .NET 应用程序 (.asmx) 的 webmethod 调用。直接调用 Web 服务成功执行,但通过 CLR 调用时,它会在 100 秒后超时,并出现以下错误:

Msg 6522, Level 16, State 1, Line 1
A .NET Framework error occurred during execution of user-defined routine or aggregate "fn_ExecuteReport":
System.Net.WebException: The operation has timed out
System.Net.WebException:
   at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
   at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
   at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   at DD.WebServices.WebExec.ExecuteReport(String ddBotID, String serverKey, Int32 ddUserID, String reportReportTypeList, String deliverToUserList)
   at ExecuteReport.GetResult(Int32 userID, SqlString reportList, SqlString deliverToUserList)

我在 fn_ExecuteReport 中增加了 Web 服务代理超时,但没有效果:

WebExec svc = new WebExec();<br/>
svc.Timeout = 3600000;  // set timeout to 1 hour<br/>
result = svc.ExecuteReport(userID, reportTypeList.ToString(),
                           deliverToUserList.ToString());

我想捕获返回的结果,所以异步执行 web 服务不是一个解决方案。我还可以在哪里覆盖 SQL CLR 调用的超时设置?感谢您提供的任何帮助。

这是函数的代码。我能够执行 web 服务,超时仅在通过 CLR 执行时发生。

ALTER FUNCTION [dbo].[fn_ExecuteReport]
(@UserID int, @ReportTypeList nvarchar(max), @DeliverToUserList nvarchar(max)) 
RETURNS [nvarchar](255) 
WITH EXECUTE AS CALLER AS EXTERNAL NAME [MyCLRLib].[ExecuteReport].[GetResult] 

我在 CLR 函数中尝试了对 Web 服务的同步和异步调用,都以 100 秒超时结束。这是我尝试过的两个电话:

同步:
WebExec svc = new WebExec(); svc.Timeout = 3600000; // 设置超时时间为 1 小时 结果 = svc.ExecuteReport(userID, reportTypeList.ToString(), deliverToUserList.ToString());

异步:
WebExec svc = new WebExec();
IAsyncResult 结果 = svc.BeginExecuteReport(userID, reportTypeList.ToString(), DeliverToUserList.ToString(), null, null);
结果.AsyncWaitHandle.WaitOne();
retStr = svc.EndExecuteReport(结果);

【问题讨论】:

  • 这只是函数的存根。把代码贴出来怎么样...
  • 我在上面添加了函数的胆量。我尝试过使网络服务调用同步和异步都没有成功。感谢您的关注。
  • " 我在上面添加了函数的胆量" - 在哪里?
  • 上面标记为“同步”和“异步”的两个部分是存根调用的“ExecuteReport”c# 类的核心。第一个是同步调用,所以我尝试将其更改为异步调用,但 CLR 在 100 秒后仍然超时,所以不是这段代码超时。 CLR 函数必须执行一个 WebRequest 来检索 Web 服务数据,而正是这个 WebRequest 似乎正在超时。我不确定这个检索代码是如何/在哪里生成的。
  • 出于几个原因(其中一个是超时问题),我决定构建一个小控制台应用程序来执行 Web 服务,而不是使用 SQL CLR。我仍然想知道如何通过 SQL CLR 调用长时间运行的 Web 服务调用,所以我会为任何能告诉我的人买啤酒。

标签: sql timeout clr webrequest


【解决方案1】:

您的错误消息表明超时源自 SQL Server。

您是否尝试过更新 SQL Server 统计信息(或重建索引)?

你能发布你的 CLR 函数的代码吗?

【讨论】:

  • 感谢您的回复。这是该功能的代码……不多。同样,我能够执行 web 服务,超时仅在通过 CLR 执行时发生。 ALTER FUNCTION [dbo].[fn_ExecuteReport](@UserID [int], @ReportTypeList [nvarchar](max), @DeliverToUserList [nvarchar](max)) RETURNS [nvarchar](255) WITH EXECUTE AS CALLER ASEXTERNAL NAME [MyCLRLib] .[ExecuteReport].[GetResult]
猜你喜欢
  • 2015-12-28
  • 1970-01-01
  • 2014-03-31
  • 2018-01-11
  • 2012-02-26
  • 2013-08-24
  • 2016-06-14
  • 1970-01-01
  • 2016-06-22
相关资源
最近更新 更多