I need help using route web service in my WPF / Bing Map control application RRS feed

  • Question

  • I have the following code which works.  It reads thru my SQL customer table, plots pushpins, and assigns tooltip data.  I now want to fetch the instructions for my route.  I have already added the web service reference for the route.  I can't seem to find a good example that captures the driving directions as I loop thru my customer rows.  Maybe someone can help me since I never used the route web service.  Here is my code:

                    using (LoadCustomersCnn = new System.Data.SqlClient.SqlConnection(connectionString))
                    using (LoadCustomersCmd = new SqlCommand("GetCustomer", LoadCustomersCnn))
                        LoadCustomersCmd.CommandType = System.Data.CommandType.StoredProcedure;

                        using (LoadCustomersRdr = LoadCustomersCmd.ExecuteReader())
                            while (LoadCustomersRdr.Read())
                                string myAddress = (string)LoadCustomersRdr["myAddress"];                            

                                // Set the full address query
                                geocodeRequest.Query = myAddress;

                                // 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("BasicHttpBinding_IGeocodeService");
                                GeocodeResponse geocodeResponse = geocodeService.Geocode(geocodeRequest);

                                if (geocodeResponse.Results.Length > 0)
                                    results = String.Format("Latitude: {0}\nLongitude: {1}",

                                    latitude = geocodeResponse.Results[0].Locations[0].Latitude;
                                    longitude = geocodeResponse.Results[0].Locations[0].Longitude;

                                    Pushpin pin = new Pushpin();
                                    pin.Location = new Microsoft.Maps.MapControl.WPF.Location(latitude, longitude);
                                    pin.ToolTip = (string)LoadCustomersRdr["Name"] + "\n\n" + (string)LoadCustomersRdr["Address"] + "\n" +
                                                  (string)LoadCustomersRdr["City"] + ", " + (string)LoadCustomersRdr["State"] + " " +
                                                  (string)LoadCustomersRdr["ZipCode"] + "\n\n" + (string)LoadCustomersRdr["Phone"];
                                    iCount += 1;
                                    pin.Content = Convert.ToString(iCount);

                                    pin.Tag = new Metadata()
                                        CustomerID = (string)LoadCustomersRdr["CustomerID"],
                                        CustomerName = (string)LoadCustomersRdr["Name"]

                                    pin.MouseDown += PinClicked;

                                    // Center the map
                                    if (counter == 0)
                                        myMap.Center = new Microsoft.Maps.MapControl.WPF.Location(latitude, longitude);
                                        counter += 1;                                    

                                    // Adds the pushpin to the map.
                                    results = "No Results Found";

                catch (Exception ex)
                    MessageBox.Show("Error: - " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);


    Wednesday, February 27, 2013 2:56 PM


All replies

  • You can find information on how to use the REST services from .NET here: Using the REST services you can easily calculate a route and get the points that create the route line. You can find information on how to generate a REST route request here: Once you have the points you can loop through and create a polyline object. I have a blog post on doing this with the Windows 8 controls which are similar to the WPF control. You can find this blog post here:

    Wednesday, February 27, 2013 4:53 PM
  • Sorry, I'm still confused on how to do the route.  I have the following code within my looping thru my customers:

    waypoints[iCount] = new RouteService.Waypoint();

    waypoints[iCount].Description = (string)LoadCustomersRdr["Name1"]; 

     waypoints[iCount].Location = new RouteService.Location();
     waypoints[iCount].Location.Latitude = latitude;
     waypoints[iCount].Location.Longitude = longitude;

    iCount += 1;

    Then I have this code outside my loop:

     routeRequest.Waypoints = waypoints;

    RouteService.RouteServiceClient routeService = new RouteService.RouteServiceClient();
    RouteService.RouteResponse routeResponse = routeService.CalculateRoute(routeRequest);

    But I get an error on the last line.  Here is the error:

    {"An endpoint configuration section for contract 'RouteService.IRouteService' could not be loaded because more than one endpoint configuration for that contract was found. Please indicate the preferred endpoint configuration section by name."}

    Not sure what this means.

    Thursday, February 28, 2013 5:23 PM
  • The issue is in your web.config file. You likely have two endpoints configured. One is likely a basic endpoint and the other is a custom one. Remove the custom endpoint.

    Thursday, February 28, 2013 5:45 PM
  • This is a WPF project, not a web site.  So I do not have a web.config.  I am brand-new to both WPF and Bing maps.  I don't know what an endpoint is.  I looked at my code and don't see anything about an endpoint.  
    Thursday, February 28, 2013 5:57 PM
  • Perhaps you meant the app.config?  I do have some endpoint things in here.  Not sure how this got there.  But here ir is:

          <endpoint address=""
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IGeocodeService"
            contract="GeoCodeService.IGeocodeService" name="BasicHttpBinding_IGeocodeService" />
          <endpoint address=""
            binding="customBinding" bindingConfiguration="CustomBinding_IGeocodeService"
            contract="GeoCodeService.IGeocodeService" name="CustomBinding_IGeocodeService" />
          <endpoint address=""
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISearchService"
            contract="SearchService.ISearchService" name="BasicHttpBinding_ISearchService" />
          <endpoint address=""
            binding="customBinding" bindingConfiguration="CustomBinding_ISearchService"
            contract="SearchService.ISearchService" name="CustomBinding_ISearchService" />
          <endpoint address=""
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IRouteService"
            contract="RouteService.IRouteService" name="BasicHttpBinding_IRouteService" />
          <endpoint address=""
            binding="customBinding" bindingConfiguration="CustomBinding_IRouteService"
            contract="RouteService.IRouteService" name="CustomBinding_IRouteService" />

    Thursday, February 28, 2013 5:59 PM
  • Ok, I got the directions captured in a string field.  Dumb question but how do I display these driving directions in my xaml to the left of my bing map control?  I am a web developer and I was thrust into this WPF project and know nothing about WPF.  Here is what I presently have in my xaml:

    <Window x:Class="WPFTestApplication.Route"
                    Title="Route" Height="700" Width="700">
                <m:Map x:Name="myMap" 
                       CredentialsProvider="my key" 

    I guess I want some kind of label control to display my directions to the left of my map?  How do I do this?  I know this is WPF question and not a Bing map question but hopefully someone can help me out.

    Thursday, February 28, 2013 6:42 PM