WCF InvalidOperationException: Binding instance is already associated with a listening URI

I am starting WCF and I am studying at Essential WCF.

I am having a problem using ServiceContract NameSpace and Name. when i run the code i will catch below an InvalidOperationException. But I could not understand clearly.

The binding instance has already been bound to the listening URI 'http: // localhost: 8080 / NamespaceChange01'. If two endpoints want to use the same ListenUri, they must also use the same instance of the binding object. Two conflicting endpoints were either specified in the AddServiceEndpoint () calls, or in the configuration file, or in combination with AddServiceEndpoint () and configuration.

Does anyone know how to avoid an InvalidOperationException?

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; namespace NamespaceChange01 { [ServiceContract(Name = "MyServiceName", Namespace = "http://ServiceNamespace")] public interface IBurgerMaster { [return: MessageParameter(Name = "myOutput")] [OperationContract(Name = "OperationName", Action = "OperationAction", ReplyAction = "ReplyActionName")] double GetStockPrice(string ticker); } [ServiceBehavior(Namespace = "http://MyService")] public class BurgerMaster : IBurgerMaster { public double GetStockPrice(string ticker) { return 100.99; } } class Program { static void Main(string[] args) { ServiceHost host = new ServiceHost(typeof(BurgerMaster)); host.Open(); Console.ReadLine(); host.Close(); } } } 
  • app.config

     <?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <services> <service name="NamespaceChange01.BurgerMaster" behaviorConfiguration="mexServiceBehavior"> <host> <baseAddresses> <add baseAddress="http://localhost:8080/NamespaceChange01"/> </baseAddresses> </host> <endpoint name="basic" binding="basicHttpBinding" contract="NamespaceChange01.IBurgerMaster"/> <endpoint name="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="mexServiceBehavior"> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> </configuration> 

Thanks.

+9
wcf
source share
4 answers

Two endpoints (base and microsec) cannot be on the same address. Add a specific address for one of them (or both).

For example:

 <endpoint name="mex" address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
+21
source share

You are missing the address attribute from the metadata endpoint:

 <endpoint name="mex" binding="mexHttpBinding" contract="IMetadataExchange" address="mex" /> 

Without it, WCF thinks you want to place the mex endpoint at the same address.

+5
source share

I know this is an old question, but recently I had a very similar problem and Google brought me here, plus I have another potential solution:

Having a completely missing service tag for the service in question and having HTTP and HTTPS bindings for it in IIS, I came across the exact same error message described.

Naturally, adding a service tag fixed the problem. Interestingly, removing the HTTPS binding in IIS made the HTTP version usable (although this was clearly undesirable).

0
source share

When creating your service class, why did you mark it with the ServiceContract attribute, as your code says?

 [ServiceBehavior(Namespace = "http://MyService")] public class BurgerMaster : IBurgerMaster 

Remove this and try again.

-2
source share

All Articles