2014-11-08 80 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> 

請看看它讓你覺得麻煩給我認識激活它。