【问题标题】:Dynamic WCF client doesn't wait more than one minute动态 WCF 客户端不会等待超过一分钟
【发布时间】:2015-01-05 07:00:11
【问题描述】:

我编写 C# 代码,以动态连接到 WCF 服务器。如果连接不到 1 分钟,那就完美了。但是如果远程功能工作超过 1-2 分钟,就会抛出异常。这是我的代码:

try
{
    BasicHttpBinding basicHttpBinding = new BasicHttpBinding()
    {
        CloseTimeout = TimeSpan.FromMinutes(20),
        OpenTimeout = TimeSpan.FromMinutes(20),
        ReceiveTimeout = TimeSpan.FromMinutes(10),
        SendTimeout = TimeSpan.FromMinutes(10)
    };
    EndpointAddress endpointAddress = new EndpointAddress("http://***");
    IBrowserClicker personService = new ChannelFactory<IBrowserClicker>(basicHttpBinding, endpointAddress).CreateChannel();
    Console.WriteLine(personService.TestConnect().Equals("Hello google!"));
}
catch (Exception exception)
{
    Console.WriteLine("Error:"+exception);
}

例外:

错误:System.ServiceModel.FaultException:由于内部错误,服务器无法处理请求。有关该错误的更多信息,请在服务器上打开 IncludeExceptionDetailInFaults(来自 ServiceBehaviorAttribute 或来自配置行为)以便将异常信息发送回客户端,或者根据 Microsoft .NET Framework SDK 文档打开跟踪并检查服务器跟踪日志。

那么,它是如何解决的?

【问题讨论】:

    标签: c# wcf


    【解决方案1】:

    尝试在 web.config 文件中打开 IncludeExceptionDetailInFaults 以查看确切的错误。这可能是

    Turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server

    这解释如下,它对我有用。 在您的 .config 文件中定义一个行为:

    <configuration>
     <system.serviceModel>
       <serviceBehaviors>
         <behavior name="debug">
         <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
    ...
    

    然后按照以下方式将行为应用于您的服务:

    <configuration>
      <system.serviceModel>
         ...
      <services>
          <service name="MyServiceName" behaviorConfiguration="debug">
       </services>
    </system.serviceModel>
    </configuration>
    

    请查看它,如果您在激活它时遇到问题,请告诉我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-21
      • 1970-01-01
      • 2016-10-10
      相关资源
      最近更新 更多