6 Comments

After renaming a WCF service reference in Microsoft Visual Studio, you can get the error:

System.InvalidOperationException : Could not find default endpoint element that references contract ‘ImportServiceReference.IImportService’ in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
    at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
    at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
    at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
    at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName)
    at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()
    at System.ServiceModel.EndpointTrait`1.CreateChannelFactory()
    at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
    at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
    at System.ServiceModel.ClientBase`1..ctor()

Make sure the name in the contract attribute of the endpoint is the same as you’re Microsoft Visual Studio Service Reference name

<endpoint address="http://localhost/ImportService/ImportService.svc"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IImportService"
        contract="ImportServiceReference.IImportService" name="WSHttpBinding_IImportService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>

Must be the same as:

image

6 Replies to “Resolving the System.InvalidOperationException : Could not find default endpoint element that references contract ‘xxx’ in the ServiceModel client configuration section”

  1. Everything it’s ok but it’s a little bit strange.

    Everything is ok when calling webservice from console application but
    it doesn’t work from class library????

    Please help me to resolve this deal…

  2. Thanks a million for posting this! I have been trying for days upon days to get my issue resolved with this! When you pointed out that the ‘contract’ had to be exactly the same as the Service name, that is what did the trick for me. And the real kicker is that when you add the service, Visual Studio adds those lines automatically and it was adding them wrong! It was making the last three letters of the ‘contract’ capital letters when the last two letters should have been lowercase. Thanks again!!

  3. contract name and service name both are same still facing issue. what to do in this case.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts