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不能用于通信,因为它处于故障状态
答案 0 :(得分:2)
没有看到堆栈跟踪或失败的代码,但听起来你的wcf客户端由于某种原因而失败,因为某些原因导致它进入故障状态并且你试图再次使用它。或者您正在使用代理的using语句。