Search code examples
asp.netasp.net-mvc-5asmx

Adding an ASMX web service as a service reference generates multiple endpoints


Lately in all my new web applications I have been adding web services as service references rather than web references. Most of our web services were designed as asmx web services.

After adding the service reference my web.config always looks like this:

<bindings>
  <basicHttpBinding>
    <binding name="UserSoap" />
  </basicHttpBinding>
  <customBinding>
    <binding name="UserSoap12">
      <textMessageEncoding messageVersion="Soap12" />
      <httpTransport />
    </binding>
  </customBinding>
</bindings>
<client>
  <endpoint address="{{service URL}}" binding="basicHttpBinding"
    bindingConfiguration="UserSoap" contract="User.UserSoap"
    name="UserSoap" />
  <endpoint address="{{service URL}}" binding="customBinding"
    bindingConfiguration="UserSoap12" contract="User.UserSoap"
    name="UserSoap12" />
</client>

Then my application gives this error when I try to consume it:

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

I have been manually removing one of the endpoints, but now I want to know how to fix this. Any ideas on how I can prevent this from happening, or why is this happening?


Solution

  • If you want to remove SOAP 1.2 support for your service, you would include the following in your web.config:

    <configuration>
        <system.web>
            <webServices >
                <protocols>
                    <remove name="HttpSoap12"/>
                </protocols>        
            </webServices>
        </system.web>   
    </configuration>
    

    Add or remove SOAP 1.2 for ASMX services

    Otherwise, you'll need to access with endpoint name.

    var service = new User.UserSoapClient("UserSoap")