When two WCF applicationsProgramWhen you want to share a port to provide the service, you will find that the next service cannot run, and a prompt will be displayed that an application is listening, such:
Application 1
Code
Servicehost host = New Servicehost ( Typeof (Wcfportsharing. addservice ));
Nettcpbinding binding = New Nettcpbinding ();
Host. addserviceendpoint ( Typeof (Wcfportsharing. iaddservice), binding, " Net. TCP: // 127.0.0.1: 4503/addservice " );
Host. open ();
Application 2
Code
Servicehost host1 = New Servicehost ( Typeof (Wcfportsharing. subservice ));
Nettcpbinding binding1 = New Nettcpbinding ();
Host1.addserviceendpoint ( Typeof (Wcfportsharing. isubservice), binding1, " Net. TCP: // 127.0.0.1: 4503/subservice " );
Host1.open ();
If you want to avoid conflict, You need to enable the WCF Port Sharing and start a service net. TCP port sharing service. This service is disabled by default. After you manually enable it, add the service configuration
Binding. portsharingenabled = True ;
In this way:
Code
Servicehost host = New Servicehost ( Typeof (Wcfportsharing. addservice ));
Nettcpbinding binding = New Nettcpbinding ();
Binding. portsharingenabled = True ;
Host. addserviceendpoint ( Typeof (Wcfportsharing. iaddservice), binding, " Net. TCP: // 127.0.0.1: 4503/addservice " );
Host. open ();
When two WCF applications want to share a port to provide services, you will find that the service started later cannot run and a prompt is displayed that an application is listening, for example:
Application 1
Code
Servicehost host = New Servicehost ( Typeof (Wcfportsharing. addservice ));
Nettcpbinding binding = New Nettcpbinding ();
Host. addserviceendpoint ( Typeof (Wcfportsharing. iaddservice), binding, " Net. TCP: // 127.0.0.1: 4503/addservice " );
Host. open ();
Application 2
Code
Servicehost host1 = New Servicehost ( Typeof (Wcfportsharing. subservice ));
Nettcpbinding binding1 = New Nettcpbinding ();
Host1.addserviceendpoint ( Typeof (Wcfportsharing. isubservice), binding1, " Net. TCP: // 127.0.0.1: 4503/subservice " );
Host1.open ();
If you want to avoid conflict, You need to enable the WCF Port Sharing and start a service net. TCP port sharing service. This service is disabled by default. After you manually enable it, add the service configuration
Binding. portsharingenabled = True ;
In this way:
Code
Servicehost host = New Servicehost ( Typeof (Wcfportsharing. addservice ));
Nettcpbinding binding = New Nettcpbinding ();
Binding. portsharingenabled = True ;
Host. addserviceendpoint ( Typeof (Wcfportsharing. iaddservice), binding, " Net. TCP: // 127.0.0.1: 4503/addservice " );
Host. open ();