<%@ WebHandler Language="C#" Class="addressLookup" %> using System; using System.Web; public class addressLookup : IHttpHandler { // calls http://rpc.geocoder.us/dist/eg/clients/GeoCoder.wsdl public void ProcessRequest (HttpContext context) { String myAddress = ""; String myLatitude = ""; String myLongitude = ""; String myError = " "; String myHelp = "; its value should be formed like '154 Nassau St, Princeton, NJ 08540'"; myAddress = context.Request.Params.Get("address"); if (myAddress == null) { myError = "parameter 'address' was null" + myHelp; } else { if (myAddress.Length == 0) { myError = "parameter 'address' was empty string" + myHelp; } else { // argument exists try { us.geocoder.rpc.GeoCode_Service myService = new us.geocoder.rpc.GeoCode_Service(); us.geocoder.rpc.GeocoderAddressResult[] results = null; results = myService.geocode_address(myAddress); if (results.Length > 0) // this fails if no result { myLatitude = results[0].lat.ToString(); myLongitude = results[0].@long.ToString(); } else { myError = "no results"; } } catch (Exception ex) { myError = ex.Message; } } // end else argument exists } // end else argument not null context.Response.Write(""); context.Response.ContentType = "text/xml"; context.Response.AddHeader("Cache-Control", "no-cache"); context.Response.Write(""); context.Response.Write("" + myLatitude + ""); context.Response.Write("" + myLongitude + ""); context.Response.Write("" + myError + ""); context.Response.Write(""); } // end ProcessRequest public bool IsReusable { get { return false; } } }