Question from the WCF .NET class - More than 1 endpoint found

I was teaching the UTS .NET class and a student asked me this interesting question…

Question
I am not able to create a new instance of the Countries.SoapClient(). The error that I get is

image

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

 

Answer

The error message is a bit cryptic as usual all technical error messages are.
The important bit in the error message is the "more than one endpoint".

That leads me to look into your configuration file: "app.config"

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="countrySoap" closeTimeout="00:01:00" openTimeout="00:01:00"
                    receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
                    bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
            <customBinding>
                <binding name="countrySoap12">
                    <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                        messageVersion="Soap12" writeEncoding="utf-8">
                        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    </textMessageEncoding>
                    <httpTransport manualAddressing="false" maxBufferPoolSize="524288"
                        maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous"
                        bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
                        keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous"
                        realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                        useDefaultWebProxy="true" />
                </binding>
            </customBinding>
        </bindings>
        <client>
            <endpoint address="http://www.webservicex.net/country.asmx" binding="basicHttpBinding"
                bindingConfiguration="countrySoap" contract="ServiceReference1.countrySoap"
                name="countrySoap" />
            <endpoint address="http://www.webservicex.net/country.asmx" binding="customBinding"
                bindingConfiguration="countrySoap12" contract="ServiceReference1.countrySoap"
                name="countrySoap12" />
        </client>
    </system.serviceModel>
</configuration>

Figure: 2 definitions for your client endpoint, see highlighted part

Where do those 2 endpoint definitions come from?
They probably come from the webservice itself (WSDL). Because we can call this particular webservice with different protocol versions, we get 2 client endpoints.

Note

To quickly verify this configuration, you open up the "WCF Test Client" tool and connect to your webservice. You can find the "WCF Test Client" tool as part of your VS2008 or VS2010 installation in the folder:

  • C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\WcfTestClient.exe
    OR
  • C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\WcfTestClient.exe

image
Figure: http://www.webservicex.net/country.asmx exposes 2 endpoints

 

2 ways to solve this

  1. Specify in your client creation which endpoint you want to use by passing the endpoint name as a parameter
    countrySoapClient countrySoapClient = new countrySoapClient("countrySoap");  //   <--  RECOMMENDED!

    image

    OR
  2. Delete one of the endpoints from your application configuration file (app.config)
        <client>
            <endpoint address="http://www.webservicex.net/country.asmx" binding="basicHttpBinding"
                bindingConfiguration="countrySoap" contract="ServiceReference1.countrySoap"
                name="countrySoap" />
            <endpoint address="http://www.webservicex.net/country.asmx" binding="customBinding"
                bindingConfiguration="countrySoap12" contract="ServiceReference1.countrySoap"
                name="countrySoap12" />
        </client>
    </system.serviceModel>
</configuration>

 

 

Have fun!

But not for long, because as soon as you try to call the GetCountries() method you encounter another problem. See next blog post

Latest Posts

Popular Posts