2014-11-08 78 views
1

我编写c#代码,以动态连接到WCF服务器。如果连接少于1分钟,那么它就是完美的。但是,如果远程功能工作超过1-2分钟,则抛出异常。这是我的代码:动态WCF客户端不会等待超过一分钟

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

例外:

Error:System.ServiceModel.FaultException: The server was unable to process the request due to an internal error. 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.

那么,它是如何解决?

回答

0

尝试打开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> 

请看看它让你觉得麻烦给我认识激活它。