none
problem with geocode service when sending several addresses RRS feed

  • Question

  • I have a problem with my application when I use the GeocodeService. I have to read several addresses at one time and I must find all the coordinates for these addresses.

    here is the xml file which im parsing and sending it to geocode service :

    <?xml version="1.0" encoding="utf-8" ?>
    <executiveInfoListing>
      <listing>
        <arrivalCity>Chennai</arrivalCity>
        <arrivalCountry>INDIA</arrivalCountry>
        <arrivalState>Tamilnadu</arrivalState>
        <departureDate>30/04/2011 04:30:00</departureDate>
        <destinationCity>DELHI</destinationCity>
        <destinationCountry>INDIA</destinationCountry>
        <destinationState>NEW DELHI</destinationState>
        <perFirstName>JEFFREY</perFirstName>
        <perLastName>IMMELT</perLastName>
      </listing>
      <listing>
        <arrivalCity>BANGALORE</arrivalCity>
        <arrivalCountry>INDIA</arrivalCountry>
        <arrivalState>KARNATAKA</arrivalState>
        <departureDate>29/03/2011 07:05:00</departureDate>
        <destinationCity>BHUBANESWAR</destinationCity>
        <destinationCountry>INDIA</destinationCountry>
        <destinationState>ORISSA</destinationState>
        <perFirstName>JEFFREY</perFirstName>
        <perLastName>IMMELT</perLastName>
      </listing>
      <listing>
        <arrivalCity>singapore</arrivalCity>
        <arrivalCountry>singapore</arrivalCountry>
        <arrivalState>singapore</arrivalState>
        <departureDate>25/04/2011 04:30:00</departureDate>
        <destinationCity>calcutta</destinationCity>
        <destinationCountry>INDIA</destinationCountry>
        <destinationState>West Bengal</destinationState>
        <perFirstName>Tom</perFirstName>
        <perLastName>IMMELT</perLastName>
      </listing>
      <listing>
        <arrivalCity>London</arrivalCity>
        <arrivalCountry>England</arrivalCountry>
        <arrivalState>England</arrivalState>
        <departureDate>11/04/2011 04:30:00</departureDate>
        <destinationCity>Bangalore</destinationCity>
        <destinationCountry>INDIA</destinationCountry>
        <destinationState>Karnataka</destinationState>
        <perFirstName>Duke</perFirstName>
        <perLastName>IMMELT</perLastName>
      </listing>
      <listing>
        <arrivalCity>BALTIMORE</arrivalCity>
        <arrivalCountry>USA</arrivalCountry>
        <arrivalState>MARYLAND</arrivalState>
        <departureDate>26/02/2006 12:15:00</departureDate>
        <destinationCity>AUGUSTA</destinationCity>
        <destinationCountry>USA</destinationCountry>
        <destinationState>GEORGIA</destinationState>
        <perFirstName>JEFFREY</perFirstName>
        <perLastName>IMMELT</perLastName>
      </listing>
      <listing>
        <arrivalCity>WHITE PLAINS</arrivalCity>
        <arrivalCountry>USA</arrivalCountry>
        <arrivalState>NEW YORK</arrivalState>
        <departureDate>15/06/2011 07:13:00</departureDate>
        <destinationCity>ATLANTA</destinationCity>
        <destinationCountry>USA</destinationCountry>
        <destinationState>GEORGIA</destinationState>
        <perFirstName>KEITH</perFirstName>
        <perLastName>SHERIN</perLastName>
      </listing>
      <listing>
        <arrivalCity>BRIDGEPORT</arrivalCity>
        <arrivalCountry>USA</arrivalCountry>
        <arrivalState>CONNECTICUT</arrivalState>
        <departureDate>19/04/2012 07:30:00</departureDate>
        <destinationCity>CINCINNATI</destinationCity>
        <destinationCountry>USA</destinationCountry>
        <destinationState>OHIO</destinationState>
        <perFirstName>KEITH</perFirstName>
        <perLastName>SHERIN</perLastName>
      </listing>
      <listing>
        <arrivalCity>DUSSELDORF</arrivalCity>
        <arrivalCountry>DEU</arrivalCountry>
        <arrivalState>NORDRHEIN-WESTFA</arrivalState>
        <departureDate>23/10/2007 09:05:00</departureDate>
        <destinationCity>MILAN</destinationCity>
        <destinationCountry>ITA</destinationCountry>
        <destinationState>LOMBARDIA</destinationState>
        <perFirstName>JEFFREY</perFirstName>
        <perLastName>IMMELT</perLastName>
      </listing>
      <listing>
        <arrivalCity>LOS ANGELES</arrivalCity>
        <arrivalCountry>USA</arrivalCountry>
        <arrivalState>CALIFORNIA</arrivalState>
        <departureDate>27/11/2007 10:45:00</departureDate>
        <destinationCity>WHITE PLAINS</destinationCity>
        <destinationCountry>USA</destinationCountry>
        <destinationState>NEW YORK</destinationState>
        <perFirstName>MICHAEL</perFirstName>
        <perLastName>NEAL</perLastName>
      </listing>
      <listing>
        <arrivalCity>SAN PEDRO SULA</arrivalCity>
        <arrivalCountry>HND</arrivalCountry>
        <arrivalState>CORTES</arrivalState>
        <departureDate>30/10/2007 04:00:00</departureDate>
        <destinationCity>ATLANTA</destinationCity>
        <destinationCountry>USA</destinationCountry>
        <destinationState>GEORGIA</destinationState>
        <perFirstName>JOHN</perFirstName>
        <perLastName>RICE</perLastName>
      </listing>
      <listing>
      <arrivalCity>SHENYANG</arrivalCity>
      <arrivalCountry>CHN</arrivalCountry>
      <arrivalState>LIAONING</arrivalState>
      <departureDate>14/06/2008 02:39:00</departureDate>
      <destinationCity>BEIJING</destinationCity>
      <destinationCountry>CHN</destinationCountry>
      <destinationState>BEIJING SHI</destinationState>
      <perFirstName>JEFFREY</perFirstName>
      <perLastName>IMMELT</perLastName>
      </listing>
      <listing>
        <arrivalCity>MEXICO CITY</arrivalCity>
        <arrivalCountry>MEXICO</arrivalCountry>
        <arrivalState>MEXICO</arrivalState>
        <departureDate>09/01/2007 05:15:00</departureDate>
        <destinationCity>TOLUCA (MEXICO C</destinationCity>
        <destinationCountry>MEX</destinationCountry>
        <destinationState>MEXICO</destinationState>
        <perFirstName>JEFFREY</perFirstName>
       <perLastName>IMMELT</perLastName>
      </listing>
      <listing>
        <arrivalCity>BRIDGEPORT</arrivalCity>
        <arrivalCountry>USA</arrivalCountry>
        <arrivalState>CONNECTICUT</arrivalState>
        <departureDate>03/10/2007 02:35:00</departureDate>
        <destinationCity>CHICAGO</destinationCity>
        <destinationCountry>USA</destinationCountry>
        <destinationState>ILLINOIS</destinationState>
        <perFirstName>JEFFREY</perFirstName>
        <perLastName>IMMELT</perLastName>
      </listing>
      <listing>
        <arrivalCity>PHILADELPHIA</arrivalCity>
        <arrivalCountry>USA</arrivalCountry>
        <arrivalState>PENNSYLVANIA</arrivalState>
        <departureDate>03/10/2007 07:15:00</departureDate>
        <destinationCity>CINCINNATI</destinationCity>
        <destinationCountry>USA</destinationCountry>
        <destinationState>OHIO</destinationState>
        <perFirstName>JOHN</perFirstName>
       <perLastName>RICE</perLastName>
      </listing>
      <listing>
        <arrivalCity>SIBLEY</arrivalCity>
        <arrivalCountry>USA</arrivalCountry>
        <arrivalState>IOWA</arrivalState>
        <departureDate>12/05/2010 07:00:00</departureDate>
        <destinationCity>NEW YORK</destinationCity>
        <destinationCountry>USA</destinationCountry>
        <destinationState>NEW YORK</destinationState>
        <perFirstName>JOHN</perFirstName>
        <perLastName>RICE</perLastName>
      </listing>
      <listing>
        <arrivalCity>ISLAMABAD</arrivalCity>
        <arrivalCountry>PAK</arrivalCountry>
        <arrivalState>PUNJAB</arrivalState>
        <departureDate>12/05/2010 07:00:00</departureDate>
        <destinationCity>NEW YORK</destinationCity>
        <destinationCountry>USA</destinationCountry>
        <destinationState>NEW YORK</destinationState>
        <perFirstName>JOHN</perFirstName>
        <perLastName>RICE</perLastName>
      </listing>
      <listing>
        <arrivalCity>JAMMU</arrivalCity>
        <arrivalCountry>IND</arrivalCountry>
        <arrivalState>INDIA</arrivalState>
        <departureDate>03/09/2010 07:00:00</departureDate>
        <destinationCity>NEW YORK</destinationCity>
        <destinationCountry>USA</destinationCountry>
        <destinationState>NEW YORK</destinationState>
        <perFirstName>JOHN</perFirstName>
       <perLastName>RICE</perLastName>
      </listing>
      <listing>
        <arrivalCity>WINDSOR LOCKS</arrivalCity>
        <arrivalCountry>USA</arrivalCountry>
        <arrivalState>CONNECTICUT</arrivalState>
        <departureDate>26/11/2010 07:00:00</departureDate>
        <destinationCity>LOUISVILLE</destinationCity>
        <destinationCountry>USA</destinationCountry>
        <destinationState>KENTUCKY</destinationState>
       <perFirstName>KEITH</perFirstName>
        <perLastName>SHERIN</perLastName>
      </listing>
      <listing>
        <arrivalCity>WHITE PLAINS</arrivalCity>
        <arrivalCountry>USA</arrivalCountry>
        <arrivalState>NEW YORK</arrivalState>
        <departureDate>04/12/2010 10:44:00</departureDate>
        <destinationCity>WINDSOR LOCKS</destinationCity>
        <destinationCountry>USA</destinationCountry>
        <destinationState>CONNECTICUT</destinationState>
        <perFirstName>JOHN</perFirstName>
        <perLastName>RICE</perLastName>
      </listing>
      <listing>
        <arrivalCity>BRAINERD</arrivalCity>
        <arrivalCountry>USA</arrivalCountry>
        <arrivalState>MINNESOTA</arrivalState>
        <departureDate>08/12/2010 04:12:00</departureDate>
        <destinationCity>WHITE PLAINS</destinationCity>
        <destinationCountry>USA</destinationCountry>
        <destinationState>NEW YORK</destinationState>
          <perFirstName>JOHN</perFirstName>
          <perLastName>RICE</perLastName>
      </listing>
    </executiveInfoListing>

    So inside a for loop I am parsing the xml preparing the address once for arriaval and once for destination and sending it to the GeocodeService for each address.

    The Geocode function calls the GeocodeService.GeocodeCompleted as an event, and I am also calling geocodeService.GeocodeAsync(request, execount);
    The execount will tell me which request was completed. When the event fires (that means, for one query the searching is done) and the Geocode Function that has the results is called.

    Inside that function I am getting the execount as this:
    int execount = System.Convert.ToInt32(e.UserState);
    But I'm getting a notfound exception sometimes  and the e.result does not return results for few addresses even if all of my places are valid. sometimes it works sometimes it gives error.

    please help me

    thanks in advance


    raghu
    • Moved by Ricky_Brundritt Friday, March 9, 2012 5:04 PM (From:Bing Maps: Map Control and Web services Development)
    Thursday, March 31, 2011 4:11 AM

Answers

  • Hello,

    Here is a fully working example in WinForm using your own kind of logic for UserState, it works as wanted:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Collections.ObjectModel;
    using WinMultiGeocode.GeocodeService;
    
    namespace WinMultiGeocode
    {
      public partial class MainForm : Form
      {
        public MainForm()
        {
          InitializeComponent();
    
          this.geocode(1, "Laventie, France", "A");
          this.geocode(2, "Armentieres, France", "A");
          this.geocode(3, "Lille, France", "A");
        }
        
        private void geocode(int execCount, string address, string strArrivalOrDeparture)
        {
          try
          {
            // Create the client
            GeocodeService.GeocodeServiceClient client = new GeocodeService.GeocodeServiceClient();
            client.GeocodeCompleted += new EventHandler<GeocodeService.GeocodeCompletedEventArgs>(client_GeocodeCompleted);
            
            GeocodeService.GeocodeRequest request = new GeocodeService.GeocodeRequest();
            request.Credentials = new GeocodeService.Credentials();
            request.Credentials.ApplicationId = "BINGMAPSKEY";
            request.Culture = "fr-FR";
            request.Address = new GeocodeService.Address() { AddressLine = address };
            request.ExecutionOptions = new GeocodeService.ExecutionOptions();
            request.ExecutionOptions.SuppressFaults = true;
    
            request.Options = new GeocodeService.GeocodeOptions();
            // Using ObservableCollection since this is the default for Silverlight proxy generation.
            request.Options.Filters = (new List<FilterBase>()).ToArray();
            GeocodeService.ConfidenceFilter objConfidenceFilter = new GeocodeService.ConfidenceFilter();
            objConfidenceFilter.MinimumConfidence = GeocodeService.Confidence.High;
            ((List<FilterBase>)request.Options.Filters.ToList()).Add(objConfidenceFilter);
    
            client.GeocodeAsync(request, execCount.ToString() + "/" + strArrivalOrDeparture);
          }
          catch (Exception ex)
          {
            throw ex;
            //ErrorLogger.WriteLogFile(this.GetType().Name, "GeoCodeAddress()", ex.Message.ToString());
          }
        }
    
        void client_GeocodeCompleted(object sender, GeocodeService.GeocodeCompletedEventArgs e)
        {
          MessageBox.Show(e.UserState.ToString() + "=" + e.Result.Results[0].DisplayName);
        }
      }
    }
    
    

    MVP - Bing Maps - My blog (FR): http://blogs.developpeur.org/nicoboo/ Twitter: http://twitter.com/nicolasboonaert/
    Sunday, April 3, 2011 10:47 PM
    Moderator
  • You should check the response status before trying to extract information from the response element:

    http://msdn.microsoft.com/en-us/library/cc980902.aspx

    The only thing that can help you to trap this error will be to check if the request did well by using the properties from the ResponseSummary as presented in this documentation page.


    MVP - Bing Maps - My blog (FR): http://blogs.developpeur.org/nicoboo/ Twitter: http://twitter.com/nicolasboonaert/
    Tuesday, April 5, 2011 1:07 PM
    Moderator

All replies

  • I've tried the geocode service using the UserState as a parameter like you.
    It works as wanted. You should try to inspect the value of "e" in order to check the StatusCode in the response Summary (see: http://msdn.microsoft.com/en-us/library/cc980902.aspx).

    Could you post the code used to call the WS if needed and the details about your notfound exception (when it occured.. at what moment in your code)?


    MVP - Bing Maps - My blog (FR): http://blogs.developpeur.org/nicoboo/ Twitter: http://twitter.com/nicolasboonaert/
    Thursday, March 31, 2011 1:48 PM
    Moderator
  • I have a static object to store a list of arrival and departure information

    public static List<ExecutiveInfo> objExecutives = null;

    after getting data from the xml and storing it in to list im looping through the list as below :

     public class ExecutiveInfo
        {
            public string FirstName { get; set; }
            public string LastName { get; set; }
            public string PersonID { get; set; }
            public string BusinessUnit { get; set; }
            public string ArrivalCity { get; set; }
            public string ArrivalState { get; set; }
            public string ArrivalCountry { get; set; }
            public double ArrivalCityLat { get; set; }
            public double ArrivalCityLong { get; set; }
            public string DepartureCity { get; set; }
            public string DepartureState { get; set; }
            public string DepartureCountry { get; set; }
            public double DepartureCityLat { get; set; }
            public double DepartureCityLong { get; set; }
            public DateTime DepartureDate { get; set; }
            public int Counter { get; set; }
            public string Message { get; set; }
        }

     


    char[] FORWARD_SLASH_SPLIT_CHAR = new char[] { '/' };

     const string A = "A";
    const string D = "D";
    const string SLASH = "/";
    int CounterforAll = 0;

     
     public void GeocodeExecutivesAddress(string strSender)
            {
                GMappingTool.GeocodeService.Address objAddress = null;

                for (int execCount = 0; execCount < MainPage.objExecutives.Count; execCount++)
                {
                    objAddress = new GMappingTool.GeocodeService.Address();
                    if (MainPage.objExecutives[execCount].DepartureDate.Date == DateTime.Today.Date)
                    {
                        if (string.IsNullOrEmpty(MainPage.objExecutives[execCount].ArrivalCity) == false)
                        {
                            objAddress.PostalTown = MainPage.objExecutives[execCount].ArrivalCity;
                        }
                        if (string.IsNullOrEmpty(MainPage.objExecutives[execCount].ArrivalState) == false)
                        {
                            objAddress.AdminDistrict = MainPage.objExecutives[execCount].ArrivalState;
                        }
                        if (string.IsNullOrEmpty(MainPage.objExecutives[execCount].ArrivalCountry) == false)
                        {
                            objAddress.CountryRegion = MainPage.objExecutives[execCount].ArrivalCountry;
                        }
      
      GeoCodeAddress(execCount, objAddress, A);

                    objAddress = new GMappingTool.GeocodeService.Address();

                        if (string.IsNullOrEmpty(MainPage.objExecutives[execCount].DepartureCity) == false)
                        {
                            objAddress.PostalTown = MainPage.objExecutives[execCount].DepartureCity;
                        }
                        if (string.IsNullOrEmpty(MainPage.objExecutives[execCount].DepartureState) == false)
                        {
                            objAddress.AdminDistrict = MainPage.objExecutives[execCount].DepartureState;
                        }
                        if (string.IsNullOrEmpty(MainPage.objExecutives[execCount].DepartureCountry) == false)
                        {
                            objAddress.CountryRegion = MainPage.objExecutives[execCount].DepartureCountry;
                        }

      GeoCodeAddress(execCount, objAddress, D);
                    }
                   
                }
            }


     private void GeoCodeAddress(int execCount, GMappingTool.GeocodeService.Address objAddress, string strArrivalOrDeparture)
            {
                try
                {
                  
                    GeocodeService.GeocodeRequest objGeocodeRequest = new GeocodeService.GeocodeRequest();
                    objGeocodeRequest.Culture = GeoCodeCalc.MainPageInstance.mapView.bingMapInstance.Culture;
                    objGeocodeRequest.Address = objAddress;
                    objGeocodeRequest.ExecutionOptions = new GeocodeService.ExecutionOptions();
                    objGeocodeRequest.ExecutionOptions.SuppressFaults = true;

                    objGeocodeRequest.Options = new GeocodeService.GeocodeOptions();
                    // Using ObservableCollection since this is the default for Silverlight proxy generation.
                    objGeocodeRequest.Options.Filters = new ObservableCollection<GeocodeService.FilterBase>();
                    GeocodeService.ConfidenceFilter objConfidenceFilter = new GeocodeService.ConfidenceFilter();
                    objConfidenceFilter.MinimumConfidence = GeocodeService.Confidence.High;
                    objGeocodeRequest.Options.Filters.Add(objConfidenceFilter);

                    GeoCodeCalc.MainPageInstance.mapView.bingMapInstance.CredentialsProvider.GetCredentials(
                        (Credentials credentials) =>
                        {
                            //Pass in credentials for web services call.
                            objGeocodeRequest.Credentials = new GMappingTool.GeocodeService.Credentials();
                            objGeocodeRequest.Credentials.ApplicationId = "Ancetv8N9CpdEM4lVPZ4uZuDuJJX3fPutGPCKUfSFf7ef4Z7Foz50glnQWheT-dE";

                            // Make asynchronous call to fetch the data ... pass state object.
                          
                            GeocodeClient.GeocodeAsync(objGeocodeRequest, execCount.ToString() + SLASH + strArrivalOrDeparture);
                         
                        });
                }
                catch (Exception ex)
                {
                    ErrorLogger.WriteLogFile(this.GetType().Name, "GeoCodeAddress()", ex.Message.ToString());
                }
            }

     private GeocodeService.GeocodeServiceClient GeocodeClient
            {
                get
                {
                    try
                    {
                        if (null == geocodeClient)
                        {
                            //Handle http/https; OutOfBrowser is currently supported on the MapControl only for http pages
                            bool httpsUriScheme = !Application.Current.IsRunningOutOfBrowser && HtmlPage.Document.DocumentUri.Scheme.Equals(Uri.UriSchemeHttps);
                            BasicHttpBinding binding = httpsUriScheme ? new BasicHttpBinding(BasicHttpSecurityMode.Transport) : new BasicHttpBinding(BasicHttpSecurityMode.None);
                            UriBuilder serviceUri = new UriBuilder("http://dev.virtualearth.net/webservices/v1/GeocodeService/GeocodeService.svc");
                            if (httpsUriScheme)
                            {
                                //For https, change the UriSceheme to https and change it to use the default https port.
                                serviceUri.Scheme = Uri.UriSchemeHttps;
                                serviceUri.Port = -1;
                            }

                            //Create the Service Client
                            geocodeClient = new GeocodeService.GeocodeServiceClient(binding, new EndpointAddress(serviceUri.Uri));
                            geocodeClient.GeocodeCompleted += new EventHandler<GeocodeService.GeocodeCompletedEventArgs>(geocodeService_GeocodeCompleted);
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorLogger.WriteLogFile(this.GetType().Name, "GeocodeClient property.", ex.Message.ToString());
                    }
                    return geocodeClient;
                }
            }


            void geocodeService_GeocodeCompleted(object sender, GeocodeService.GeocodeCompletedEventArgs e)
            {
                // Callback when the geocode is finished.
                string outString;
              

        // here im getting the e.userstate as i have described in my earlier post
     
                string[] strUserStates = e.UserState.ToString().Split(FORWARD_SLASH_SPLIT_CHAR);

                if (strUserStates.Length == 2)
                {
      int execCount = Convert.ToInt16(strUserStates[0]);

                    MainPage.objExecutives[execCount].Counter += 1;
                    CounterforAll += 1;
                    try
                    {
                        if (e.Result.ResponseSummary.StatusCode != GeocodeService.ResponseStatusCode.Success)
                        {
                            outString = "error geocoding ... status <" + e.Result.ResponseSummary.StatusCode.ToString() + ">";
                            ErrorLogger.WriteLogFile(this.GetType().Name, "geocodeService_GeocodeCompleted", outString);
                        }
                        else if (e.Result.Results.Count == 0)
                        {
                            try
                            {
                                outString = "No results";
                                ErrorLogger.WriteLogFile(this.GetType().Name, "geocodeService_GeocodeCompleted", outString);
                            }
                            catch (Exception ex)
                            {
                                ErrorLogger.WriteLogFile(this.GetType().Name, "geocodeService_GeocodeCompleted", ex.Message.ToString());
                            }

                        }
                     
                        if (strUserStates[1] == A)
                        {
                            MainPage.objExecutives[execCount].ArrivalCityLat = e.Result.Results[0].Locations[0].Latitude;
                            MainPage.objExecutives[execCount].ArrivalCityLong = e.Result.Results[0].Locations[0].Longitude;
                        }
                        else if (strUserStates[1] == D)
                        {
                            MainPage.objExecutives[execCount].DepartureCityLat = e.Result.Results[0].Locations[0].Latitude;
                            MainPage.objExecutives[execCount].DepartureCityLong = e.Result.Results[0].Locations[0].Longitude;
                        }

                        if (MainPage.objExecutives[execCount].Counter == 2)
                        {
                            delGEExecutives delgeexecutives = new delGEExecutives(GeoCodeCalc.MainPageInstance.DelegateGEExecutives);
                            if (delgeexecutives != null)
                            {
                                delgeexecutives(execCount);
                            }
                        }
                    }
                  
                    catch (Exception ex)
                    {
                        ErrorLogger.WriteLogFile(this.GetType().Name, "geocodeService_GeocodeCompleted", ex.Message.ToString());
                        outString = "Exception raised";
                    }
                    finally
                    {
                        if (MainPage.objExecutives.Count * 2 == CounterforAll)
                        {
                            GeoCodeCalc.MainPageInstance.waitingIconState.IsBusy = false;
                        }
                    }

                }
            }
         
    when i executive the code i'm getting NOT Found error in the Reference.cs file at runtime

    public GMappingTool.GeocodeService.GeocodeResponse EndGeocode(System.IAsyncResult result) {
                    object[] _args = new object[0];
                    GMappingTool.GeocodeService.GeocodeResponse _result = ((GMappingTool.GeocodeService.GeocodeResponse)(base.EndInvoke("Geocode", _args, result)));
                    return _result;

                }
    this is the error description : The remote server returned an error: NotFound.

    Please help me as im not able to figure out since the exception is in EndInoke delegate instance of geocode service

    thanks in advance


    raghu
    Friday, April 1, 2011 3:36 AM
  • Hello,

    Here is a fully working example in WinForm using your own kind of logic for UserState, it works as wanted:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Collections.ObjectModel;
    using WinMultiGeocode.GeocodeService;
    
    namespace WinMultiGeocode
    {
      public partial class MainForm : Form
      {
        public MainForm()
        {
          InitializeComponent();
    
          this.geocode(1, "Laventie, France", "A");
          this.geocode(2, "Armentieres, France", "A");
          this.geocode(3, "Lille, France", "A");
        }
        
        private void geocode(int execCount, string address, string strArrivalOrDeparture)
        {
          try
          {
            // Create the client
            GeocodeService.GeocodeServiceClient client = new GeocodeService.GeocodeServiceClient();
            client.GeocodeCompleted += new EventHandler<GeocodeService.GeocodeCompletedEventArgs>(client_GeocodeCompleted);
            
            GeocodeService.GeocodeRequest request = new GeocodeService.GeocodeRequest();
            request.Credentials = new GeocodeService.Credentials();
            request.Credentials.ApplicationId = "BINGMAPSKEY";
            request.Culture = "fr-FR";
            request.Address = new GeocodeService.Address() { AddressLine = address };
            request.ExecutionOptions = new GeocodeService.ExecutionOptions();
            request.ExecutionOptions.SuppressFaults = true;
    
            request.Options = new GeocodeService.GeocodeOptions();
            // Using ObservableCollection since this is the default for Silverlight proxy generation.
            request.Options.Filters = (new List<FilterBase>()).ToArray();
            GeocodeService.ConfidenceFilter objConfidenceFilter = new GeocodeService.ConfidenceFilter();
            objConfidenceFilter.MinimumConfidence = GeocodeService.Confidence.High;
            ((List<FilterBase>)request.Options.Filters.ToList()).Add(objConfidenceFilter);
    
            client.GeocodeAsync(request, execCount.ToString() + "/" + strArrivalOrDeparture);
          }
          catch (Exception ex)
          {
            throw ex;
            //ErrorLogger.WriteLogFile(this.GetType().Name, "GeoCodeAddress()", ex.Message.ToString());
          }
        }
    
        void client_GeocodeCompleted(object sender, GeocodeService.GeocodeCompletedEventArgs e)
        {
          MessageBox.Show(e.UserState.ToString() + "=" + e.Result.Results[0].DisplayName);
        }
      }
    }
    
    

    MVP - Bing Maps - My blog (FR): http://blogs.developpeur.org/nicoboo/ Twitter: http://twitter.com/nicolasboonaert/
    Sunday, April 3, 2011 10:47 PM
    Moderator
  • Hi Nicolas,

    Thanks for your help,.. i m doing exactly the same as you have suggested in your reply.. i think we are sending the city, state and country which the geocode not able to recognize and pick the lat and long... can you please help me is there any way to handle this NotFound exception.

    Thanks in advance

     


    raghu
    Tuesday, April 5, 2011 5:26 AM
  • You should check the response status before trying to extract information from the response element:

    http://msdn.microsoft.com/en-us/library/cc980902.aspx

    The only thing that can help you to trap this error will be to check if the request did well by using the properties from the ResponseSummary as presented in this documentation page.


    MVP - Bing Maps - My blog (FR): http://blogs.developpeur.org/nicoboo/ Twitter: http://twitter.com/nicolasboonaert/
    Tuesday, April 5, 2011 1:07 PM
    Moderator
  • Hi Nicolas Boonaert,

    Could not figure out why is that "Not Found Exception " , planning to use REST Api and pass country and city and state information , get the xml response and parse the xml response to get the Latitude and Longitude Information

    Thanks for your kind reply..

    Thanks and Regards


    raghu
    Friday, April 8, 2011 4:39 AM