Monday, June 18, 2012

An endpoint configuration section for contract could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name.


An endpoint configuration section for contract 'MyServiceReference.IHelloWorld' could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name.



This is due to the app.config in the client project has multiple endpoints defined and so the application does not know which one to use to communicate with the service. So, comment the other endpoints which you client application is not intending to refer to and run the client application again. The error should be gone.

For example, look at the following configuration in the app.config file in the client project:
<client>
            <endpoint address="http://localhost:8000/HelloWorld" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IHelloWorld" contract="MyServiceReference.IHelloWorld"
                name="BasicHttpBinding_IHelloWorld" />
            <endpoint address="net.tcp://localhost:9000/HelloWorld" binding="netTcpBinding"
                bindingConfiguration="NetTcpBinding_IHelloWorld" contract="MyServiceReference.IHelloWorld"
                name="NetTcpBinding_IHelloWorld">
                <identity>
                    <userPrincipalName value="MyPC\ComputerName" />
                </identity>
            </endpoint>
        </client>
The error is due to the app.config in the client project has two endpoints defined and so the application does not know which one to use to communicate with the service. So, comment the one endpoint which is referring to NetTcpBinding and run the program again.
<client>
            <endpoint address="http://localhost:8000/HelloWorld" binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IHelloWorld" contract="MyServiceReference.IHelloWorld"
                name="BasicHttpBinding_IHelloWorld" />
            <!--<endpoint address="net.tcp://localhost:9000/HelloWorld" binding="netTcpBinding"
                bindingConfiguration="NetTcpBinding_IHelloWorld" contract="MyServiceReference.IHelloWorld"
                name="NetTcpBinding_IHelloWorld">
                <identity>
                    <userPrincipalName value="MyPC\ComputerName" />
                </identity>
            </endpoint>-->
        </client>

Otherwise, specify in your code which endpoint is to be used as in the below sample code:
 MyServiceReference.HelloWorldClient proxy = new Client.MyServiceReference.HelloWorldClient("BasicHttpBinding_IHelloWorld");
            Console.WriteLine(proxy.ShowData("Hello World From Client using basicHttpBinding"));

            proxy = new Client.MyServiceReference.HelloWorldClient("NetTcpBinding_IHelloWorld");
            Console.WriteLine(proxy.ShowData("Hello World From Client using netTcpBinding"));
Hope this helps!!!

3 comments:

jerrynixon said...

Thanks, man; saved me a ton. When I am king, you will be taken care of.

Akki said...

Hahahaa... nice one... You are welcome Man!!!

Anonymous said...

Thanks..

Post a Comment