title: Bing-Map-API what am I doing wrong?
body: <p>I am trying for my school to use the Bing Map API and use GeocodeAdress. I build this application: <a href="http://msdn.microsoft.com/en-us/library/dd221354.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/dd221354.aspx</a> and the problem is I get this error every time.</p>
  
  <p>it is at line 62: this method: GeocodeServiceClient geocodeService = new GeocodeServiceClient(); </p>
  
  <p>!InvalidOperationException was unhandled
  An unhandled exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll</p>
  
  <p>Additional information: An endpoint configuration section for contract 'GeocodeService.IGeocodeService' could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Navigation;
  using System.Windows.Shapes;
  
  using BingMapsSample.GeocodeService;
  using BingMapsSample.SearchService;
  using BingMapsSample.ImageryService;
  using BingMapsSample.RouteService;
  
  namespace BingMapsSample
  {
  /// &lt;summary&gt;
  /// Interaction logic for MainWindow.xaml
  /// &lt;/summary&gt;
  public partial class MainWindow : Window
  {
  
      public MainWindow()
      {
          InitializeComponent();
      }
  
      private String GeocodeAddress(string address)
      {
          string results = "";
          string key = "Validate Bing Map Education Code";
          GeocodeRequest geocodeRequest = new GeocodeRequest();
  
          // Set the credentials using a valid Bing Maps key
          geocodeRequest.Credentials = new GeocodeService.Credentials();
          geocodeRequest.Credentials.ApplicationId = key;
  
          // Set the full address query
          geocodeRequest.Query = address;
  
          // Set the options to only return high confidence results 
          ConfidenceFilter[] filters = new ConfidenceFilter[1];
          filters[0] = new ConfidenceFilter();
          filters[0].MinimumConfidence = GeocodeService.Confidence.High;
  
          // Add the filters to the options
          GeocodeOptions geocodeOptions = new GeocodeOptions();
          geocodeOptions.Filters = filters;
          geocodeRequest.Options = geocodeOptions;
  
          // Make the geocode request
          GeocodeServiceClient geocodeService = new GeocodeServiceClient();
          GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);
  
          if (geocodeResponse.Results.Length &gt; 0)
              results = String.Format("Latitude: {0}\nLongitude: {1}",
                geocodeResponse.Results[0].Locations[0].Latitude,
                geocodeResponse.Results[0].Locations[0].Longitude);
          else
              results = "No Results Found";
  
          return results;
      }
  
      private string ReverseGeocodePoint(string locationString)
      {
          string results = "";
          string key = "Validate Bing Map Education Code";
          ReverseGeocodeRequest reverseGeocodeRequest = new ReverseGeocodeRequest();
  
          // Set the credentials using a valid Bing Maps key
          reverseGeocodeRequest.Credentials = new GeocodeService.Credentials();
          reverseGeocodeRequest.Credentials.ApplicationId = key;
  
          // Set the point to use to find a matching address
          GeocodeService.Location point = new GeocodeService.Location();
          string[] digits = locationString.Split(',');
  
          point.Latitude = double.Parse(digits[0].Trim());
          point.Longitude = double.Parse(digits[1].Trim());
  
          reverseGeocodeRequest.Location = point;
  
          // Make the reverse geocode request
          GeocodeServiceClient geocodeService = new GeocodeServiceClient();
          GeocodeResponse geocodeResponse = geocodeService.ReverseGeocode(reverseGeocodeRequest);
  
          if (geocodeResponse.Results.Length &gt; 0)
              results = geocodeResponse.Results[0].DisplayName;
          else
              results = "No Results found";
  
          return results;
      }
  
      private string SearchKeywordLocation(string keywordLocation)
      {
          String results = "";
          String key = "Validate Bing Map Education Code";
          SearchRequest searchRequest = new SearchRequest();
  
          // Set the credentials using a valid Bing Maps key
          searchRequest.Credentials = new SearchService.Credentials();
          searchRequest.Credentials.ApplicationId = key;
  
          //Create the search query
          StructuredSearchQuery ssQuery = new StructuredSearchQuery();
          string[] parts = keywordLocation.Split(';');
          ssQuery.Keyword = parts[0];
          ssQuery.Location = parts[1];
          searchRequest.StructuredQuery = ssQuery;
  
          //Define options on the search
          searchRequest.SearchOptions = new SearchOptions();
          searchRequest.SearchOptions.Filters =
              new FilterExpression()
              {
                  PropertyId = 3,
                  CompareOperator = CompareOperator.GreaterThanOrEquals,
                  FilterValue = 8.16
              };
  
          //Make the search request 
          SearchServiceClient searchService = new SearchServiceClient();
          SearchResponse searchResponse = searchService.Search(searchRequest);
  
          //Parse and format results
          if (searchResponse.ResultSets[0].Results.Length &gt; 0)
          {
              StringBuilder resultList = new StringBuilder("");
              for (int i = 0; i &lt; searchResponse.ResultSets[0].Results.Length; i++)
              {
                  resultList.Append(String.Format("{0}. {1}\n", i + 1,
                      searchResponse.ResultSets[0].Results[i].Name));
              }
  
              results = resultList.ToString();
          }
          else
              results = "No results found";
  
          return results;
      }
  
  
  
      private void Geocode_Click(object sender, RoutedEventArgs e)
      {
          labelResults.Content = GeocodeAddress(textInput.Text);
      }
  
      private void ReverseGeocode_Click(object sender, RoutedEventArgs e)
      {
          labelResults.Content = ReverseGeocodePoint(textInput.Text);
      }
  
      private void Search_Click(object sender, RoutedEventArgs e)
      {
          labelResults.Content = SearchKeywordLocation(textInput.Text);
      }
  
  }
  }
  </code></pre>
  
  <p>I found the solution line 62 should be:</p>
  
  <pre><code>var geocodeService = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
  </code></pre>