다음을 통해 공유


Troubleshooting "'An endpoint configuration section for contract could not be loaded because more than one endpoint configuration for that contract was found" error

While I was playing with Microsoft AdCenter API, I have encountered this error:

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

Out of curiosity, I searched the web for guidance to troubleshoot this error. Surprisingly, I have found very confusing posts of forums with no clear guidance on how to fix the problem. However there seems to be a very simple solution in VS2008 SP1, unless I am missing something.

  1. Open app.config file and check the list of bindings for the service
  2. Pick one binding and copy it to your source as a parameter to a constructor of Service Client class created by "Service Reference" dialog.

That's it. In my example, the app.config file looked like this:

image

Now I was going to use HTTPS connection to the service and as such I am choosing to use "BasicHttpBinding_ICampaignManagementService" binding, which means modifying source code from:

             svcCampMgt = new CampaignManagementServiceClient();

to

             svcCampMgt = new CampaignManagementServiceClient("BasicHttpBinding_ICampaignManagementService");

This change complete fixes the problem. Now some WCF guru can probably point out several other reasons for this error, but hey, for simple scenarios, this change should fix the error just fine.

Comments

  • Anonymous
    October 29, 2008
    Hi, thanks for the solution. This is why this error occurs: Visual Studio generates the end points in the app.config when you refresh your service reference. If your end point has been modified inside the app.config file it creates a second end point, and that is what causes the problem. So to fix this, simply select the one you want to keep, look in the <basicHttpBinding> node of the file, and delete everything between <binding.name...> and </binding>, you'll notice that you have two of those, only delete one of them. Do the same for the <Client> node of the file. Unfortunately Visual Studion will generate that code everytime you update the service reference, so you'll have to remove it again every time. Your solution is the best one in this case, and if you deliberately have two endpoint, eg. to include one for over http etc. Cheers!

  • Anonymous
    November 21, 2008
    Thank you so much. I had no idea how to find out what the endpoint names ...

  • Anonymous
    January 21, 2009
    usally means that you to refrences in your web.config..Good Luck