110,568
社区成员
发帖
与我相关
我的任务
分享
定义一个绑定方法 这里使用的是tcp,实际根据你的情况
private static NetTcpBinding GetNetTcpBinding(bool TransactionFlow)
{
NetTcpBinding tcp = new NetTcpBinding();
tcp.TransactionFlow = TransactionFlow;
tcp.TransactionProtocol = System.ServiceModel.TransactionProtocol.WSAtomicTransactionOctober2004;
tcp.CloseTimeout = new TimeSpan(0, 1, 0);
tcp.OpenTimeout = new TimeSpan(0, 1, 0);
tcp.ReceiveTimeout = new TimeSpan(0, 20, 0);
tcp.SendTimeout = new TimeSpan(0, 1, 0);
tcp.TransferMode = TransferMode.Buffered;
tcp.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
tcp.MaxBufferPoolSize = int.MaxValue;
tcp.MaxBufferSize = int.MaxValue;
tcp.MaxReceivedMessageSize = int.MaxValue;
tcp.ReaderQuotas.MaxArrayLength = int.MaxValue;
tcp.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
tcp.ReaderQuotas.MaxDepth = 32;
tcp.ReaderQuotas.MaxNameTableCharCount = 16384;
tcp.ReaderQuotas.MaxStringContentLength = int.MaxValue;
tcp.MaxConnections = 10; //最大连接数
tcp.ListenBacklog = 10; //最大挂起
return tcp;
}
//定义一个终结点与地址:服务名需要根据发布的hex确定
EndpointAddress endadd = new EndpointAddress("net.tcp://服务器址址:端口/服务名");
//回调对象根据实际,有些没有
客户端引用对象 cilent = new TaskService.TaskServiceClient(回调对象, GetNetTcpBinding(true), endadd);
//若需要身份验证
NetworkCredential credential = cilent.ChannelFactory.Credentials.Windows.ClientCredential;
credential.UserName = "用户名";
credential.Password = "密码";
cilent.方法()