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.