Finally, I found that it was the problem of the login user I served. I used LOCAL SERVICE, so I did not have access rights
Using WCF NetTCPBinding Transport security mode, the channel cannot be opened between the client and the server
I have one client machine and two server machines. The system of the server machine is the same.
Server machine
Windows Server 2019 Standard, Version:1809
.Net Framework 4.7 Advanced Service -> TCP Port Sharing open
Client machine
Windows 11 Pro, Version: 21H2
.Net Framework 4.8 Advanced Service -> TCP Port Sharing open
Questions:
The problem I encountered is that one of the two server machines cannot communicate with the client. I checked that the binding port and address are correct and the machine is in the same domain. I don't know what account Windows uses to establish communication. Is there any way to know? Why can't I open the channel? The socket connection was aborted when the client executed channel.Open
The problem I encountered is that one of the two server machines cannot communicate with the client. I don't know what account Windows uses to establish communication. Is there any way to know? Why can't I open the channel? The socket connection was aborted when the client executed channel.Open()
What I do
I checked that the binding port and address are correct and the machine is in the same domain. If I change Client to bindings. Security. Mode=SecurityMode. None; Then you can connect to the server machine that failed to connect before, so I suspect that the Windows permissions of this machine have special settings, but I don't know where to find the settings.
The WCF client side code is as follows
//Client side code:
NetTcpBinding bindings = new NetTcpBinding;
bindings.MaxReceivedMessageSize = 2147483647;
bindings.Security.Mode = SecurityMode.Transport;
string addr = "net.tcp://10.224.11.11:12345/MyTCPService";
EndpointAddress address = new EndpointAddresss(new Uri(addr), EndpointIdentity.CreateSpnIdentity(""));
ChannelFactory<MyTCPService.IDBAgent> myFactory = new ChannelFactory<MyTCPService.IDBAgent>(bindings, address);
MyTCPService.IDBAgent channel = myFactory.CreateChannel();
CommunicationState state = ((IClientChannel)channel).State;
if (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);