none
Exception: The Service contains multiple ServiceEndpoints with different ContractDescriptions which each have Name......... RRS feed

  • Question

  • Hello,

    I have following code to host my WCF service in a Console App. The "Service" implements "IService2Contract" contract.

    ServiceHost serviceHost = new ServiceHost(typeof(Service),
                    new Uri("http://127.0.0.1:9999/"));
    
                serviceHost.AddDefaultEndpoints();
    
                serviceHost.Description.Endpoints.Add(new ServiceEndpoint(ContractDescription.GetContract(typeof(IService2Contract)),
                    new NetTcpBinding(),
                    new EndpointAddress("net.tcp://127.0.0.1:7777/")));
    
                serviceHost.Open();
    
                Console.WriteLine("Service is running....Press any key to exit");
                Console.ReadKey();


    This throws an exception, "The Service contains multiple ServiceEndpoints with different ContractDescriptions which each have Name='IService2Contract' and Namespace='http://tempuri.org/'.  Either provide ContractDescriptions with unique Name and Namespaces, or ensure the ServiceEndpoints have the same ContractDescription instance." 

    However, when I use only AddDefaultEndpoints(), it works fine:

    ServiceHost serviceHost = new ServiceHost(typeof(Service),
                    new Uri("http://127.0.0.1:9999/"),
                    new Uri("net.tcp://127.0.0.1:7777/"));
    
                serviceHost.AddDefaultEndpoints();
    
                ////serviceHost.Description.Endpoints.Add(new ServiceEndpoint(ContractDescription.GetContract(typeof(IService2Contract)),
                ////    new NetTcpBinding(),
                ////    new EndpointAddress("net.tcp://127.0.0.1:7777/")));
    
                serviceHost.Open();
    
                Console.WriteLine("Service is running....Press any key to exit");
                Console.ReadKey();

    Why it does not throw the exception in latter case? Any thoughts?

    Thanks!

    Monday, May 12, 2014 3:50 PM

All replies

  • Hi,

    When we want to add service endpoint in code, then we often use the following code:

         ServiceHost serviceHost = new ServiceHost(typeof(WcfServiceLibrary33.Service1),
                     new Uri("http://127.0.0.1:9999/"),new Uri("net.tcp://127.0.0.1:7777/"));
          serviceHost.AddServiceEndpoint(typeof(WcfServiceLibrary33.IService1), new NetTcpBinding(), "");
    serviceHost.Open();
    Console.WriteLine("Service is running....Press any key to exit");
          
    Console.ReadKey();

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, May 13, 2014 7:04 AM
    Moderator
  • Sorry for delayed response.

    Yes, but I'd like to understand why my code doesn't work? Want to know the root cause of mentioned exception.

    Friday, May 23, 2014 2:06 PM