FAQ about WCF-Port Sharing

Source: Internet
Author: User

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 ();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.