none
Failed to compile code to call Bing Map REST service. RRS feed

  • Question

  • Hi all, 

    Refering to http://msdn.microsoft.com/en-us/library/jj819168.aspx , I wrote a C# file to call Bing Map REST service. But it can't be compiled because of lacking definition to 'Response' class. 

    Is there anyone know which library I should reference to resolve this problem?

    Any help is appreciated.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Runtime.Serialization.Json;
    using System.Text;
    using System.Threading.Tasks;
    using System.Runtime.Serialization;
    using System.ServiceModel.Web;
    
    namespace TestRESTService_2
    {
    	class Program
    	{
    		static void Main(string[] args)
    		{
    			string key = "YOUR_BING_MAPS_KEY or SESSION_KEY";
    			string query = "1 Microsoft Way, Redmond, WA";
    
    			Uri geocodeRequest = new Uri(string.Format("http://dev.virtualearth.net/REST/v1/Locations?q={0}&key={1}", query, key));
    
    			GetResponse(geocodeRequest, (x) =>
    			{
    				Console.WriteLine(x.ResourceSets[0].Resources.Length + " result(s) found.");
    				Console.ReadLine();
    			});
    
    			Console.ReadLine();
    		}
    
    		private static void GetResponse(Uri uri, Action<Response> callback)
    		{
    			WebClient wc = new WebClient();
    			wc.OpenReadCompleted += (o, a) =>
    			{
    				if (callback != null)
    				{
    					DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Response));
    					callback(ser.ReadObject(a.Result) as Response);
    				}
    			};
    			wc.OpenReadAsync(uri);
    		}
    	}
    }

    Wednesday, February 20, 2013 9:35 PM

Answers

  • The bottom of the documentation you are using points to the Data contracts you need for the REST services which are available here: http://msdn.microsoft.com/en-us/library/jj870778.aspx Simply create a empty C# file and copy in paste in the C# Data Contracts. Then add the namespace to this class: using BingMapsRESTService.Common.JSON;

    http://rbrundritt.wordpress.com

    • Proposed as answer by Ricky_Brundritt Wednesday, February 20, 2013 10:02 PM
    • Marked as answer by shi_hang_nk Wednesday, February 20, 2013 10:22 PM
    Wednesday, February 20, 2013 10:02 PM

All replies