Search code examples
.netwcfbing-ads-api

Bing Ads API: endpoint configuration in .config


I've got an ASP.Net MVC (Framework version 4.6.2) site where I'm trying to integrate daily expense totals from our Bing Ads campaign through the API.

I've added the package Microsoft.BingAds.SDK through Nuget and written some code against its classes that compiles, so I figured I could fire it up and see what happens.

What happens is this:

Could not find default endpoint element that references contract 'Microsoft.BingAds.V11.Reporting.IReportingService' 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.

The error happens in the constructor of the ReportingServiceClient():

var client = new ReportingServiceClient();

I'm not sure how to proceed. There is indeed no endpoint configured in my .config file. I would have expected Nuget to add necessary config, but there's nothing. I have no idea why it didn't, or what I'm supposed to be adding to my .config.


Solution

  • Do you have more details e.g., code snippet where you create and use the service client? Are you using A) ReportingServiceManager or B) ServiceClient?

    AuthorizationData authorizationData = new AuthorizationData
    {
        // By this point OAuthWebAuthCodeGrant already has 
        // access and refresh tokens
        Authentication = OAuthWebAuthCodeGrant,
        DeveloperToken = "DeveloperTokenGoesHere"
    };
    
    // Option A: ReportingServiceManager
    ReportingServiceManager reportingServiceManager = new ReportingServiceManager(authorizationData);
    
    // Option B: ServiceClient<IReportingService>
    ServiceClient<IReportingService> service = new ServiceClient<IReportingService>(authorizationData);
    

    Here is an example web solution from the API Docs. I suggest that you also review this example from GitHub that uses ReportingServiceManager.

    Also note that I installed System.ServiceModel.Primitives 4.4.1, System.ServiceModel.Http 4.4.1, and System.ServiceModel.ConfigurationManager 4.4.1 (ran into issues several weeks ago with some other versions) as documented here.

    I hope this helps!