none
Coffee Shops Nearby RRS feed

  • Question

  • Hi, I am trying a simple search for "coffee" shops nearby, using the following code on Windows Phone 8

    SearchServiceClient searchService = new SearchServiceClient("BasicHttpBinding_ISearchService");
            private void SearchKeywordLocation(double latitude, double longitude)
            {
                try
                {
    		searchService.SearchCompleted += new EventHandler<SearchService.SearchCompletedEventArgs>(MySearchCompleted);
    
                    SearchService.SearchRequest  mySearchRequest = new SearchService.SearchRequest();
                    mySearchRequest.Credentials = new SearchService.Credentials();
                    mySearchRequest.Credentials.ApplicationId = "<Bing Maps Key>";
    
    		SearchService.StructuredSearchQuery ssQuery = new SearchService.StructuredSearchQuery();
                    ssQuery.Keyword = "Coffee";
                    ssQuery.Location = latitude.ToString() + ", " + longitude.ToString();
                    mySearchRequest.StructuredQuery = ssQuery;
    
    		searchService.SearchAsync(mySearchRequest);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }  
    }
    
    	private void MySearchCompleted (object sender, SearchCompletedEventArgs e)
            {
    		SearchResponse searchResponse = e.Result;
                	......
              }

    But this throws an exception in the result returned ? I have added a service reference to Search Service, as that is what I am using. Can you please help me figure out the cause?

    System.ServiceModel.Dispatcher.NetDispatcherFaultException was unhandled by user code
      HResult=-2146233087
      Message=The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://dev.virtualearth.net/webservices/v1/search/contracts:SearchResult. The InnerException message was 'Error in line 1 position 1321. Element 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:anyType' contains data of the 'http://dev.virtualearth.net/webservices/v1/search:Neighborhood' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'Neighborhood' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'.  Please see InnerException for more details.
      Source=System.ServiceModel

    Friday, April 5, 2013 6:40 AM

Answers

All replies

  • I highly recommend using the REST services instead as they are much faster than the old, legacy SOAP services. Take a look at this blog post: http://rbrundritt.wordpress.com/2012/01/17/dynamically-updating-data-in-bing-maps-v7/

    Coffee shops have an Entity Type ID of 9996

    Here is some more information on these services: http://msdn.microsoft.com/en-us/library/hh478189.aspx


    http://rbrundritt.wordpress.com

    • Proposed as answer by Ricky_Brundritt Wednesday, April 10, 2013 9:42 PM
    • Unproposed as answer by vj9 Thursday, April 11, 2013 8:38 AM
    • Proposed as answer by Ricky_Brundritt Thursday, April 11, 2013 3:36 PM
    • Marked as answer by Ricky_Brundritt Wednesday, April 17, 2013 3:33 PM
    Wednesday, April 10, 2013 9:42 PM
  • Hi Richard

    But, as far as the msdn blog is concerned - it seems that I am hampered by the fact, that I need to use one of the public Data Sources to query, what do  I do if I wish to make something more global ( not limited to North America or Europe ) ??

    Thursday, April 11, 2013 8:21 AM
  • If you really want to go the SOAP route then try updating your service reference. It looks like it is having issues parsing the responses. Note that you won't find much more data in the SOAP services. In fact the SOAP services have no data for France due to some licensing restrictions with the data we have for that region. This was resolved with the public data sources through the Bing Spatial Data Services.

    http://rbrundritt.wordpress.com

    • Proposed as answer by Ricky_Brundritt Thursday, April 11, 2013 3:36 PM
    • Marked as answer by Ricky_Brundritt Wednesday, April 17, 2013 3:33 PM
    • Unmarked as answer by vj9 Thursday, April 18, 2013 6:54 AM
    • Marked as answer by Ricky_Brundritt Tuesday, May 28, 2013 8:36 AM
    Thursday, April 11, 2013 3:36 PM
  • Hi, I am trying a simple search for "coffee" shops nearby, using the following code on Windows Phone 8

    SearchServiceClient searchService = new SearchServiceClient("BasicHttpBinding_ISearchService");
            private void SearchKeywordLocation(double latitude, double longitude)
            {
                try
                {
    		searchService.SearchCompleted += new EventHandler<SearchService.SearchCompletedEventArgs>(MySearchCompleted);
    
                    SearchService.SearchRequest  mySearchRequest = new SearchService.SearchRequest();
                    mySearchRequest.Credentials = new SearchService.Credentials();
                    mySearchRequest.Credentials.ApplicationId = "<Bing Maps Key>";
    
    		SearchService.StructuredSearchQuery ssQuery = new SearchService.StructuredSearchQuery();
                    ssQuery.Keyword = "Coffee";
                    ssQuery.Location = latitude.ToString() + ", " + longitude.ToString();
                    mySearchRequest.StructuredQuery = ssQuery;
    
    		searchService.SearchAsync(mySearchRequest);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }  
    }
    
    	private void MySearchCompleted (object sender, SearchCompletedEventArgs e)
            {
    		SearchResponse searchResponse = e.Result;
                	......
              }

    But this throws an exception in the result returned ? I have added a service reference to Search Service, as that is what I am using. Can you please help me figure out the cause?

    System.ServiceModel.Dispatcher.NetDispatcherFaultException was unhandled by user code
      HResult=-2146233087
      Message=The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://dev.virtualearth.net/webservices/v1/search/contracts:SearchResult. The InnerException message was 'Error in line 1 position 1321. Element 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:anyType' contains data of the 'http://dev.virtualearth.net/webservices/v1/search:Neighborhood' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'Neighborhood' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'.  Please see InnerException for more details.
      Source=System.ServiceModel


    Got similar exception. The code works with Windoes Phone 7.x SDK but not with Windows Phone 8 SDK, so not sure if WP8 will support Bing Map SOAP Search Service.
    Tuesday, May 14, 2013 4:14 AM