【发布时间】:2014-10-15 05:53:55
【问题描述】:
我正在开发一个 WCFService (C#),它是外部公司提供的外部 Web 服务的“包装器”。 myService 和 exterService 之间的连接在我的客户端提供的开发机器和测试服务器上就像一个魅力 - 问题从生产服务器开始 - 当我上传我的服务并从网站调用它时,它只需要几个调用,然后外部服务开始抛出超时- 在我的原始代码中,我使用了 using 指令,但在阅读了一些类似的问题线程后,我将其更改为使用 .Close 服务客户端。不幸的是,它没有帮助。你能帮帮我吗?
这是调用外部服务的代码。
public static ExternalResponse RunAskQuestionBasicQuery(ExternalRequest request, string innerTransId)
{
ExternalResponse resp = null;
ExternalTestSoapClient client = new ExternalTestSoapClient("ExternalTestSoap12");
Logger.GetInstance().Log(innerTransId, "ExternalTestSoapClient created.");
try
{
Logger.GetInstance().Log(innerTransId, "AskQuestion() calling...");
resp = client.AskQuestion(request.SearchNumber, User, Password);
Logger.GetInstance().Log(innerTransId, "AskQuestion() called.");
client.Close();
Logger.GetInstance().Log(innerTransId, "ExternalTestSoapClient closed.");
}
catch (CommunicationException)
{
client.Abort();
resp = null;
SetError(bvResp, "External service is not accessible.");
Logger.GetInstance().Log(innerTransId, "ExternalTestSoapClient aborted [CommunicationException].");
}
catch (TimeoutException)
{
client.Abort();
resp = null;
SetError(bvResp, "External service is not accessible.");
Logger.GetInstance().Log(innerTransId, "ExternalTestSoapClient aborted [TimeoutException].");
}
catch (Exception ex)
{
Logger.GetInstance().Log(innerTransId, ex.Message);
throw;
}
}
在一些电话之后,我开始出现超时。
【问题讨论】:
-
查看异常的消息是什么以及任何内部异常详细信息可能会有所帮助。
-
开发/测试是否使用与生产环境不同的外部服务端点?如果不一样则说明生产环境的外部服务有问题,需要联系供应商。
-
几次通话后的超时让我认为连接没有被关闭并且您正在达到 maxConcurrentSessions (我认为默认为 10)。您是否成功记录了“ExternalTestSoapClient closed”?
-
@ShellShock - 不幸的是它是完全相同的端点。
-
@ajg - 我们确实成功记录了“ExternalTestSoapClient closed”。而且不是 10 次调用——有时是 12 次,有时是 14 次,今天早上超过 20 次。我们在调用 .Close() 后添加了客户端的 .State 日志记录——它似乎开始工作了。我将不得不等到下午服务器负载更高时 - 也许它会再次开始失败 - 我越来越困惑。如果下午开始失败 - 我将粘贴日志。
标签: c# web-services wcf timeout