使用WCF NetTCPBinding Transport安全模式,客户端和服务器之间无法打通通道

问题描述 投票:0回答:1

我有一台客户端机器和两台服务器机器。服务器机器的系统是一样的。 服务器机器 Windows Server 2019 标准版,版本:1809 .Net Framework 4.7 高级服务 -> TCP 端口共享打开 客户端机器 Windows 11 专业版,版本:21H2 .Net Framework 4.8 高级服务 -> TCP 端口共享打开 WCF客户端代码如下 //客户端代码: NetTcpBinding 绑定 = 新的 NetTcpBinding; bindings.MaxReceivedMessageSize = 2147483647; bindings.Security.Mode = SecurityMode.Transport; string addr = "net.tcp://10.224.11.11:12345/MyTCPService"; EndpointAddress 地址 = new EndpointAddresss(new Uri(addr), EndpointIdentity.CreateSpnIdentity("")); ChannelFactory myFactory = new ChannelFactory(绑定, 地址); MyTCPService.IDBAgent 通道 = myFactory.CreateChannel(); CommunicationState 状态 = ((IClientChannel)channel).State; 如果(状态 == CommunicationState.Created) { ((IClientChannel)channel).Open(); }

//Server side code: 
string addr = "net.tcp://localhost:12345/MyTCPService";
ServiceHost serHost = new ServiceHost(typeof(DataAgent), new Uri(addr));
NetTcpBinding bindings = new NetTcpBinding;
bindings.CloseTimeout = TimeSpan.Parse("00:01:00");
bindings.OpenTimeout = TimeSpan.Parse("00:01:00");
bindings.ReceiveTimeout = TimeSpan.Parse("00:01:00");
bindings.SendTimeout = TimeSpan.Parse("00:01:00");
bindings.TransactionFlow = false;
bindings.TransferMode = TransferMode.Buffered;
bindings.MaxBufferPoolSize = 1024;
bindings.MaxBufferSize = 1073741824;
bindings.MaxReceivedMessageSize = 1073741824;
bindings.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
bindings.ReaderQuotas.MaxDepth = 64;
bindings.ReaderQuotas.MaxArrayLength = 2147483647;
bindings.ReaderQuotas.MaxStringContentLength = 2147483647;
bindings.ReaderQuotas.MaxNameTableCharCount = 2147483647;
bindings.ReaderQuotas.MaxBytesPerRead = 2147483647;
bindings.ReliableSession.InactivityTimeout = TimeSpan.Parse("00:05:00");
bindings.ReliableSession.Ordered = true;
bindings.ReliableSession.Enabled = false;
bindings.Security.Mode = SecurityMode.Transport;

ServiceThrottlingBehavior throttling = new ServiceThrottlingBehavior
{
    MaxConcurrentCalls = 500,
    MaxConcurrentInstances = 500,
    MaxConcurrentSessions = 500
};

ServiceMetadataBehavior metadata = new ServiceMetadataBehavior
{
    HttpGetEnabled = false
};
serHost.Description.Behaviors.Add(throttling);
serHost.Description.Behaviors.Add(metadata);
serHost.AddServiceEndpoint(typeof(IDBAgent), bindings, addr);
serHost.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexTcpBindings(), addr);

问题: 我遇到的问题是两台服务器机器中的一台无法与客户端通信。我检查了绑定端口和地址是否正确,并且机器在同一个域中。我不知道 Windows 使用什么帐户建立通信。有什么方法可以知道吗?为什么我打不开频道?当客户端执行通道 Open() 函数时,套接字连接被中止 有没有办法获取Windows认证的证书名称,以便我检查WCF的客户端和服务器是否匹配证书? 我做什么 我检查了绑定端口和地址是否正确,并且机器在同一个域中。如果我将客户端更改为绑定安全模式为无;然后就可以连接到之前连接失败的服务器机器了,所以我怀疑这台机器的Windows权限有特殊设置,但是不知道去哪里找设置。

c# wcf
1个回答
0
投票

错误信息是:套接字连接被中止。这可能是由于处理您的消息时出错或远程主机超过接收超时或底层网络资源问题引起的。

© www.soinside.com 2019 - 2024. All rights reserved.