C# 几次呼叫后呼叫服务超时

C# 几次呼叫后呼叫服务超时,c#,web-services,wcf,timeout,C#,Web Services,Wcf,Timeout,我正在开发一个WCFService C,它是外部公司提供的外部Web服务的“包装器”。myService和exterService之间的连接在我的客户机提供的开发机器和测试服务器上就像一个符咒一样工作-问题从生产服务器开始-当我上传我的服务并从网站调用它时,它只工作了几个调用,而外部服务开始超时-在我使用指令的原始代码中,但在阅读了一些类似的问题线程后,我将其改为使用。关闭服务客户端。不幸的是,这没有帮助。你能帮我一下吗 这是调用外部服务的代码 public static ExternalRes

我正在开发一个WCFService C,它是外部公司提供的外部Web服务的“包装器”。myService和exterService之间的连接在我的客户机提供的开发机器和测试服务器上就像一个符咒一样工作-问题从生产服务器开始-当我上传我的服务并从网站调用它时,它只工作了几个调用,而外部服务开始超时-在我使用指令的原始代码中,但在阅读了一些类似的问题线程后,我将其改为使用。关闭服务客户端。不幸的是,这没有帮助。你能帮我一下吗

这是调用外部服务的代码

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;
        }
 }

在一些调用之后,我就开始超时了。

我真的看不出你的代码有什么问题,尽管这并不重要,因为你每次都会创建一个新的客户端,但我不确定是否有一个静态方法调用WCF服务

我最幸运的是WCF使用了这种模式——它非常接近你的模式,只是将关闭移动到最后一个块中

public 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.");           
        return resp;
    }
    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;
    }
    finally
    {
        if (client.State == CommunicationState.Opened)
        {
            client.Close();
            Logger.GetInstance().Log(innerTransId, "ExternalTestSoapClient closed.");
        }
    }
}

查看异常消息和任何内部异常详细信息可能会有所帮助。dev/test是否使用与生产环境不同的外部服务端点?如果不同,则表明生产环境中的外部服务存在问题,您需要联系提供商。几次呼叫后超时,我认为连接没有关闭,您正在点击maxConcurrentSessions默认值10。您是否成功记录了“ExternalTestSoapClient closed”日志?@ShellShock-很遗憾,它与端点完全相同。@ajg-我们成功记录了“ExternalTestSoapClient closed”。不是10个电话,有时是12个,有时是14个,今天早上是20多个。我们在调用.Close之后添加了客户端.State的日志记录,它似乎开始工作了。我将不得不等到下午,当服务器负载更高的时候——也许它会再次失败——我越来越困惑。如果下午开始失败,我将粘贴日志。