WCF error: registration already exists for URI

Below is my WCF service configuration. I use 2 ServiceHost to host 2 types of services. They use the same base address, but use different relative addresses for their endpoints.

But I got this error, why?

The service cannot be started. System.InvalidOperationException: ChannelDispatcher in 'http: // earth: 1111 /' with contract '' IHttpGetHelpPageAndMetadataContract '' cannot open its IChannelListener. ---> System.InvalidOperationException: registration already exists for URI 'http: // earth: 1111 / '.

<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="serviceBehavior"> <serviceMetadata httpGetEnabled="true" /> </behavior> </serviceBehaviors> </behaviors> <services> <service behaviorConfiguration="serviceBehavior" name="Distributed.Troubleshooting.System.IIS.IISServiceType"> <endpoint address="iis" binding="basicHttpBinding" name="iis" contract="Distributed.Troubleshooting.System.IIS.IISServiceContract" /> <endpoint address="iismex" binding="mexHttpBinding" bindingConfiguration="" name="iismex" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="http://Earth:1111/" /> </baseAddresses> </host> </service> <service behaviorConfiguration="serviceBehavior" name="Distributed.Troubleshooting.System.SQL.SQLServiceType"> <endpoint address="sql" binding="basicHttpBinding" name="sql" contract="Distributed.Troubleshooting.System.SQL.SQLServiceContract" /> <endpoint address="sqlmex" binding="mexHttpBinding" bindingConfiguration="" name="sqlmex" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="http://Earth:1111/" /> </baseAddresses> </host> </service> </services> </system.serviceModel> </configuration> 

Some even more ridiculous conclusions:

I changed my configuration to the following:

 <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="serviceBehavior"> <serviceMetadata httpGetEnabled="true" /> </behavior> </serviceBehaviors> </behaviors> <services> <service behaviorConfiguration="serviceBehavior" name="Distributed.Troubleshooting.System.IIS.IISServiceType"> <endpoint address="http://Earth:1111/iis" binding="basicHttpBinding" name="iis" contract="Distributed.Troubleshooting.System.IIS.IISServiceContract" /> <endpoint address="http://Earth:1111/iismex" binding="mexHttpBinding" bindingConfiguration="" name="iismex" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="http://Earth:1111/iis" /> </baseAddresses> </host> </service> <service behaviorConfiguration="serviceBehavior" name="Distributed.Troubleshooting.System.SQL.SQLServiceType"> <endpoint address="http://Earth:1111/sql" binding="basicHttpBinding" name="sql" contract="Distributed.Troubleshooting.System.SQL.SQLServiceContract" /> <endpoint address="http://Earth:1111/sqlmex" binding="mexHttpBinding" bindingConfiguration="" name="sqlmex" contract="IMetadataExchange" /> <host> <baseAddresses> <add baseAddress="http://Earth:1111/sql" /> </baseAddresses> </host> </service> </services> </system.serviceModel> </configuration> 

Then I found that I could use the "Add Service Link" in Visual Studio with the following addresses:

+4
source share
4 answers

It is possible to host more than one Service with the same base address. Set the HttpHelpPageEnabled and HttpsHelpPageEnabled all ServiceDebugBehavior properties to false , then it should work.

Act. . By default, there always exists a ServiceDebugBehavior registered in the host behavior description collection, even if it is not explicitly specified (I tried it only with the software configuration and the ServiceHost class, and not through the XML configuration). So you must add an explicit ServiceDebugBehavior and set the specified properties. The IncludeExceptionDetailInFaults property can be true .

+1
source

Have you tried to remove one of the Service blocks and merge the endpoints into one?

I donโ€™t see the reasons why you divided them.

Make sure the baseaddress + endpoint address is unique.

0
source

You cannot host two services with the same base address.

You need to host another on a different port or address.

Sort of

 http://Earth:1111/Service1 

and

 http://Earth:1111/Service2 
0
source

I really donโ€™t know why this is so, but one solution is to leave the service without a base address and specify the full address for the endpoints. This does not change the address of different endpoints, nor is the ambiguity of the addresses. I could not find the link to this link on MSDN.

From my own experience, the problem is with http, not with net.tcp. I do not use service metadata. I thought that "IHttpGetHelpPageAndMetadataContract" is associated with metadata, but I did not find a way to disable it.

0
source

Source: https://habr.com/ru/post/1383904/


All Articles