To enable the Port Sharing Service in WCF, you only need to perform the following three steps:
Enable the NET. TCP Port Sharing Service (disabled by default)
The WCF Service adopts the TCP protocol.
Set PortSharingEnabled to true.
Step 1. Enable the NET. TCP Port Sharing Service
Go to "start"> "Control Panel"> "Administrative Tools"> Service, open the "Service dialog box" as shown in, and locate "Net. TCP Port Sharing Service.
Step 2: Use the TCP protocol in the WCF Service
In TCP-based WCF communication, we use NetTcpBinding to process all the communication details, including Port Sharing.
Step 3: Set PortSharingEnabled to true
In NetTcpBinding, a special attribute PortSharingEnabled is defined to indicate whether Port Sharing is enabled.
You can configure the PortSharingEnabled attribute of NetTcpBinding to enable the port for WCF:
- < bindings>
- < netTcpBinding>
- < binding name="PortBinding" portSharingEnabled="true" />
- < /netTcpBinding>
- < /bindings>
You can also enable binding by using code.
- NetTcpBinding binding = new NetTcpBinding();
- binding.PortSharingEnabled = true;
This binding implicitly allows external processes (SMSvcHost.exe carrying the Net. TCP Port Sharing Service) to manage TCP sockets. The above is an introduction to all the steps for enabling the port in WCF.