2010-07-28 186 views
-1
try 
{ 
    String endPointAddr = "net.tcp://localhost:8000/MyService"; 
    NetTcpBinding tcpBinding = new NetTcpBinding(); 
    tcpBinding.TransactionFlow = false; 
    tcpBinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign; 
    tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows; 
    tcpBinding.Security.Mode = SecurityMode.None; 

    EndpointAddress endpointAddress = new EndpointAddress(endPointAddr); 

    Console.WriteLine("::::: WCF Service Demo :::::"); 
    Console.WriteLine("Attempt to connect to: " + endPointAddr); 


    ChannelFactory<IServices> WCF = new ChannelFactory<IServices>(tcpBinding, endpointAddress); 
    IServices proxy = WCF.CreateChannel(); 

    using (WCF as IDisposable) 
    { 
     Console.WriteLine("Connected to: " + endPointAddr); 
     Dictionary<long, DATALINK> dicDataLink = proxy.getDataLink(); 
     lblCTRGData.Text = dicTRGDataLink.Count.ToString(); 
    } 
} 
catch (Exception ex) 
{ 
    lblCTRGData.Text = ex.Message.ToString(); 
} 
Console.ReadLine(); 

如果字典有50到100條記錄但記錄大於該錯誤,則此代碼可以流暢地運行發生通信對象System.ServiceModel.Channels.ServiceChannel不能用於通信,因爲它處於Faulted狀態通信對象System.ServiceModel.Channels.ServiceChannel不能用於通信,因爲它處於Faulted狀態

+0

而你的問題是?您是否有機會在使用語句中使用代理編寫服務調用,並且該服務發生錯誤? – Paddy 2010-07-28 09:27:02

回答

2

沒有看到堆棧跟蹤或失敗的代碼,但聽起來您的wcf客戶端失敗某種原因導致它進入故障狀態,並且您正在嘗試再次使用它。或者你在代理中使用using語句。

Avoiding Problems with the Using Statement

+0

此博客文章提到了您提供的鏈接,但通過在WCF客戶端代理類中提供一個包裝並提供一個實現MSDN文章中代碼的Dispose方法,提供了一種備用解決方案。允許繼續使用using語句並集中修復,如果您必須在多個地方調用您的WCF客戶端。 http://blogs.msdn.com/b/jjameson/archive/2010/03/18/avoiding-problems-with-the-using-statement-and-wcf-service-proxies.aspx – 2011-12-05 23:31:49

相關問題