Could not find default endpoint element that references contract error

I am working on an API to consume Amazon.com web services to search product. Previously I had consumed Amazon.com web services as a web reference. This time I decided to use .Net 3.5 WCF service reference for this web service. After implementing a simple book search API, I wrote a console application to test it out. As soon as the library tried to create instance of web service client, I got the following error.

Could not find default endpoint element that references contract 'AmazonData.AWSECommerceServicePortType' 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.

I looked at the consuming application's BIN folder. I did not see any configuration file. Then I looked at BIN folder of my class library. I found that ServiceModel Metadata Utility Tool (Svcutil.exe) generated app.config file in the project and it got compiled into MyApi.dll.config. This configuration contains binding, endpoint etc. definitions that default constructor of AWSECommerceServicePortTypeClient object was looking for. There are couple of options you have to fix this problem.

  • In app.config file of consuming application, create the required entries.
  • Copy config file (MyApi.dll.config) from class library to bin folder of consuming application and rename it to MyApp.config
  • Programatically create instances of Binding and RemoteAddress objects and use the constructor that takes these 2 parameters.
    
     public AWSECommerceServicePortTypeClient
      (System.ServiceModel.Channels.Binding binding,
       System.ServiceModel.EndpointAddress remoteAddress) : 
                    base(binding, remoteAddress) {}
    
    
comments powered by Disqus

Blog Tags