简体   繁体   English

动态WCF客户端等待时间不超过一分钟

[英]Dynamic WCF client doesn't wait more than one minute

I write c# code, to dynamic connect to WCF server. 我编写C#代码,以动态连接到WCF服务器。 If connect will less that 1 minutes it's work perfect. 如果连接少于1分钟,则说明工作正常。 But if remote function work more than 1-2 minutes, it's throw exception. 但是,如果远程功能工作超过1-2分钟,则会抛出异常。 This is my code: 这是我的代码:

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

Exception: 例外:

Error:System.ServiceModel.FaultException: The server was unable to process the request due to an internal error. 错误:System.ServiceModel.FaultException:服务器由于内部错误而无法处理请求。 For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs. 有关错误的更多信息,请打开服务器上的IncludeExceptionDetailInFaults(从ServiceBehaviorAttribute或从配置行为),以便将异常信息发送回客户端,或者按照Microsoft .NET Framework SDK文档和检查服务器跟踪日志。

So, how it's fix? 那么,如何解决?

try to turn on IncludeExceptionDetailInFaults in web.config file to see the exact error. 尝试在web.config文件中打开IncludeExceptionDetailInFaults以查看确切的错误。 and this is possible duplicate of 这可能是重复的

Turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server 在服务器上打开IncludeExceptionDetailInFaults(通过ServiceBehaviorAttribute或<serviceDebug>配置行为)

This explain as follows, and it worked for me. 解释如下,它对我有用。 In your .config file define a behavior: 在您的.config文件中定义一个行为:

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

Then apply the behavior to your service along these lines: 然后按照以下方式将行为应用于您的服务:

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

Please look at it and let me know if you find trouble to activate it. 请查看它,如果您发现激活它的麻烦,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM