<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>C#</title>
        <link>http://geekswithblogs.net/JuanDoNeblo/category/7201.aspx</link>
        <description>Our language of choice ;)</description>
        <language>en-GB</language>
        <copyright>Marco Anastasi &amp; Serena Caruso</copyright>
        <managingEditor>marcoanastasi@tiscali.it</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Showing ESRI Shapefile Layers on a Virtual Earth Map: a simple HowTo</title>
            <link>http://geekswithblogs.net/JuanDoNeblo/archive/2008/04/13/showing-esri-shapefile-layers-on-a-virtual-earth-map.aspx</link>
            <description>&lt;p&gt;If you've ever tried to find a way to display an ESRI ShapeFile on a Virtual Earth map, you'll have probably noticed how little information there is on the Internet about how to accomplish this apparently arduous task.&lt;/p&gt;  &lt;p&gt;As a matter of fact, I needed to do exactly this while adding some collateral features to the software Serena and I are developing for our thesis, but after some Googling, I found that there was (and there still is) almost no useful information on how to achieve integration between Virtual Earth and ESRI Shapefiles. &lt;/p&gt;  &lt;p&gt;So I had to figure out what I judge a rather clean solution by myself. After all, I thought I could fill the void on this topic and help someone else avoid to switch "lazy mode" off by writing an article about it ;)&lt;/p&gt;  &lt;p&gt;By the way, with the technique I'm describing, you're going to be able to not only display Shapefiles as layers on Virtual Earth, but also interact with them in countless ways: extract data from them, show data associated with a shape when you click on it on the map, even modify or create new Shapefiles (Although only showing and querying the map are going to be covered in this post). All of this care of SharpMap, one of the best (if not the best) open source .NET libraries for GIS.&lt;/p&gt;  &lt;p&gt;Actually, &lt;a href="http://www.codeplex.com/SharpMap" target="_blank"&gt;SharpMap&lt;/a&gt; does much, much more than this... it even has a performing rendering engine for spatial data, so it really is an understatement to think of it as a mere instrument to get ESRI data into our Virtual Earth maps. In fact I strongly recommend to go and give a look at the &lt;a href="http://www.codeplex.com/SharpMap" target="_blank"&gt;SharpMap&lt;/a&gt; project page on &lt;a href="http://www.codeplex.com/" target="_blank"&gt;CodePlex&lt;/a&gt;.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;strong&gt;SharpMap versions&lt;/strong&gt;&lt;/p&gt;    &lt;p&gt;SharpMap 2.0 is currently in beta stage. The currently stable release is 0.9. Version 2.0 beta is not radically different from version 0.9, at least for the parts of the library that we're going to use, so feel free to resort to the stable version if you feel more at ease, but I thought worthy to use version 2.0 beta in my project because of a rather important addition, i.e. the possibility to &lt;strong&gt;write&lt;/strong&gt; on Shapefiles as well as read them, which to my knowledge wasn't present in the 0.9 version. Obviously, if your application doesn't require to modify or create Shapefiles, you can safely fall back to the 0.9 version.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt; &lt;/p&gt;  &lt;h4&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/ShowingESRIShapefileLayersonaVirtualEart_E26E/ScreenShot028_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="278" alt="A Shapefile containing Great Britain's Administrative Areas" src="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/ShowingESRIShapefileLayersonaVirtualEart_E26E/ScreenShot028_thumb.png" width="304" align="right" border="0" /&gt;&lt;/a&gt;&lt;/h4&gt;  &lt;h4&gt; &lt;/h4&gt;  &lt;h3&gt;The idea.&lt;/h3&gt;  &lt;p&gt;Let's suppose that we have a Shapefile containing polygons which represent the administrative regions of the United Kingdom, and that we want to overlay that on the map. &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;First of all we need to extract the polygon data from the Shapefile, and convert all the polygons to a format readable by Virtual Earth. Each "part" in the Shapefile will become a "polygon shape" in Virtual Earth. In this phase, we will leverage SharpMap's ability to parse Shapefiles to .NET objects. &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;List&lt;/span&gt;&lt;span style="color: black"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;Shape&lt;/span&gt;&lt;span style="color: black"&gt;&amp;gt; LoadShapefileLayer(&lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&lt;span style="color: black"&gt; filePath)  &lt;br /&gt;{  &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;Random&lt;/span&gt;&lt;span style="color: black"&gt; random = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;Random&lt;/span&gt;&lt;span style="color: black"&gt;((&lt;/span&gt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&lt;span style="color: black"&gt;)&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;DateTime&lt;/span&gt;&lt;span style="color: black"&gt;.Now.Ticks);  &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: green"&gt;// SharpMap's Shapefile reader / writer      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;    ShapeFileProvider&lt;/span&gt;&lt;span style="color: black"&gt; sf = &lt;/span&gt;&lt;span style="color: blue"&gt;null&lt;/span&gt;&lt;span style="color: black"&gt;;  &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;try  &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;    {  &lt;br /&gt;        sf = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;ShapeFileProvider&lt;/span&gt;&lt;span style="color: black"&gt;(filePath);  &lt;br /&gt;        sf.Open(&lt;/span&gt;&lt;span style="color: blue"&gt;false&lt;/span&gt;&lt;span style="color: black"&gt;);  &lt;br /&gt;&lt;/span&gt;&lt;/div&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;&lt;span style="color: black"&gt;&lt;/span&gt;&lt;/div&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;&lt;span style="color: blue"&gt;        if&lt;/span&gt;&lt;span style="color: black"&gt; (sf.ShapeType != &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;ShapeType&lt;/span&gt;&lt;span style="color: black"&gt;.Polygon)  &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;null&lt;/span&gt;&lt;span style="color: black"&gt;;  &lt;br /&gt;      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: green"&gt;// Initializing the list of Shapes to be returned  &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;        List&lt;/span&gt;&lt;span style="color: black"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;Shape&lt;/span&gt;&lt;span style="color: black"&gt;&amp;gt; layer = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;List&lt;/span&gt;&lt;span style="color: black"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;Shape&lt;/span&gt;&lt;span style="color: black"&gt;&amp;gt;();  &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: green"&gt;// Retrieving all the geometries in the Shapefile      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;        BoundingBox&lt;/span&gt;&lt;span style="color: black"&gt; ext = sf.GetExtents();  &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;IEnumerable&lt;/span&gt;&lt;span style="color: black"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;Geometry&lt;/span&gt;&lt;span style="color: black"&gt;&amp;gt; geometries = sf.ExecuteGeometryIntersectionQuery(ext);  &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: green"&gt;// Iterating through all the geometries in the shapefile, converting them  &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;        &lt;/span&gt;&lt;span style="color: green"&gt;// to Shape objects and adding them to the output list      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;        foreach&lt;/span&gt;&lt;span style="color: black"&gt; (&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;Geometry&lt;/span&gt;&lt;span style="color: black"&gt; geometry &lt;/span&gt;&lt;span style="color: blue"&gt;in&lt;/span&gt;&lt;span style="color: black"&gt; geometries)  &lt;br /&gt;        {  &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;List&lt;/span&gt;&lt;span style="color: black"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;PointF&lt;/span&gt;&lt;span style="color: black"&gt;&amp;gt; points = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;List&lt;/span&gt;&lt;span style="color: black"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;PointF&lt;/span&gt;&lt;span style="color: black"&gt;&amp;gt;();  &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;Polygon&lt;/span&gt;&lt;span style="color: black"&gt; polygon = geometry &lt;/span&gt;&lt;span style="color: blue"&gt;as&lt;/span&gt;&lt;span style="color: black"&gt; SharpMap.Geometries.&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;Polygon&lt;/span&gt;&lt;span style="color: black"&gt;;  &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: green"&gt;/* Verify that the geometry is actually a polygon. If it is not, just skip it.  &lt;br /&gt;             * Multipolygon support is not yet added */  &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (polygon != &lt;/span&gt;&lt;span style="color: blue"&gt;null&lt;/span&gt;&lt;span style="color: black"&gt;)  &lt;br /&gt;            {  &lt;br /&gt;                &lt;/span&gt;&lt;span style="color: blue"&gt;foreach&lt;/span&gt;&lt;span style="color: black"&gt; (&lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; vertex &lt;/span&gt;&lt;span style="color: blue"&gt;in&lt;/span&gt;&lt;span style="color: black"&gt; polygon.ExteriorRing.Vertices)  &lt;br /&gt;                    points.Add(&lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;PointF&lt;/span&gt;&lt;span style="color: black"&gt;((&lt;/span&gt;&lt;span style="color: blue"&gt;float&lt;/span&gt;&lt;span style="color: black"&gt;)vertex.X, (&lt;/span&gt;&lt;span style="color: blue"&gt;float&lt;/span&gt;&lt;span style="color: black"&gt;)vertex.Y));  &lt;br /&gt;                &lt;br /&gt;&lt;span style="color: green"&gt;                /* Each shape is assigned a random colour, to create&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;&lt;span style="color: black"&gt;&lt;span style="color: green"&gt;                 * the effect of a political map */&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;&lt;span style="color: black"&gt;                &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;Color&lt;/span&gt;&lt;span style="color: black"&gt; randomColour = &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;Color&lt;/span&gt;&lt;span style="color: black"&gt;.FromArgb(75,  &lt;br /&gt;                    random.Next(255), random.Next(255), random.Next(255));  &lt;br /&gt;                layer.Add(&lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;Shape&lt;/span&gt;&lt;span style="color: black"&gt;(points, randomColour));  &lt;br /&gt;            }  &lt;br /&gt;        }  &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: black"&gt; layer;  &lt;br /&gt;    }  &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;finally  &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;    {  &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (sf != &lt;/span&gt;&lt;span style="color: blue"&gt;null&lt;/span&gt;&lt;span style="color: black"&gt;)  &lt;br /&gt;            sf.Close();  &lt;br /&gt;    }  &lt;br /&gt;} &lt;/span&gt;&lt;/div&gt;  &lt;p&gt;&lt;span style="color: black"&gt;&lt;/span&gt;&lt;span style="color: black"&gt;&lt;/span&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;This example only covers the importing of Polygon-based Shapefiles, but it can easily be extended to support Polylines and Points&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Next, we need to make this data available to the Virtual Earth Map. We can do this by leveraging ASP.NET AJAX ScriptServices. To make a long story short, in order to use the converted data with the Virtual Earth API, on the client side, we need to create an ASP.NET web service, and decorate it with the &lt;strong&gt;[ScriptService]&lt;/strong&gt; attribute. This will instruct the ASP.NET engine to create a Javascript helper class and make this method callable from client code in the page. &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;If you want to know more about the details of this process, the underlying communication protocol and different ways to leverage it, I recommend you to read my series of posts on "How to integrate JSON web services in an ASP.NET AJAX web application" &lt;a href="http://geekswithblogs.net/JuanDoNeblo/archive/2007/11/08/How-to-integrate-JSON-web-services-in-an-ASP.NET-AJAX.aspx" target="_blank"&gt;here&lt;/a&gt;. You could also find my previous post on how to create a simple Virtual Earth Mashup useful. You can find it &lt;a href="http://geekswithblogs.net/JuanDoNeblo/archive/2007/11/13/Getting-started-with-Virtual-Earth-Mashups-showing-current-weather-conditions.aspx" target="_blank"&gt;here&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt; &lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;[&lt;span style="color: rgb(43,145,175)"&gt;WebService&lt;/span&gt;&lt;span style="color: black"&gt;]      &lt;br /&gt;[&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;WebServiceBinding&lt;/span&gt;&lt;span style="color: black"&gt;(ConformsTo = &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;WsiProfiles&lt;/span&gt;&lt;span style="color: black"&gt;.BasicProfile1_1)]      &lt;br /&gt;[&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;ScriptService&lt;/span&gt;&lt;span style="color: black"&gt;]      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;MapService&lt;/span&gt;&lt;span style="color: black"&gt; : &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;WebService      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;{      &lt;br /&gt;    [&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;WebMethod&lt;/span&gt;&lt;span style="color: black"&gt;]      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;List&lt;/span&gt;&lt;span style="color: black"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;Shape&lt;/span&gt;&lt;span style="color: black"&gt;&amp;gt; GetMapData(&lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&lt;span style="color: black"&gt; fileName)      &lt;br /&gt;    {       &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: green"&gt;// ShapefileReader is a simple class containing &lt;/span&gt;&lt;/div&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;&lt;span style="color: green"&gt;        // the Shapefile reading and querying methods      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;        &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;ShapefileReader&lt;/span&gt;&lt;span style="color: black"&gt; sr = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;ShapefileReader&lt;/span&gt;&lt;span style="color: black"&gt;();      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: black"&gt; sr.LoadShapefileLayer(Server.MapPath(&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;"~/Maps/"&lt;/span&gt;&lt;span style="color: black"&gt; + fileName));      &lt;br /&gt;    }&lt;/span&gt;&lt;/div&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;&lt;span style="color: black"&gt;&lt;/span&gt;&lt;span style="color: black"&gt;}      &lt;br /&gt;&lt;/span&gt;&lt;/div&gt;  &lt;p&gt;This web method will be callable with extreme simplicity from the client side:&lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;&lt;span style="color: blue"&gt;function&lt;/span&gt;&lt;span style="color: black"&gt; LoadShapefile(fileName)      &lt;br /&gt;{       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: green"&gt;/* The shapefileName global variable holds the filename of the      &lt;br /&gt;     * last loaded Shapefile for future reference (i.e. querying the map) */       &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;    shapefileName = fileName;      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: green"&gt;/* Here we call the GetMapData asmx ScriptService, passing fileName as      &lt;br /&gt;     * a parameter. GetESRIData_success is a callback that will be executed       &lt;br /&gt;     * upon successful completion of the method call, and will be passed the       &lt;br /&gt;     * return data as parameter. onFailed, on the other side, will be executed       &lt;br /&gt;     * in case of failed request */       &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;    MapService.GetMapData(fileName, GetESRIData_success, onFailed);      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: green"&gt;// MessageBox is a function that displays a nice informative box on the map      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;    MessageBox(&lt;/span&gt;&lt;span style="color: blue"&gt;true&lt;/span&gt;&lt;span style="color: black"&gt;, &lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;"Please wait while retrieving Shapefile data..."&lt;/span&gt;&lt;span style="color: black"&gt;);      &lt;br /&gt;}&lt;/span&gt; &lt;/div&gt;  &lt;p&gt;Now that the data is available to the client side, we need to go through all the Shape objects and actually convert them to Virtual Earth shapes. &lt;/p&gt;  &lt;p&gt;In case of successful completion of the method call, the &lt;strong&gt;GetESRIData_success &lt;/strong&gt;callback will invoke the AddLayer() method, passing it the received object; AddLayer() will perform the conversion before actually drawing the shapes on the map.&lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;&lt;span style="color: blue"&gt;function&lt;/span&gt;&lt;span style="color: black"&gt; GetESRIData_success(e)      &lt;br /&gt;{     &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (e!= &lt;/span&gt;&lt;span style="color: blue"&gt;null&lt;/span&gt;&lt;span style="color: black"&gt;)   &lt;br /&gt;        AddLayer(e);       &lt;br /&gt;}       &lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;function&lt;/span&gt;&lt;span style="color: black"&gt; onFailed(e)      &lt;br /&gt;{       &lt;br /&gt;    MessageBox(&lt;/span&gt;&lt;span style="color: blue"&gt;true&lt;/span&gt;&lt;span style="color: black"&gt;, &lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;"Error while connecting to the remote web service. Please try again later."&lt;/span&gt;&lt;span style="color: black"&gt;, 5000);      &lt;br /&gt;}       &lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;function&lt;/span&gt;&lt;span style="color: black"&gt; AddLayer(jsonLayer)      &lt;br /&gt;{       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; polygons = ConvertShapes(jsonLayer);      &lt;br /&gt;     &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;for&lt;/span&gt;&lt;span style="color: black"&gt; (&lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; i = 0; i &amp;lt; polygons.length; i++)      &lt;br /&gt;    {       &lt;br /&gt;        DrawPolygon(polygons[i]&lt;/span&gt;&lt;span style="color: black"&gt;);      &lt;br /&gt;    }       &lt;br /&gt;    MessageBox(&lt;/span&gt;&lt;span style="color: blue"&gt;true&lt;/span&gt;&lt;span style="color: black"&gt;, String.format(&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;"{0} polygons drawn on the map"&lt;/span&gt;&lt;span style="color: black"&gt;, polygons.length), 2000);      &lt;br /&gt;}&lt;/span&gt; &lt;/div&gt;  &lt;p&gt;The conversion from custom list of deserialized .NET Shape objects to array of actual Virtual Earth VEShape objects will be performed in two steps: first of all, the ConvertShapes() method will convert the list of deserialized Shape objects to an array of JavaScript "polygon" objects, each containing an array of VELatLong objects and a colour for the shape:&lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;&lt;span style="color: blue"&gt;function&lt;/span&gt;&lt;span style="color: black"&gt; ConvertShapes(layer)      &lt;br /&gt;{       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; polygons = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; Array();      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;for&lt;/span&gt;&lt;span style="color: black"&gt; (&lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; i = 0; i &amp;lt; layer.length; i++)      &lt;br /&gt;    {       &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; polygon = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; Object();      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; llpoints = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; Array();      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;for&lt;/span&gt;&lt;span style="color: black"&gt; (&lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; j = 0; j &amp;lt; layer[i].Points.length; j++)      &lt;br /&gt;        {         &lt;br /&gt;            llpoints.push(&lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; VELatLong(layer[i].Points[j].Y, layer[i].Points[j].X));      &lt;br /&gt;        }       &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; veCol = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; VEColor(layer[i].Colour.R, layer[i].Colour.G, layer[i].Colour.B, layer[i].Colour.A/255);  &lt;br /&gt;        polygon.Points = llpoints;  &lt;br /&gt;        polygon.Colour = veCol;  &lt;br /&gt;        polygons.push(polygon);       &lt;br /&gt;    }       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: black"&gt; polygons;      &lt;br /&gt;}&lt;/span&gt; &lt;/div&gt;  &lt;p&gt;Finally, for each of the JavaScript polygon objects, a new VEShape object is created and added to the map, care of the DrawPolygon() method.&lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;&lt;span style="color: blue"&gt;function&lt;/span&gt;&lt;span style="color: black"&gt; DrawPolygon(polygon)      &lt;br /&gt;{       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; shape = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; VEShape(VEShapeType.Polygon, polygon.Points);      &lt;br /&gt;    shape.SetFillColor(polygon.Colour);       &lt;br /&gt;    shape.SetLineColor(polygon.Colour);       &lt;br /&gt;    shape.SetLineWidth(1);       &lt;br /&gt;    shape.HideIcon();       &lt;br /&gt;         &lt;br /&gt;    map.AddShape(shape);       &lt;br /&gt;}&lt;/span&gt; &lt;/div&gt;  &lt;p&gt;Finally, this is what we get:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/ShowingESRIShapefileLayersonaVirtualEart_E26E/ScreenShot007_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="484" alt="Great Britain's Administrative Areas overlaid on a Virtual Earth map" src="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/ShowingESRIShapefileLayersonaVirtualEart_E26E/ScreenShot007_thumb.png" width="644" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Pretty neat, isn't it? ;)&lt;/p&gt;  &lt;p&gt;Obviously, the shapes become more detailed as you zoom in:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/ShowingESRIShapefileLayersonaVirtualEart_E26E/ScreenShot008_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="229" alt="Great Britain's Administrative Areas overlaid on a Virtual Earth map" src="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/ShowingESRIShapefileLayersonaVirtualEart_E26E/ScreenShot008_thumb.png" width="304" border="0" /&gt;&lt;/a&gt; &lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/ShowingESRIShapefileLayersonaVirtualEart_E26E/ScreenShot009_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="229" alt="Great Britain's Administrative Areas overlaid on a Virtual Earth map (Zoom)" src="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/ShowingESRIShapefileLayersonaVirtualEart_E26E/ScreenShot009_thumb.png" width="304" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h3&gt;Querying.&lt;/h3&gt;  &lt;p&gt;Now what if we want to access the info associated with each part (i.e. shape) in the Shapefile? &lt;/p&gt;  &lt;p&gt;Luckily, SharpMap comes once again in our help, making this very easy. When provided with a bounding box, the library's &lt;strong&gt;ExecuteIntersectionQuery()&lt;/strong&gt; method returns a DataSet containing the information associated with the shapes that intersect it. All we need to do to get this info to the client is create another ScriptService, and invoke it when the user clicks on the map, providing the Latitude and Longitude of the clicked point.&lt;/p&gt;  &lt;p&gt;This is the method that actually performs the query on the Shapefile:&lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&lt;span style="color: black"&gt; QueryPoint(&lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&lt;span style="color: black"&gt; filePath, &lt;/span&gt;&lt;span style="color: blue"&gt;double&lt;/span&gt;&lt;span style="color: black"&gt; lat, &lt;/span&gt;&lt;span style="color: blue"&gt;double&lt;/span&gt;&lt;span style="color: black"&gt; lon)      &lt;br /&gt;{       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;ShapeFileProvider&lt;/span&gt;&lt;span style="color: black"&gt; sf = &lt;/span&gt;&lt;span style="color: blue"&gt;null&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;try      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;    {      &lt;br /&gt;        sf = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;ShapeFileProvider&lt;/span&gt;&lt;span style="color: black"&gt;(filePath);      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (!sf.IsOpen)      &lt;br /&gt;            sf.Open(&lt;/span&gt;&lt;span style="color: blue"&gt;false&lt;/span&gt;&lt;span style="color: black"&gt;);      &lt;br /&gt;      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: green"&gt;/* This is the SharpMap object that will contain the query results */      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;        FeatureDataSet&lt;/span&gt;&lt;span style="color: black"&gt; ds = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;FeatureDataSet&lt;/span&gt;&lt;span style="color: black"&gt;();      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: green"&gt;/* This is the extents of the map upon which we want to perform the query.  &lt;br /&gt;         * In our case, it will simply be the point where the user clicked. */       &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;        BoundingBox&lt;/span&gt;&lt;span style="color: black"&gt; bbox = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; SharpMap.Geometries.&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;Point&lt;/span&gt;&lt;span style="color: black"&gt;(lon, lat).GetBoundingBox();      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: green"&gt;/* This actually executes the query and puts the results into the FeatureDataSet */      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;        sf.ExecuteIntersectionQuery(bbox, ds);      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;DataTable&lt;/span&gt;&lt;span style="color: black"&gt; table = ds.Tables[0];      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (table.Rows.Count &amp;lt; 1)      &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;null&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: green"&gt;/* Here we format the query results in a simple HTML table to be shown in the      &lt;br /&gt;         * MessageBox on the map for demo purposes */       &lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;        StringBuilder&lt;/span&gt;&lt;span style="color: black"&gt; sb = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;StringBuilder&lt;/span&gt;&lt;span style="color: black"&gt;();      &lt;br /&gt;        sb.AppendLine(&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;"&amp;lt;table&amp;gt;"&lt;/span&gt;&lt;span style="color: black"&gt;);      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;foreach&lt;/span&gt;&lt;span style="color: black"&gt; (&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;DataRow&lt;/span&gt;&lt;span style="color: black"&gt; row &lt;/span&gt;&lt;span style="color: blue"&gt;in&lt;/span&gt;&lt;span style="color: black"&gt; table.Rows)      &lt;br /&gt;        {       &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;foreach&lt;/span&gt;&lt;span style="color: black"&gt; (&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;DataColumn&lt;/span&gt;&lt;span style="color: black"&gt; column &lt;/span&gt;&lt;span style="color: blue"&gt;in&lt;/span&gt;&lt;span style="color: black"&gt; table.Columns)      &lt;br /&gt;            {  &lt;br /&gt;                sb.AppendFormat(&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;"&amp;lt;tr&amp;gt;&amp;lt;td style='background-color:#113;'&amp;gt;{0}&amp;lt;/td&amp;gt;" &lt;span style="color: black"&gt;+&lt;/span&gt; &lt;/span&gt;&lt;/div&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;&lt;span style="color: rgb(163,21,21)"&gt;                            "&amp;lt;td&amp;gt;{1}&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;"&lt;/span&gt;&lt;span style="color: black"&gt;, column.ColumnName, row[column]);      &lt;br /&gt;            }       &lt;br /&gt;            sb.AppendFormat(&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;"&amp;lt;tr style='height:10px;'&amp;gt;&amp;lt;/tr&amp;gt;"&lt;/span&gt;&lt;span style="color: black"&gt;);      &lt;br /&gt;        }       &lt;br /&gt;        sb.AppendLine(&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;"&amp;lt;/table&amp;gt;"&lt;/span&gt;&lt;span style="color: black"&gt;);      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: black"&gt; sb.ToString();      &lt;br /&gt;    }       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;finally      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;    {      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (sf != &lt;/span&gt;&lt;span style="color: blue"&gt;null&lt;/span&gt;&lt;span style="color: black"&gt;)      &lt;br /&gt;            sf.Close();       &lt;br /&gt;    } &lt;/span&gt;&lt;/div&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;&lt;span style="color: black"&gt;}      &lt;br /&gt;&lt;/span&gt;&lt;/div&gt;  &lt;p&gt;And here's the very simple Web Method that exposes the method's functionality to client script:&lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;[&lt;span style="color: rgb(43,145,175)"&gt;WebMethod&lt;/span&gt;&lt;span style="color: black"&gt;]      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&lt;span style="color: black"&gt; GetPlaceInfo(&lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&lt;span style="color: black"&gt; fileName, &lt;/span&gt;&lt;span style="color: blue"&gt;double&lt;/span&gt;&lt;span style="color: black"&gt; latitude, &lt;/span&gt;&lt;span style="color: blue"&gt;double&lt;/span&gt;&lt;span style="color: black"&gt; longitude)      &lt;br /&gt;{       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;ShapefileReader&lt;/span&gt;&lt;span style="color: black"&gt; sr = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;ShapefileReader&lt;/span&gt;&lt;span style="color: black"&gt;();      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: black"&gt; sr.QueryPoint(Server.MapPath(&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;"~/Maps/"&lt;/span&gt;&lt;span style="color: black"&gt; + fileName), latitude, longitude);      &lt;br /&gt;}&lt;/span&gt; &lt;/div&gt;  &lt;p&gt;Finally, this is what happens on the client when the user clicks on a point on the map. Notice how we leverage ASP.NET AJAX's page lifecycle "pageLoad" event to initially setup our map and register the onclick event handler. The rest of this snippet should be self explanatory. In case it is not, you can have a look at &lt;a href="http://go.microsoft.com/fwlink/?LinkId=99049" target="_blank"&gt;Virtual Earth SDK&lt;/a&gt; to learn more about map events and methods.&lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;&lt;span style="color: blue"&gt;function&lt;/span&gt;&lt;span style="color: black"&gt; pageLoad()      &lt;br /&gt;{       &lt;br /&gt;    map = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; VEMap(&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;'myMap'&lt;/span&gt;&lt;span style="color: black"&gt;);      &lt;br /&gt;    map.LoadMap(&lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; VELatLong(50.5, -2.1), 6);      &lt;br /&gt;    map.AttachEvent(&lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;"onclick"&lt;/span&gt;&lt;span style="color: black"&gt;, map_onclick);      &lt;br /&gt;}&lt;/span&gt; &lt;/div&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt; &lt;/div&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;&lt;span style="color: blue"&gt;function&lt;/span&gt;&lt;span style="color: black"&gt; map_onclick(e)      &lt;br /&gt;{       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (shapefileName != &lt;/span&gt;&lt;span style="color: blue"&gt;null&lt;/span&gt;&lt;span style="color: black"&gt;)      &lt;br /&gt;    {  &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; ll = map.PixelToLatLong(&lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; VEPixel(e.mapX, e.mapY));      &lt;br /&gt;        MapService.GetPlaceInfo(shapefileName, ll.Latitude, ll.Longitude, &lt;/span&gt;&lt;/div&gt;  &lt;div style="font-size: 10pt; font-family: consolas,courier new,monospace; background-color: rgb(238,238,238)"&gt;&lt;span style="color: black"&gt;                                QueryData_success, onFailed);      &lt;br /&gt;    }       &lt;br /&gt;}       &lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;function&lt;/span&gt;&lt;span style="color: black"&gt; QueryData_success(e)      &lt;br /&gt;{       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (e != &lt;/span&gt;&lt;span style="color: blue"&gt;null&lt;/span&gt;&lt;span style="color: black"&gt;)      &lt;br /&gt;        MessageBox(&lt;/span&gt;&lt;span style="color: blue"&gt;true&lt;/span&gt;&lt;span style="color: black"&gt;, e, 0, &lt;/span&gt;&lt;span style="color: blue"&gt;true&lt;/span&gt;&lt;span style="color: black"&gt;);      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;else      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;        MessageBox(&lt;/span&gt;&lt;span style="color: blue"&gt;true&lt;/span&gt;&lt;span style="color: black"&gt;, &lt;/span&gt;&lt;span style="color: rgb(163,21,21)"&gt;"No data to display"&lt;/span&gt;&lt;span style="color: black"&gt;, 2000);      &lt;br /&gt;}&lt;/span&gt; &lt;/div&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/ShowingESRIShapefileLayersonaVirtualEart_E26E/ScreenShot010_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="484" alt="Querying the map" src="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/ShowingESRIShapefileLayersonaVirtualEart_E26E/ScreenShot010_thumb.png" width="642" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/ShowingESRIShapefileLayersonaVirtualEart_E26E/ScreenShot011_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="184" alt="Querying the map" src="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/ShowingESRIShapefileLayersonaVirtualEart_E26E/ScreenShot011_thumb.png" width="244" border="0" /&gt;&lt;/a&gt; &lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/ShowingESRIShapefileLayersonaVirtualEart_E26E/ScreenShot012_2.png"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="184" alt="Querying the map" src="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/ShowingESRIShapefileLayersonaVirtualEart_E26E/ScreenShot012_thumb.png" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;That's all folks! I hope you enjoyed this article and found it useful! As always, I urge you to leave a comment if you need any more info or clarification. Finally, if you liked this article and you want to help me spread the word, you might consider clicking on the "kick it" button below! ;)&lt;/p&gt;  &lt;h5&gt;As usual, you can see a &lt;a href="http://www.korisweb.net/JuanDoNeblo/Shapefiles/Default.aspx"&gt;live demo&lt;/a&gt; of the application &lt;a href="http://www.korisweb.net/JuanDoNeblo/Shapefiles/Default.aspx"&gt;here&lt;/a&gt;, and you can &lt;a href="http://www.korisweb.net/JuanDoNeblo/Shapefiles/Shapefiles.zip"&gt;download the source code&lt;/a&gt; of this project &lt;a href="http://www.korisweb.net/JuanDoNeblo/Shapefiles/Shapefiles.zip"&gt;here&lt;/a&gt;.&lt;/h5&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;  &lt;h5 style="color: rgb(180,200,53)"&gt;Marco&lt;/h5&gt;  &lt;p style="color: rgb(180,200,53)"&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:d9d489d2-86b2-46b1-94d7-952c0d7a3e1d" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tag: &lt;a href="http://technorati.com/tags/Virtual%20Earth" rel="tag"&gt;Virtual Earth&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Shapefile" rel="tag"&gt;Shapefile&lt;/a&gt;,&lt;a href="http://technorati.com/tags/ESRI" rel="tag"&gt;ESRI&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Mashup" rel="tag"&gt;Mashup&lt;/a&gt;,&lt;a href="http://technorati.com/tags/GIS" rel="tag"&gt;GIS&lt;/a&gt;,&lt;a href="http://technorati.com/tags/ASP.NET" rel="tag"&gt;ASP.NET&lt;/a&gt;,&lt;a href="http://technorati.com/tags/AJAX" rel="tag"&gt;AJAX&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Javascript" rel="tag"&gt;Javascript&lt;/a&gt;,&lt;a href="http://technorati.com/tags/C#" rel="tag"&gt;C#&lt;/a&gt;&lt;/div&gt;  &lt;p&gt;&lt;/p&gt; &lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fgeekswithblogs.net%2fJuanDoNeblo%2farchive%2f2008%2f04%2f13%2fshowing-esri-shapefile-layers-on-a-virtual-earth-map.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fgeekswithblogs.net%2fJuanDoNeblo%2farchive%2f2008%2f04%2f13%2fshowing-esri-shapefile-layers-on-a-virtual-earth-map.aspx" border="0" /&gt;&lt;/a&gt;&lt;a href="http://digg.com/submit?phase=2&amp;amp;url=http%3A//geekswithblogs.net/JuanDoNeblo/archive/2008/04/13/showing-esri-shapefile-layers-on-a-virtual-earth-map.aspx&amp;amp;topic=programming&amp;amp;"&gt;&lt;img height="16" alt="Digg!" src="http://digg.com/img/badges/16x16-digg-guy.gif" width="16" /&gt;&lt;/a&gt;&lt;a href="http://www.dzone.com/links/showing_esri_shapefile_layers_on_a_virtual_earth.html"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="16" alt="dzone" src="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/Asi.NETAJAXshowingcurrentweatherconditio_C9A1/dzone_3.png" width="16" border="0" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121212"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=121212" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/JuanDoNeblo/aggbug/121212.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Marco Anastasi &amp; Serena Caruso</dc:creator>
            <guid>http://geekswithblogs.net/JuanDoNeblo/archive/2008/04/13/showing-esri-shapefile-layers-on-a-virtual-earth-map.aspx</guid>
            <pubDate>Sun, 13 Apr 2008 17:03:58 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/JuanDoNeblo/comments/121212.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/JuanDoNeblo/archive/2008/04/13/showing-esri-shapefile-layers-on-a-virtual-earth-map.aspx#feedback</comments>
            <slash:comments>28</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/JuanDoNeblo/comments/commentRss/121212.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/JuanDoNeblo/services/trackbacks/121212.aspx</trackback:ping>
        </item>
        <item>
            <title>Getting started with Virtual Earth Mashups: showing current weather conditions on a map</title>
            <link>http://geekswithblogs.net/JuanDoNeblo/archive/2007/11/13/Getting-started-with-Virtual-Earth-Mashups-showing-current-weather-conditions.aspx</link>
            <description>&lt;p&gt;In this article we'll see how easy it is to use &lt;a href="http://dev.live.com/virtualearth/sdk/" target="_blank"&gt;Virtual Earth SDK&lt;/a&gt; to produce a simple mashup, using web services that provide information in JSON format.&lt;/p&gt;  &lt;h5&gt;&lt;a href="http://www.prestifin.biz/JuanDoNeblo/VEMashup/Default.aspx" target="_blank"&gt;Live Demo&lt;/a&gt; - &lt;a href="http://www.prestifin.biz/JuanDoNeblo/VEMashup/VEMashup.zip" target="_blank"&gt;Source Code&lt;/a&gt;&lt;/h5&gt;  &lt;p&gt;If you are not familiar with JSON or how to integrate JSON services in ASP.NET AJAX applications, you can take a look at my 3-part series of articles on JSON and ASP.NET AJAX &lt;a href="http://geekswithblogs.net/JuanDoNeblo/articles/How-to-integrate-JSON-web-services-in-an-ASP.NET-AJAX.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;First of all, we need to create a simple &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;.aspx&lt;/span&gt; page, and add a &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;ScriptManager&lt;/span&gt; to it. Then, we're going to reference the Virtual Earth API in the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;ScriptManager&lt;/span&gt;'s &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;Script&lt;/span&gt; section:&lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: #eee"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ScriptManager&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;ID&lt;/span&gt;&lt;span style="color: blue"&gt;="ScriptManager1"&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;="server"&amp;gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;  &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Scripts&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ScriptReference&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6"&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;  &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Scripts&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ScriptManager&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/div&gt;  &lt;p&gt;We also need a &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;Div &lt;/span&gt;in the page, to act as a placeholder for the Virtual Earth map, and a button to trigger the web service call.&lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: #eee"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;div&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;='myMap'&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;style&lt;/span&gt;&lt;span style="color: blue"&gt;="&lt;/span&gt;&lt;span style="color: red"&gt;position&lt;/span&gt;&lt;span style="color: black"&gt;:&lt;/span&gt;&lt;span style="color: blue"&gt;relative&lt;/span&gt;&lt;span style="color: black"&gt;;&lt;/span&gt;&lt;span style="color: red"&gt;width&lt;/span&gt;&lt;span style="color: black"&gt;:&lt;/span&gt;&lt;span style="color: blue"&gt;800px&lt;/span&gt;&lt;span style="color: black"&gt;;&lt;/span&gt;&lt;span style="color: red"&gt;height&lt;/span&gt;&lt;span style="color: black"&gt;:&lt;/span&gt;&lt;span style="color: blue"&gt;600px&lt;/span&gt;&lt;span style="color: black"&gt;;&lt;/span&gt;&lt;span style="color: blue"&gt;"&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;input&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;="button"&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;onclick&lt;/span&gt;&lt;span style="color: blue"&gt;="getWeather_onclick()"&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;="Get Weather Info..."&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt; &lt;/div&gt;  &lt;p&gt;We've almost succeeded in showing a simple Virtual Earth map in our ASP.NET page. All that's left to do, is call the JavaScript method of the VE API that will actually initialise the map and populate our placeholder div.&lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: #eee"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;script&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;="text/javascript"&amp;gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;     &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; map = &lt;/span&gt;&lt;span style="color: blue"&gt;null&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;function&lt;/span&gt;&lt;span style="color: black"&gt; pageLoad()      &lt;br /&gt;{       &lt;br /&gt;    map = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; VEMap(&lt;/span&gt;&lt;span style="color: #a31515"&gt;'myMap'&lt;/span&gt;&lt;span style="color: black"&gt;);      &lt;br /&gt;    map.LoadMap(&lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; VELatLong(51.5, -0.1), 10&lt;/span&gt;&lt;span style="color: black"&gt;);      &lt;br /&gt;}       &lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;script&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/div&gt;  &lt;p&gt;You may notice that we put the initialisation logic in the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;pageLoad()&lt;/span&gt; method of our page in order to leverage the ASP.NET AJAX client side lifecycle. Another very common way to initialise the map, is to define an event handler for the body &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;onload&lt;/span&gt; event. &lt;/p&gt;  &lt;p&gt;If you try to run the project now, you'll see something like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/Asi.NETAJAXshowingcurrentweatherconditio_C9A1/ScreenShot002_2.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="518" alt="ScreenShot002" src="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/Asi.NETAJAXshowingcurrentweatherconditio_C9A1/ScreenShot002_thumb.jpg" width="604" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;If you try to run the project now, you'll see that the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;Div &lt;/span&gt;we created is already populated with a road map of Greater London. If you take a moment to play around with it, you'll see that all the standard functionalities of Virtual Earth, including panning, zooming, changing the map style etc. already work out of the box. We could even include the standard "What - When" search with a line of code if we wanted! (see &lt;a href="http://msdn2.microsoft.com/en-us/library/bb429619.aspx" target="_blank"&gt;Virtual Earth documentation&lt;/a&gt; for more info). It's a great deal of functionalities for such a little effort on our part!&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;NOTE: As always, inline script and global variables are used for clarity, but in a more complex project, it would be much tidier to use separate .js files for JavaScript code, and enclose methods and variables in client side classes, in order to attain a more OO application model. Using the ASP.NET AJAX Library helps a great deal in this regard.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Now, we need to integrate an external web service that provides us with up-to-date weather information on the area we select on the map. After a short search on the web, you may find that &lt;a href="http://www.geonames.org/export/JSON-webservices.html#weatherJSON" target="_blank"&gt;Geonames&lt;/a&gt;'s free weather services are extremely powerful and useful, and, as a bonus, they come in JSON format, and that will make our job easier ;)&lt;/p&gt;  &lt;p&gt;As you may know, for security reasons, cross-domain requests from client script are forbidden, i.e. JavaScript code can only successfully make an HTTP web request to the domain in which the page originated. To circumvent this restriction, we will have to create a .NET proxy service in our server side code, and call it from our JavaScript. I've written a relatively extensive &lt;a href="http://geekswithblogs.net/JuanDoNeblo/articles/How-to-integrate-JSON-web-services-in-an-ASP.NET-AJAX.aspx" target="_blank"&gt;tutorial&lt;/a&gt; on this topic, so if you've never created a proxy service, or used JSON web services with ASP.NET AJAX, you may find useful to &lt;a href="http://geekswithblogs.net/JuanDoNeblo/articles/How-to-integrate-JSON-web-services-in-an-ASP.NET-AJAX.aspx" target="_blank"&gt;have a look at it&lt;/a&gt; before going on. On a side note, keep in mind that, although I won't talk about them in this article, different solutions exist to call a remote JSON service from client side code. Anyway, in my opinion, the solution presented here is the tidiest and most flexible one.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.geonames.org/export/JSON-webservices.html" target="_blank"&gt;Geonames&lt;/a&gt; provides an entire set of web methods to retrieve weather info provided by observation stations all around the world using different criteria. What we want to do is retrieve the available weather data provided by meteorological stations near a specific point on the map. The most straightforward way to do that is by calling the &lt;em&gt;findNearByWeatherJSON&lt;/em&gt; web service, located at &lt;a title="http://ws.geonames.org/findNearByWeatherJSON" href="http://ws.geonames.org/findNearByWeatherJSON"&gt;http://ws.geonames.org/findNearByWeatherJSON&lt;/a&gt;. The service takes at least two parameters, the longitude and latitude of a point, and returns the observation taken at the station closest to the supplied point. When issuing the request, we can also specify the maximum number of results we want returned. By default, only data from the closest station is retrieved, but it can be useful to get data from multiple stations around the selected point.&lt;/p&gt;  &lt;p&gt;Let's see the code for the proxy web service:&lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: #eee"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt;&lt;span style="color: black"&gt; System.Web.Services;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt;&lt;span style="color: black"&gt; System.Web.Script.Services;      &lt;br /&gt;      &lt;br /&gt;[&lt;/span&gt;&lt;span style="color: #2b91af"&gt;WebService&lt;/span&gt;&lt;span style="color: black"&gt;]      &lt;br /&gt;[&lt;/span&gt;&lt;span style="color: #2b91af"&gt;WebServiceBinding&lt;/span&gt;&lt;span style="color: black"&gt;(ConformsTo = &lt;/span&gt;&lt;span style="color: #2b91af"&gt;WsiProfiles&lt;/span&gt;&lt;span style="color: black"&gt;.BasicProfile1_1)]      &lt;br /&gt;[&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ScriptService&lt;/span&gt;&lt;span style="color: black"&gt;]      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: #2b91af"&gt;WeatherService&lt;/span&gt;&lt;span style="color: black"&gt; : &lt;/span&gt;&lt;span style="color: #2b91af"&gt;WebService      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;{      &lt;br /&gt;    [&lt;/span&gt;&lt;span style="color: #2b91af"&gt;WebMethod&lt;/span&gt;&lt;span style="color: black"&gt;]      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&lt;span style="color: black"&gt; GetWeatherByLocation(&lt;/span&gt;&lt;span style="color: blue"&gt;double&lt;/span&gt;&lt;span style="color: black"&gt; lat, &lt;/span&gt;&lt;span style="color: blue"&gt;double&lt;/span&gt;&lt;span style="color: black"&gt; lng)      &lt;br /&gt;    {       &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: #2b91af"&gt;GeonamesWeather&lt;/span&gt;&lt;span style="color: black"&gt;.GetWeatherByLocation(lat, lng);      &lt;br /&gt;    }       &lt;br /&gt;}       &lt;br /&gt;&lt;/span&gt;&lt;/div&gt;  &lt;p&gt;and for the GeonamesWeather class:&lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: #eee"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt;&lt;span style="color: black"&gt; System;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt;&lt;span style="color: black"&gt; System.Net;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt;&lt;span style="color: black"&gt; System.Globalization;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt;&lt;span style="color: black"&gt; System.IO;      &lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: #2b91af"&gt;GeonamesWeather      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;{      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;private&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;readonly&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&lt;span style="color: black"&gt; FindNearbyWeatherUrl =      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: #a31515"&gt;"http://ws.geonames.org/findNearByWeatherJSON?lat={0}&amp;amp;lng={1}&amp;amp;maxRows=10"&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&lt;span style="color: black"&gt; GetWeatherByLocation(&lt;/span&gt;&lt;span style="color: blue"&gt;double&lt;/span&gt;&lt;span style="color: black"&gt; lat, &lt;/span&gt;&lt;span style="color: blue"&gt;double&lt;/span&gt;&lt;span style="color: black"&gt; lng)      &lt;br /&gt;    {       &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&lt;span style="color: black"&gt; formattedUri = &lt;/span&gt;&lt;span style="color: #2b91af"&gt;String&lt;/span&gt;&lt;span style="color: black"&gt;.Format(&lt;/span&gt;&lt;span style="color: #2b91af"&gt;CultureInfo&lt;/span&gt;&lt;span style="color: black"&gt;.InvariantCulture,&lt;/span&gt;&lt;/div&gt;  &lt;div style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: #eee"&gt;&lt;span style="color: black"&gt;                                            FindNearbyWeatherUrl, lat, lng);      &lt;br /&gt;      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpWebRequest&lt;/span&gt;&lt;span style="color: black"&gt; webRequest = GetWebRequest(formattedUri);      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpWebResponse&lt;/span&gt;&lt;span style="color: black"&gt; response = (&lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpWebResponse&lt;/span&gt;&lt;span style="color: black"&gt;)webRequest.GetResponse();      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&lt;span style="color: black"&gt; jsonResponse = &lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&lt;span style="color: black"&gt;.Empty;      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt;&lt;span style="color: black"&gt; (&lt;/span&gt;&lt;span style="color: #2b91af"&gt;StreamReader&lt;/span&gt;&lt;span style="color: black"&gt; sr = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: #2b91af"&gt;StreamReader&lt;/span&gt;&lt;span style="color: black"&gt;(response.GetResponseStream()))      &lt;br /&gt;        {       &lt;br /&gt;            jsonResponse = sr.ReadToEnd();       &lt;br /&gt;        }       &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: black"&gt; jsonResponse;      &lt;br /&gt;    }       &lt;br /&gt;      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;private&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpWebRequest&lt;/span&gt;&lt;span style="color: black"&gt; GetWebRequest(&lt;/span&gt;&lt;span style="color: blue"&gt;string&lt;/span&gt;&lt;span style="color: black"&gt; formattedUri)      &lt;br /&gt;    {       &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: green"&gt;// Construct the request's URL.   &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;        &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Uri&lt;/span&gt;&lt;span style="color: black"&gt; serviceUri = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Uri&lt;/span&gt;&lt;span style="color: black"&gt;(formattedUri, &lt;/span&gt;&lt;span style="color: #2b91af"&gt;UriKind&lt;/span&gt;&lt;span style="color: black"&gt;.Absolute);      &lt;br /&gt;      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: green"&gt;// Return a HttpWebRequest object.   &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: black"&gt; (&lt;/span&gt;&lt;span style="color: #2b91af"&gt;HttpWebRequest&lt;/span&gt;&lt;span style="color: black"&gt;)System.Net.&lt;/span&gt;&lt;span style="color: #2b91af"&gt;WebRequest&lt;/span&gt;&lt;span style="color: black"&gt;.Create(serviceUri);      &lt;br /&gt;    }       &lt;br /&gt;}&lt;/span&gt; &lt;/div&gt;  &lt;p&gt;As you can see, by specifying &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;maxRows=10&lt;/span&gt; we're retrieving the observations from at most 10 weather stations near the selected location. If you want to know in greater detail what we are doing here, please refer to &lt;a href="http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/24/json_in_aspnetajax_part2.aspx" target="_blank"&gt;this&lt;/a&gt; post where I concentrate more on how to create a proxy web service. What we absolutely need to point out is that by marking the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;WeatherService &lt;/span&gt;class with the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;[ScriptService] &lt;/span&gt;attribute, we are instructing the compiler to create a proxy JavaScript class to allow the method to be called directly from client code.&lt;/p&gt;  &lt;p&gt;For reference, here's an example of a typical response received from the web service call:&lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: #eee"&gt;{"weatherObservations":    &lt;br /&gt;[{"clouds":"scattered clouds",     &lt;br /&gt;  "weatherCondition":"n/a",     &lt;br /&gt;  "observation":"EGUY 081550Z 27014KT 9999 SCT026 BKN045 10/07 Q1011 BLU",     &lt;br /&gt;  "windDirection":270,     &lt;br /&gt;  "ICAO":"EGUY",     &lt;br /&gt;  "elevation":41,     &lt;br /&gt;  "countryCode":"GB",     &lt;br /&gt;  "lng":-0.116666666666667,     &lt;br /&gt;  "temperature":"10",     &lt;br /&gt;  "dewPoint":"7",     &lt;br /&gt;  "windSpeed":"14",     &lt;br /&gt;  "humidity":81,     &lt;br /&gt;  "stationName":     &lt;br /&gt;  "Wyton Royal Air Force Base",     &lt;br /&gt;  "datetime":"2007-11-08 15:50:00",     &lt;br /&gt;  "lat":52.35,     &lt;br /&gt;  "hectoPascAltimeter":1011},     &lt;br /&gt;{"clouds":"few clouds",     &lt;br /&gt;  "weatherCondition":"n/a",     &lt;br /&gt;  "observation":"EGXT 081850Z 30018G28KT 9999 FEW038 08/01 Q1013 BLU",     &lt;br /&gt;  "windDirection":300,     &lt;br /&gt;  "ICAO":"EGXT",     &lt;br /&gt;  "elevation":84,     &lt;br /&gt;  "countryCode":"GB",     &lt;br /&gt;  "lng":-0.466666666666667,     &lt;br /&gt;  "temperature":"8",     &lt;br /&gt;  "dewPoint":"1",     &lt;br /&gt;  "windSpeed":"18",     &lt;br /&gt;  "humidity":61,     &lt;br /&gt;  "stationName":"Wittering",     &lt;br /&gt;  "datetime":"2007-11-08 18:50:00",     &lt;br /&gt;  "lat":52.6166666666667,     &lt;br /&gt;  "hectoPascAltimeter":1013},     &lt;br /&gt;{...},     &lt;br /&gt;{...},     &lt;br /&gt;{...}]} &lt;/div&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;NOTE: Carriage returns and indentation have been inserted only to improve readability, but the response stream won't contain any.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;So, let's see what we've got here: the received JSON response, once deserialized to a JavaScript object, will have a single property, &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;weatherObservations&lt;/span&gt;, which will contain an array of observations, each in turn containing several properties that describe the current weather condition.&lt;/p&gt;  &lt;p&gt;Now, one thing we need to make our web method callable from client code, is to add a reference to it in the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;Services&lt;/span&gt; section of the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;ScriptManager&lt;/span&gt;. So here's how our &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;ScriptManager&lt;/span&gt; will look like, assuming we named the Web Service &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;&lt;em&gt;WeatherService.asmx&lt;/em&gt;&lt;/span&gt; and we put it in the site root:&lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: #eee"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ScriptManager&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;ID&lt;/span&gt;&lt;span style="color: blue"&gt;="ScriptManager1"&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;="server"&amp;gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;  &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Scripts&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ScriptReference&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6"&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;  &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Scripts&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;  &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Services&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ServiceReference&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;="~/WeatherService.asmx"&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;/&amp;gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;  &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Services&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ScriptManager&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt; &lt;/div&gt;  &lt;p&gt;Now we're ready to call the web service, and we'll do this from the button's &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;onclick&lt;/span&gt; event handler:&lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: #eee"&gt;&lt;span style="color: blue"&gt;function&lt;/span&gt;&lt;span style="color: black"&gt; getWeather_onclick()      &lt;br /&gt;{       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; centre = map.GetCenter();      &lt;br /&gt;    WeatherService.GetWeatherByLocation(centre.Latitude, centre.Longitude, &lt;/span&gt;&lt;/div&gt;  &lt;div style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: #eee"&gt;&lt;span style="color: black"&gt;                                        GetWeather_success, onFailed);      &lt;br /&gt;    MessageBox(&lt;/span&gt;&lt;span style="color: blue"&gt;true&lt;/span&gt;&lt;span style="color: black"&gt;, &lt;/span&gt;&lt;span style="color: #a31515"&gt;"Please wait while retrieving weather data..."&lt;/span&gt;&lt;span style="color: black"&gt;);      &lt;br /&gt;}&lt;/span&gt; &lt;/div&gt;  &lt;p&gt;When the button is clicked, the geographical coordinates corresponding to the location currently displayed at the centre of the map are retrieved, using the Virtual Earth map's &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;GetCenter()&lt;/span&gt; method. Then the proxy .&lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;asmx&lt;/span&gt; web service is called in an RPC fashion, passing it the location's latitude and longitude. As the method execution is asynchronous, we need to provide a succeeded callback function, that will be invoked when the request finishes successfully, and will be passed the return value from the Web Service call. We also provide the method with a reference to a callback to be executed in case something goes wrong. Finally, as the web service call can take a while to complete, the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;MessageBox() &lt;/span&gt;function is used to show some visual feedback to the user in order to keep him/her up to date with what's happening. With some appropriate CSS, we can make the MessageBox blend in nicely with the Virtual Earth 6 interface, like this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/Asi.NETAJAXshowingcurrentweatherconditio_C9A1/ScreenShot005_2.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="228" alt="ScreenShot005" src="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/Asi.NETAJAXshowingcurrentweatherconditio_C9A1/ScreenShot005_thumb.jpg" width="441" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Let's see how the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;MessageBox()&lt;/span&gt; function is implemented.&lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: #eee"&gt;&lt;span style="color: blue"&gt;function&lt;/span&gt;&lt;span style="color: black"&gt; MessageBox(show, message, timeout)      &lt;br /&gt;{       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; balloon = $get(&lt;/span&gt;&lt;span style="color: #a31515"&gt;'messageBalloon'&lt;/span&gt;&lt;span style="color: black"&gt;);      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (!show)      &lt;br /&gt;        balloon.style.display = &lt;/span&gt;&lt;span style="color: #a31515"&gt;'none'&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;else      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;    {      &lt;br /&gt;        balloon.style.display = &lt;/span&gt;&lt;span style="color: #a31515"&gt;'block'&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;        balloon.innerHTML = message;       &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (timeout)      &lt;br /&gt;            setTimeout(&lt;/span&gt;&lt;span style="color: #a31515"&gt;'MessageBox(false)'&lt;/span&gt;&lt;span style="color: black"&gt;, timeout);      &lt;br /&gt;    }       &lt;br /&gt;}&lt;/span&gt; &lt;/div&gt;  &lt;p&gt;Note that in order for the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;MessageBox()&lt;/span&gt; function to work, we need to add a &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;Div&lt;/span&gt; named m&lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;essageBalloon&lt;/span&gt; to the page markup. As you can see, we pass the function three parameters: &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;show&lt;/span&gt; determines whether the message is to be shown or hidden, &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;message&lt;/span&gt; contains the actual message to be shown, and &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;timeout&lt;/span&gt;, if present, instructs the function to show the message only for the specified period in milliseconds. All parameters are optional: in case no parameter is passed, the currently shown message, if any, is hidden. &lt;/p&gt;  &lt;p&gt;Finally, let's see how the two callback functions are implemented: &lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: #eee"&gt;&lt;span style="color: blue"&gt;function&lt;/span&gt;&lt;span style="color: black"&gt; onFailed(e)      &lt;br /&gt;{       &lt;br /&gt;    MessageBox(&lt;/span&gt;&lt;span style="color: blue"&gt;true&lt;/span&gt;&lt;span style="color: black"&gt;, &lt;/span&gt;&lt;span style="color: #a31515"&gt;"Error while connecting to the remote web service. Please try again later."&lt;/span&gt;&lt;span style="color: black"&gt;, 5000);      &lt;br /&gt;}       &lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;function&lt;/span&gt;&lt;span style="color: black"&gt; GetWeather_success(e)      &lt;br /&gt;{       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; weatherData = Sys.Serialization.JavaScriptSerializer.deserialize(e);      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; stationsFound = 0;      &lt;br /&gt;     &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (weatherData.weatherObservations &amp;amp;&amp;amp; weatherData.weatherObservations.length &amp;gt; 0)      &lt;br /&gt;    {       &lt;br /&gt;        Array.forEach(weatherData.weatherObservations, AddWeatherPushpin);       &lt;br /&gt;        stationsFound = weatherData.weatherObservations.length;       &lt;br /&gt;    }       &lt;br /&gt;     &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (stationsFound &amp;gt; 0)      &lt;br /&gt;    {       &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; message = String.format(&lt;/span&gt;&lt;span style="color: #a31515"&gt;"Data was retrieved for {0} weather stations."&lt;/span&gt;&lt;span style="color: black"&gt;,&lt;/span&gt;&lt;/div&gt;  &lt;div style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: #eee"&gt;&lt;span style="color: black"&gt;                                    stationsFound);      &lt;br /&gt;        MessageBox(&lt;/span&gt;&lt;span style="color: blue"&gt;true&lt;/span&gt;&lt;span style="color: black"&gt;, message, 2000);     &lt;br /&gt;    }       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;else      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;    {      &lt;br /&gt;        MessageBox(&lt;/span&gt;&lt;span style="color: blue"&gt;true&lt;/span&gt;&lt;span style="color: black"&gt;, &lt;/span&gt;&lt;span style="color: #a31515"&gt;"No weather data was found. Please try again."&lt;/span&gt;&lt;span style="color: black"&gt;, 5000);      &lt;br /&gt;    }       &lt;br /&gt;}&lt;/span&gt; &lt;/div&gt;  &lt;p&gt;The &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;&lt;strong&gt;onFailed()&lt;/strong&gt;&lt;/span&gt; function is really self-explanatory: it simply pops up a message to notify the user that something went wrong in the web service call. &lt;/p&gt;  &lt;p&gt;On the other hand, the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;&lt;strong&gt;getWeather_success()&lt;/strong&gt;&lt;/span&gt; callback gets a bit more complicated, so let's analyse it in depth. First of all, the returned JSON string is deserialized to a JavaScript object using the AJAX Client Library's &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;JavaScriptSerializer&lt;/span&gt; class, and the object is then assigned to the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;weatherData&lt;/span&gt; variable. To learn more about this process, you can refer to &lt;a href="http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/31/json_in_aspnetajax_part3.aspx" target="_blank"&gt;this post&lt;/a&gt; in my already mentioned series on JSON, or have a look at the &lt;a href="http://asp.net/AJAX/Documentation/Live/ClientReference/Sys.Serialization/JavascriptSerializerClass/default.aspx" target="_blank"&gt;msdn&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;weatherData&lt;/span&gt; object will contain a &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;weatherObservations&lt;/span&gt; property only if one or more observations could be retrieved for the specified location. When everything goes as expected, the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;weatherObservations&lt;/span&gt; property contains an array of observations, one for each weather station. So what we need to do in our function is check for the existence of the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;weatherObservations&lt;/span&gt; property, and if we find it, call the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;AddWeatherPushpin()&lt;/span&gt; function, passing it each of the observations found in the array. The &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;AddWeatherPushpin()&lt;/span&gt; function will then prepare and add a specific icon to the map for each of the observations.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Notice that, to improve clarity, rather than looping through the returned array in a &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace"&gt;for&lt;/span&gt; cycle, I preferred to use the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace"&gt;Array.forEach()&lt;/span&gt; method of the ASP.NET AJAX Client Library, which does that under the hood and processes each item of the array with the function provided as the second argument.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Finally, we notify the user with the query result by popping up a message.&lt;/p&gt;  &lt;p&gt;In the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;AddWeatherPushpin()&lt;/span&gt; function, we analyse the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;&lt;strong&gt;clouds&lt;/strong&gt;&lt;/span&gt; property of the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;weatherData&lt;/span&gt; object to determine what is the current cloudiness level above each station. Then, we choose an appropriate icon to be shown on the map based on the cloudiness index. The possible cloudiness levels returned from the web service can be found &lt;a href="http://forum.geonames.org/gforum/posts/list/28.page" target="_blank"&gt;here&lt;/a&gt;. The icon names are chosen following the naming convention you can find &lt;a href="http://www.desktopsidebar.com/forums/index.php?showtopic=3693" target="_blank"&gt;here&lt;/a&gt;, which to my knowledge happens to be the most followed by the creators of weather icon sets.&lt;/p&gt;  &lt;p&gt;This is how the icons will appear on the map:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/Asi.NETAJAXshowingcurrentweatherconditio_C9A1/ScreenShot003_4.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="527" alt="ScreenShot003" src="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/Asi.NETAJAXshowingcurrentweatherconditio_C9A1/ScreenShot003_thumb_1.jpg" width="604" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We also need to prepare the content for the InfoBoxes that will pop up when moving the mouse above the icons and show the retrieved weather information details. This is how they will look like:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/Asi.NETAJAXshowingcurrentweatherconditio_C9A1/ScreenShot007_2.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="404" alt="ScreenShot007" src="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/Asi.NETAJAXshowingcurrentweatherconditio_C9A1/ScreenShot007_thumb.jpg" width="604" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Finally, let's see the implementation of this function:&lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: #eee"&gt;&lt;span style="color: blue"&gt;function&lt;/span&gt;&lt;span style="color: black"&gt; AddWeatherPushpin(observation)      &lt;br /&gt;{       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; icon;      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: green"&gt;// The observation time is parsed in order to determine      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;    &lt;/span&gt;&lt;span style="color: green"&gt;// whether the observation was taken during the day or      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;    &lt;/span&gt;&lt;span style="color: green"&gt;// the night and choose an appropriate icon.&lt;/span&gt;&lt;/div&gt;  &lt;div style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: #eee"&gt;&lt;span style="color: green"&gt;    // The format of the returned date is yyyy-MM-dd hh:mm:ss      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; d = observation.datetime;      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; date = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; Date(d.substr(0,4), d.substr(5,2), d.substr(8,2),      &lt;br /&gt;                        d.substr(11,2), d.substr(14,2), d.substr(17,2));       &lt;br /&gt;     &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; isDay = (date.getHours() &amp;gt; 6 &amp;amp;&amp;amp; date.getHours() &amp;lt; 20);      &lt;br /&gt;       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;switch&lt;/span&gt;&lt;span style="color: black"&gt; (observation.clouds)      &lt;br /&gt;    {       &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;case&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: #a31515"&gt;'clear sky'&lt;/span&gt;&lt;span style="color: black"&gt;:      &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (isDay) icon = &lt;/span&gt;&lt;span style="color: #a31515"&gt;'32'&lt;/span&gt;&lt;span style="color: black"&gt;; &lt;/span&gt;&lt;span style="color: blue"&gt;else&lt;/span&gt;&lt;span style="color: black"&gt; icon = &lt;/span&gt;&lt;span style="color: #a31515"&gt;'31'&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;break&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;case&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: #a31515"&gt;'few clouds'&lt;/span&gt;&lt;span style="color: black"&gt;:      &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (isDay) icon = &lt;/span&gt;&lt;span style="color: #a31515"&gt;'30'&lt;/span&gt;&lt;span style="color: black"&gt;; &lt;/span&gt;&lt;span style="color: blue"&gt;else&lt;/span&gt;&lt;span style="color: black"&gt; icon = &lt;/span&gt;&lt;span style="color: #a31515"&gt;'29'&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;break&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;case&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: #a31515"&gt;'scattered clouds'&lt;/span&gt;&lt;span style="color: black"&gt;:      &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (isDay) icon = &lt;/span&gt;&lt;span style="color: #a31515"&gt;'28'&lt;/span&gt;&lt;span style="color: black"&gt;; &lt;/span&gt;&lt;span style="color: blue"&gt;else&lt;/span&gt;&lt;span style="color: black"&gt; icon = &lt;/span&gt;&lt;span style="color: #a31515"&gt;'27'&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;break&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;case&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: #a31515"&gt;'broken clouds'&lt;/span&gt;&lt;span style="color: black"&gt;:      &lt;br /&gt;            icon = &lt;/span&gt;&lt;span style="color: #a31515"&gt;'26'&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;break&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;case&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: #a31515"&gt;'overcast'&lt;/span&gt;&lt;span style="color: black"&gt;:      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;case&lt;/span&gt;&lt;span style="color: black"&gt; &lt;/span&gt;&lt;span style="color: #a31515"&gt;'vertical visibility'&lt;/span&gt;&lt;span style="color: black"&gt;:      &lt;br /&gt;            icon = &lt;/span&gt;&lt;span style="color: #a31515"&gt;'23'&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: blue"&gt;break&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: blue"&gt;default&lt;/span&gt;&lt;span style="color: black"&gt;:      &lt;br /&gt;            icon = &lt;/span&gt;&lt;span style="color: #a31515"&gt;'NA'&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;    }       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: green"&gt;// The wind speed is converted from knots to m/s      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; windSpeedMs = Math.round(observation.windSpeed * 0.5144444 * 100)/100;      &lt;br /&gt;   &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; html = &lt;/span&gt;&lt;span style="color: #a31515"&gt;"&amp;lt;em&amp;gt;{0}&amp;lt;/em&amp;gt;&amp;lt;br/&amp;gt;&amp;lt;b&amp;gt;Clouds:&amp;lt;/b&amp;gt; {1}&amp;lt;br/&amp;gt;&amp;lt;b&amp;gt;Weather condition:&amp;lt;/b&amp;gt; {2}&amp;lt;br/&amp;gt;"&lt;/span&gt;&lt;span style="color: black"&gt; +      &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: #a31515"&gt;"&amp;lt;b&amp;gt;Temperature:&amp;lt;/b&amp;gt; {3} °C&amp;lt;br/&amp;gt;&amp;lt;b&amp;gt;Dew Point:&amp;lt;/b&amp;gt; {4} °C&amp;lt;br/&amp;gt;"&lt;/span&gt;&lt;span style="color: black"&gt; +      &lt;br /&gt;            &lt;/span&gt;&lt;span style="color: #a31515"&gt;"&amp;lt;b&amp;gt;Wind:&amp;lt;/b&amp;gt; {5}kt ({6} m/s) from {7}°&amp;lt;br/&amp;gt;&amp;lt;b&amp;gt;Altimeter:&amp;lt;/b&amp;gt; {8} hPa"&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; details = String.format(html,      &lt;br /&gt;            observation.datetime, observation.clouds, observation.weatherCondition,       &lt;br /&gt;            observation.temperature, observation.dewPoint, observation.windSpeed,       &lt;br /&gt;            windSpeedMs, observation.windDirection, observation.hectoPascAltimeter);       &lt;br /&gt;     &lt;br /&gt;    icon = String.format(&lt;/span&gt;&lt;span style="color: #a31515"&gt;"images/{0}.png"&lt;/span&gt;&lt;span style="color: black"&gt;, icon);      &lt;br /&gt;    icon = GetCorrectIcon(icon, 48, 48, -10, -12);       &lt;br /&gt;    AddPushpin(observation.lat, observation.lng, observation.stationName, details, icon);       &lt;br /&gt;}&lt;/span&gt; &lt;/div&gt;  &lt;p&gt;Most of the function above is self-explanatory or already commented in the code. What I want to point out, is what happens in the last three lines. First of all, the icon's name is transformed to a hard-coded virtual path. Then the custom html to use for the pushpin's custom icon is obtained by invoking the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;GetCorrectIcon()&lt;/span&gt; function and passing it the icon's file path, the icon's dimensions and the icon's offset (needed to position the icon correctly on the map). Finally, the call to &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;AddPushpin()&lt;/span&gt; actually creates the weather pushpins and adds them to the map.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;The kind of elaborations seen in the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace"&gt;AddWeatherPushpin()&lt;/span&gt; function could obviously have been made on the server and sent to the client together with the remote service's JSON response, but this would have involved serialization and deserialization of data on the server. By choosing this approach, we would have kept the client code tidier, and we would have leveraged the fact that we had to use a proxy Web Service anyway, but this was beyond the scope of this article. If you want to know more of how to elaborate the response from a JSON Web Service on the server, and want to see an example of how this can be done, you can take a look at &lt;a href="http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/31/json_in_aspnetajax_part3.aspx" target="_blank"&gt;this article&lt;/a&gt;.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Let's see how these functions are implemented:&lt;/p&gt;  &lt;div style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: #eee"&gt;&lt;span style="color: blue"&gt;function&lt;/span&gt;&lt;span style="color: black"&gt; GetCorrectIcon(iconPath, width, height, offsetLeft, offsetTop)      &lt;br /&gt;{       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: green"&gt;/// &amp;lt;summary&amp;gt;Fixes the IE6 png transparency issue for the passed icon&amp;lt;/summary&amp;gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; html;      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (Sys.Browser.agent == Sys.Browser.InternetExplorer &amp;amp;&amp;amp;      &lt;br /&gt;        Sys.Browser.version == 6)       &lt;br /&gt;        html = &lt;/span&gt;&lt;span style="color: #a31515"&gt;"&amp;lt;img src='images/blank.gif' "&lt;/span&gt;&lt;span style="color: black"&gt; +      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: #a31515"&gt;"style='position:absolute;left:{0}px;top:{1}px;width:{2}px;height:{3}px;"&lt;/span&gt;&lt;span style="color: black"&gt; +      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: #a31515"&gt;"filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\"{4}\", "&lt;/span&gt;&lt;span style="color: black"&gt; +      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: #a31515"&gt;"sizingMethod=\"image\" );' /&amp;gt;"&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;else      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: black"&gt;        html = &lt;/span&gt;&lt;span style="color: #a31515"&gt;"&amp;lt;img src='{4}' "&lt;/span&gt;&lt;span style="color: black"&gt; +      &lt;br /&gt;        &lt;/span&gt;&lt;span style="color: #a31515"&gt;"style='position:absolute;left:{0}px;top:{1}px;width:{2}px;height:{3}px;' /&amp;gt;"&lt;/span&gt;&lt;span style="color: black"&gt;;      &lt;br /&gt;     &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (!offsetLeft) offsetLeft = 0;      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (!offsetTop) offsetTop = 0;      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: black"&gt; String.format(html, offsetLeft, offsetTop, width, height, iconPath);      &lt;br /&gt;}     &lt;br /&gt;      &lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;function&lt;/span&gt;&lt;span style="color: black"&gt; AddPushpin(lat, lon, title, description, icon)      &lt;br /&gt;{       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; point = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; VELatLong(lat, lon);      &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;var&lt;/span&gt;&lt;span style="color: black"&gt; shp = &lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: black"&gt; VEShape(VEShapeType.Pushpin, point);      &lt;br /&gt;    shp.SetTitle(title);       &lt;br /&gt;    shp.SetDescription(description);       &lt;br /&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;if&lt;/span&gt;&lt;span style="color: black"&gt; (icon)      &lt;br /&gt;    {       &lt;br /&gt;        shp.SetCustomIcon(icon);       &lt;br /&gt;    }       &lt;br /&gt;    map.AddShape(shp);       &lt;br /&gt;}&lt;/span&gt; &lt;/div&gt;  &lt;p&gt;Basically, the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;&lt;strong&gt;GetCorrectIcon()&lt;/strong&gt;&lt;/span&gt; function's role is to generate the html needed to position the weather icon correctly on the map. To do this, we need to create an &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;img&lt;/span&gt; tag and add some inline CSS properties to it, taking into account the icon's dimensions and the desired offset. In fact, by default, pushpin icons are positioned on the map assuming an icon size of 25x30 pixels; when a different icon size is used, the icon's positioning on the map has to be manually fine-tuned; this can be done by setting the CSS &lt;font face="Consolas" size="2"&gt;left&lt;/font&gt; and &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;top&lt;/span&gt; properties for the image. &lt;/p&gt;  &lt;p&gt;Another thing to take into account is that we're using transparent &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;.png&lt;/span&gt; images, and, as everyone knows, Internet Explorer 6 cannot render them correctly, so we need to use a workaround to make everything work smoothly also on that browser. In particular, we leverage once again the AJAX Client Library's utility classes to check whether the current browser is IE6, and in that case, we use Microsoft's &lt;a href="http://support.microsoft.com/default.aspx?scid=kb;en-us;294714" target="_blank"&gt;suggested fix&lt;/a&gt; for this problem, and add the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;AlphaImageLoader&lt;/span&gt; filter to the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;img&lt;/span&gt; styles collection, while setting the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;img src&lt;/span&gt; attribute to a 1x1 pixel blank image. This will make the experience of those users using IE6 as pleasant as anyone else's.&lt;/p&gt;  &lt;p&gt;Finally, let's spend a few words about the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;&lt;strong&gt;AddPushpin()&lt;/strong&gt;&lt;/span&gt; function. It simply creates a Pushpin shape located at the supplied coordinates, sets the content of the associated InfoBox using the supplied title and description, and finally, when the &lt;span style="font-size: 10pt; font-family: consolas, courier new, monospace; background-color: white"&gt;icon&lt;/span&gt; parameter is specified, sets a custom icon for the pushpin. Finally, it adds the freshly created icon to the VE map.&lt;/p&gt;  &lt;p&gt;And that's all! Finally, our Virtual Earth mashup is ready to be enjoyed by our users!&lt;/p&gt;  &lt;h5&gt;As usual, you can see a &lt;a href="http://www.prestifin.biz/JuanDoNeblo/VEMashup/Default.aspx" target="_blank"&gt;live demo&lt;/a&gt; of the application &lt;a href="http://www.prestifin.biz/JuanDoNeblo/VEMashup/Default.aspx" target="_blank"&gt;here&lt;/a&gt;, and you can &lt;a href="http://www.prestifin.biz/JuanDoNeblo/VEMashup/VEMashup.zip" target="_blank"&gt;download the source code&lt;/a&gt; of this project &lt;a href="http://www.prestifin.biz/JuanDoNeblo/VEMashup/VEMashup.zip" target="_blank"&gt;here&lt;/a&gt;.&lt;/h5&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;  &lt;h5 style="color: #b4c835"&gt;Marco&lt;/h5&gt;  &lt;p&gt; &lt;/p&gt;  &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:c2d2f5a4-723b-48e2-aa02-5f548a081d63" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Virtual%20Earth" rel="tag"&gt;Virtual Earth&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Mashup" rel="tag"&gt;Mashup&lt;/a&gt;,&lt;a href="http://technorati.com/tags/ASP.NET" rel="tag"&gt;ASP.NET&lt;/a&gt;,&lt;a href="http://technorati.com/tags/AJAX" rel="tag"&gt;AJAX&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Javascript" rel="tag"&gt;Javascript&lt;/a&gt;,&lt;a href="http://technorati.com/tags/C#" rel="tag"&gt;C#&lt;/a&gt;,&lt;a href="http://technorati.com/tags/JSON" rel="tag"&gt;JSON&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Weather" rel="tag"&gt;Weather&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Web%20Service" rel="tag"&gt;Web Service&lt;/a&gt;&lt;/div&gt;  &lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fgeekswithblogs.net%2fJuanDoNeblo%2farchive%2f2007%2f11%2f13%2fGetting-started-with-Virtual-Earth-Mashups-showing-current-weather-conditions.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fgeekswithblogs.net%2fJuanDoNeblo%2farchive%2f2007%2f11%2f13%2fGetting-started-with-Virtual-Earth-Mashups-showing-current-weather-conditions.aspx" border="0" /&gt;&lt;/a&gt; &lt;a href="http://digg.com/submit?phase=2&amp;amp;url=http%3A//geekswithblogs.net/JuanDoNeblo/archive/2007/11/13/Getting-started-with-Virtual-Earth-Mashups-showing-current-weather-conditions.aspx&amp;amp;topic=programming&amp;amp;"&gt;&lt;img height="16" alt="Digg!" src="http://digg.com/img/badges/16x16-digg-guy.gif" width="16" /&gt;&lt;/a&gt;&lt;a href="http://www.dzone.com/links/getting_started_with_virtual_earth_mashups_showin.html"&gt;&lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="16" alt="dzone" src="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/Asi.NETAJAXshowingcurrentweatherconditio_C9A1/dzone_3.png" width="16" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=116823"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=116823" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/JuanDoNeblo/aggbug/116823.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Marco Anastasi &amp; Serena Caruso</dc:creator>
            <guid>http://geekswithblogs.net/JuanDoNeblo/archive/2007/11/13/Getting-started-with-Virtual-Earth-Mashups-showing-current-weather-conditions.aspx</guid>
            <pubDate>Tue, 13 Nov 2007 18:15:21 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/JuanDoNeblo/comments/116823.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/JuanDoNeblo/archive/2007/11/13/Getting-started-with-Virtual-Earth-Mashups-showing-current-weather-conditions.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/JuanDoNeblo/comments/commentRss/116823.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/JuanDoNeblo/services/trackbacks/116823.aspx</trackback:ping>
        </item>
        <item>
            <title>JSON in ASP.NET Ajax: Part 3. Server side deserialization and elaboration of JSON data returned from a Web Service.</title>
            <link>http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/31/json_in_aspnetajax_part3.aspx</link>
            <description>&lt;p&gt;&lt;em&gt;This is the third part of a series of articles on ASP.NET AJAX and JSON. If you haven't read &lt;a target="_blank" href="http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/22/json_in_aspnetajax_part1.aspx"&gt;part 1&lt;/a&gt; and &lt;a target="_blank" href="http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/24/json_in_aspnetajax_part2.aspx"&gt;part 2&lt;/a&gt; of this series, you are strongly advised to do so before going on to read this article.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Let's take what we've seen so far on JSON and ASP.NET one step further, and discover how we can leverage the ASP.NET AJAX infastructure to make the managing of an AJAX application even sleeker. Now, let's imagine that we want to elaborate the JSON response returned from the web service before sending it back to the client. &lt;/p&gt;
&lt;p&gt;This can prove useful for many a reason, for example, to enrich the returned object with properties generated by complex elaborations, which we would rather do on the server than on the client.&lt;/p&gt;
&lt;p&gt;In fact, what we will see today, is how to add a &lt;a target="_blank" href="http://en.wikipedia.org/wiki/Air_pollution_dispersion_terminology"&gt;Stability Class&lt;/a&gt; property, computed used the Pasquill method for categorizing atmospheric turbulence, to the weather observation data returned from the &lt;a target="_blank" href="http://www.geonames.org/export/JSON-webservices.html#weatherJSON"&gt;Geonames&lt;/a&gt; web service we have come to know in my previous articles. I want to point out that this is merely an example of a complex elaboration that would generally take place on the server rather than on the client, but it could be substituted with any kind of data transformation or elaboration that you would need to apply to the data &lt;strong&gt;before &lt;/strong&gt;sending it back to the client.&lt;/p&gt;
&lt;p&gt;Now, in order to do this, we might modify the returned JSON object directly as a string, but you can imagine how cumbersome and error-prone this process would become if the elaborations to be made were less than trivial. We need some more flexibility. And here's where the ASP.NET AJAX infrastructure comes to help us again.&lt;/p&gt;
&lt;p&gt;What we want to do first, is convert the JSON response to a .NET object, in order to pave the way for the elaborations that we are going to make. We can do this in a straightforward way, leveraging the .NET &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: white"&gt;JavaScriptSerializer&lt;/span&gt; class, which can be found in the &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: white"&gt;System.Web.Script.Serialization&lt;/span&gt; namespace. But before starting the actual deserialization process, we need to make some preparation. First of all, we need to create the class we want our JSON object to be shaped into:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: #eee"&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;class&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;WeatherObservation &lt;br /&gt;
&lt;/span&gt;&lt;span style="COLOR: black"&gt;{ &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;span style="COLOR: black"&gt; clouds { &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;span style="COLOR: black"&gt;; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;set&lt;/span&gt;&lt;span style="COLOR: black"&gt;; } &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;span style="COLOR: black"&gt; observation { &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;span style="COLOR: black"&gt;; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;set&lt;/span&gt;&lt;span style="COLOR: black"&gt;; } &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;span style="COLOR: black"&gt; weatherCondition { &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;span style="COLOR: black"&gt;; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;set&lt;/span&gt;&lt;span style="COLOR: black"&gt;; } &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;&lt;span style="COLOR: black"&gt; windDirection { &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;span style="COLOR: black"&gt;; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;set&lt;/span&gt;&lt;span style="COLOR: black"&gt;; } &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;&lt;span style="COLOR: black"&gt; windSpeed { &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;span style="COLOR: black"&gt;; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;set&lt;/span&gt;&lt;span style="COLOR: black"&gt;; } &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;span style="COLOR: black"&gt; ICAO { &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;span style="COLOR: black"&gt;; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;set&lt;/span&gt;&lt;span style="COLOR: black"&gt;; } &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;&lt;span style="COLOR: black"&gt; elevation { &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;span style="COLOR: black"&gt;; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;set&lt;/span&gt;&lt;span style="COLOR: black"&gt;; } &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;span style="COLOR: black"&gt; countryCode { &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;span style="COLOR: black"&gt;; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;set&lt;/span&gt;&lt;span style="COLOR: black"&gt;; } &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;double&lt;/span&gt;&lt;span style="COLOR: black"&gt; lat { &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;span style="COLOR: black"&gt;; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;set&lt;/span&gt;&lt;span style="COLOR: black"&gt;; } &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;double&lt;/span&gt;&lt;span style="COLOR: black"&gt; lng { &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;span style="COLOR: black"&gt;; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;set&lt;/span&gt;&lt;span style="COLOR: black"&gt;; } &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;&lt;span style="COLOR: black"&gt; temperature { &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;span style="COLOR: black"&gt;; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;set&lt;/span&gt;&lt;span style="COLOR: black"&gt;; } &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;&lt;span style="COLOR: black"&gt; dewPoint { &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;span style="COLOR: black"&gt;; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;set&lt;/span&gt;&lt;span style="COLOR: black"&gt;; } &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;&lt;span style="COLOR: black"&gt; humidity { &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;span style="COLOR: black"&gt;; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;set&lt;/span&gt;&lt;span style="COLOR: black"&gt;; } &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;span style="COLOR: black"&gt; stationName { &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;span style="COLOR: black"&gt;; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;set&lt;/span&gt;&lt;span style="COLOR: black"&gt;; } &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;span style="COLOR: black"&gt; datetime { &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;span style="COLOR: black"&gt;; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;set&lt;/span&gt;&lt;span style="COLOR: black"&gt;; } &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;int&lt;/span&gt;&lt;span style="COLOR: black"&gt; hectoPascAltimeter { &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;span style="COLOR: black"&gt;; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;set&lt;/span&gt;&lt;span style="COLOR: black"&gt;; } &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;span style="COLOR: black"&gt; stabilityClass { &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;span style="COLOR: black"&gt;; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;set&lt;/span&gt;&lt;span style="COLOR: black"&gt;; } &lt;br /&gt;
}&lt;/span&gt; &lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;As you can see, the properties that we added to the class map directly to those present in the returned JSON object. (See &lt;a target="_blank" href="http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/24/json_in_aspnetajax_part2.aspx"&gt;here&lt;/a&gt; if you haven't read my previous post and you want to see how the returned JSON string looks like). Also notice that this is the place where we define the additional properties that we want to send to the client along with the original ones; in this case, we added the &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: white"&gt;stabilityClass&lt;/span&gt; property.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;NOTE: You might notice that we used Automatic Properties, a new language feature introduced with C# 3.0, to make our code more compact and readable (let alone saving a lot of keystrokes ;) ). You can read more on Automatic Properties on &lt;/em&gt;&lt;a target="_blank" href="http://weblogs.asp.net/scottgu/archive/2007/03/08/new-c-orcas-language-features-automatic-properties-object-initializers-and-collection-initializers.aspx"&gt;&lt;em&gt;Scott Guthrie's blog&lt;/em&gt;&lt;/a&gt;&lt;em&gt;. If you are not using C# 3.0 yet, the only thing you need to do in order to make this work, is to write basic properties or public fields rather than Automatic Properties.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Actually, if you look at the returned JSON string closely, you'll find out that the weather observation is not returned as a top-level object, but is itself the content of the top-level &lt;em&gt;weatherObservation&lt;/em&gt; property. This might seem redundant at first, but this schema is due to fact that more than one weather observation can be returned from the Web Service if desired, and in that case the &lt;em&gt;weatherObservations&lt;/em&gt; property would contain an array of observations. Anyway, we can overlook this detail for the moment; all we need to do now to make everything work smoothly, is define a new class, containing a &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: white"&gt;weatherObservation &lt;/span&gt;property:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: #eee"&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;class&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;SingleWeatherObservation &lt;br /&gt;
&lt;/span&gt;&lt;span style="COLOR: black"&gt;{ &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;WeatherObservation&lt;/span&gt;&lt;span style="COLOR: black"&gt; weatherObservation { &lt;/span&gt;&lt;span style="COLOR: blue"&gt;get&lt;/span&gt;&lt;span style="COLOR: black"&gt;; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;set&lt;/span&gt;&lt;span style="COLOR: black"&gt;; } &lt;br /&gt;
}&lt;/span&gt; &lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Now we're ready to modify our &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: white"&gt;GetWeatherByLocation&lt;/span&gt; method.&lt;/p&gt;
&lt;p&gt;We'll add a call to the &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: white"&gt;Deserialize&amp;lt;T&amp;gt;()&lt;/span&gt; method of the &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: white"&gt;JavaScriptSerializer&lt;/span&gt; class. This method will return an object of type T, containing the deserialized data, which we will use for all our subsequent computations. In particular, we'll pass this object to our &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: white"&gt;ComputeStabilityClasses()&lt;/span&gt; method, in order to compute the suggested Stability Classes. Later, we'll use this value to set the &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: white"&gt;stabilityClass&lt;/span&gt; property of our object. Let's see how the code looks like:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: #eee"&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;static&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;span style="COLOR: black"&gt; GetWeatherByLocation(&lt;/span&gt;&lt;span style="COLOR: blue"&gt;double&lt;/span&gt;&lt;span style="COLOR: black"&gt; lat, &lt;/span&gt;&lt;span style="COLOR: blue"&gt;double&lt;/span&gt;&lt;span style="COLOR: black"&gt; lng) &lt;br /&gt;
{ &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;span style="COLOR: black"&gt; formattedUri = &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;String&lt;/span&gt;&lt;span style="COLOR: black"&gt;.Format(&lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;CultureInfo&lt;/span&gt;&lt;span style="COLOR: black"&gt;.InvariantCulture,&lt;/span&gt;&lt;/div&gt;
&lt;div style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: #eee"&gt;&lt;span style="COLOR: black"&gt;                                        FindNearbyWeatherUrl, lat, lng); &lt;br /&gt;
&lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;HttpWebRequest&lt;/span&gt;&lt;span style="COLOR: black"&gt; webRequest = GetWebRequest(formattedUri); &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;HttpWebResponse&lt;/span&gt;&lt;span style="COLOR: black"&gt; response = (&lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;HttpWebResponse&lt;/span&gt;&lt;span style="COLOR: black"&gt;)webRequest.GetResponse(); &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;span style="COLOR: black"&gt; jsonResponse = &lt;/span&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;span style="COLOR: black"&gt;.Empty; &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt;&lt;span style="COLOR: black"&gt; (&lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;StreamReader&lt;/span&gt;&lt;span style="COLOR: black"&gt; sr = &lt;/span&gt;&lt;span style="COLOR: blue"&gt;new&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;StreamReader&lt;/span&gt;&lt;span style="COLOR: black"&gt;(response.GetResponseStream())) &lt;br /&gt;
    { &lt;br /&gt;
        jsonResponse = sr.ReadToEnd(); &lt;br /&gt;
    }&lt;/span&gt;&lt;/div&gt;
&lt;div style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: #eee"&gt;&lt;span style="COLOR: black"&gt;&lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;JavaScriptSerializer&lt;/span&gt;&lt;span style="COLOR: black"&gt; ser = &lt;/span&gt;&lt;span style="COLOR: blue"&gt;new&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;JavaScriptSerializer&lt;/span&gt;&lt;span style="COLOR: black"&gt;(); &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;SingleWeatherObservation&lt;/span&gt;&lt;span style="COLOR: black"&gt; observation = &lt;/span&gt;&lt;/div&gt;
&lt;div style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: #eee"&gt;&lt;span style="COLOR: black"&gt;                     ser.Deserialize&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;SingleWeatherObservation&lt;/span&gt;&lt;span style="COLOR: black"&gt;&amp;gt;(jsonResponse); &lt;br /&gt;
    observation.weatherObservation.stabilityClass =&lt;/span&gt;&lt;/div&gt;
&lt;div style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: #eee"&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: black"&gt;                     ComputeStabilityClasses(observation.weatherObservation); &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;return&lt;/span&gt;&lt;span style="COLOR: black"&gt; ser.Serialize(observation); &lt;br /&gt;
}&lt;/span&gt; &lt;/div&gt;
&lt;div style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: #eee"&gt;&lt;span style="COLOR: blue"&gt;private&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;static&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;&lt;span style="COLOR: black"&gt; ComputeStabilityClasses(WeatherObservation weatherObservation) &lt;br /&gt;
{ &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: green"&gt;// ... code for computing the Stability Class &lt;br /&gt;
&lt;/span&gt;&lt;span style="COLOR: black"&gt;}&lt;/span&gt; &lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;As you can see, the last thing we do is serialize our object back to a JSON string before handing it back to the caller (which happens to be our proxy Web Service). This is perfectly legitimate, but is an unnecessary step that can be avoided, now that we are working with .NET objects. In fact, the AJAX framework can take the burden of serializing and deserializing .NET objects to and from JSON onto its shoulders, in order to make the process of calling ASP.NET Script-enabled Web Services completely transparent to the user. Let's see how to do this.&lt;/p&gt;
&lt;p&gt;First of all, we need to make some little changes to our &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: white"&gt;GetWeatherByLocation()&lt;/span&gt; method in order to make it return our .NET object rather than its JSON-serialized counterpart; we'll have to change its signature, and return our &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: white"&gt;observation&lt;/span&gt; object without serializing it:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: #eee"&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;static&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;SingleWeatherObservation&lt;/span&gt;&lt;span style="COLOR: black"&gt; GetWeatherByLocation(&lt;/span&gt;&lt;span style="COLOR: blue"&gt;double&lt;/span&gt;&lt;span style="COLOR: black"&gt; lat, &lt;/span&gt;&lt;span style="COLOR: blue"&gt;double&lt;/span&gt;&lt;span style="COLOR: black"&gt; lng) &lt;br /&gt;
{ &lt;br /&gt;
&lt;/span&gt;&lt;span style="COLOR: green"&gt;    //.... Same code as above &lt;br /&gt;
&lt;/span&gt;&lt;span style="COLOR: blue"&gt;    return&lt;/span&gt;&lt;span style="COLOR: black"&gt; observation; &lt;br /&gt;
}&lt;/span&gt; &lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Then we'll have to propagate this change to the caller method, i.e. the Web Service's &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: white"&gt;GetWeatherByLocation()&lt;/span&gt; method:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: #eee"&gt;&lt;span style="COLOR: blue"&gt;namespace&lt;/span&gt;&lt;span style="COLOR: black"&gt; Mashup &lt;br /&gt;
{ &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: green"&gt;/* To allow this Web Service to be called from script using ASP.NET AJAX,   &lt;br /&gt;
     * we need to set the following attribute. */ &lt;br /&gt;
&lt;/span&gt;&lt;span style="COLOR: black"&gt;    [&lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;ScriptService&lt;/span&gt;&lt;span style="COLOR: black"&gt;] &lt;br /&gt;
    [&lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;WebService&lt;/span&gt;&lt;span style="COLOR: black"&gt;(Namespace = &lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;"Mashup"&lt;/span&gt;&lt;span style="COLOR: black"&gt;)] &lt;br /&gt;
    [&lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;WebServiceBinding&lt;/span&gt;&lt;span style="COLOR: black"&gt;(ConformsTo = &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;WsiProfiles&lt;/span&gt;&lt;span style="COLOR: black"&gt;.BasicProfile1_1)] &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;class&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;WeatherService&lt;/span&gt;&lt;span style="COLOR: black"&gt; : &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;WebService &lt;br /&gt;
&lt;/span&gt;&lt;span style="COLOR: black"&gt;    { &lt;br /&gt;
        [&lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;WebMethod&lt;/span&gt;&lt;span style="COLOR: black"&gt;] &lt;br /&gt;
        &lt;/span&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;SingleWeatherObservation&lt;/span&gt;&lt;span style="COLOR: black"&gt; GetWeatherByLocation(&lt;/span&gt;&lt;span style="COLOR: blue"&gt;double&lt;/span&gt;&lt;span style="COLOR: black"&gt; lat, &lt;/span&gt;&lt;span style="COLOR: blue"&gt;double&lt;/span&gt;&lt;span style="COLOR: black"&gt; lng) &lt;br /&gt;
        { &lt;br /&gt;
            &lt;/span&gt;&lt;span style="COLOR: blue"&gt;return&lt;/span&gt;&lt;span style="COLOR: black"&gt; &lt;/span&gt;&lt;span style="COLOR: #2b91af"&gt;GeonamesWeather&lt;/span&gt;&lt;span style="COLOR: black"&gt;.GetWeatherByLocation(lat, lng); &lt;br /&gt;
        } &lt;br /&gt;
    } &lt;br /&gt;
}&lt;/span&gt; &lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;You can see that the Web Method returns a &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: white"&gt;SingleWeatherObservation&lt;/span&gt; object rather than a string containing its JSON representation. Now, we'll have to make some little changes to the client code in order to reflect the changes made to the server side.&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: #eee"&gt;&lt;span style="COLOR: blue"&gt;function&lt;/span&gt;&lt;span style="COLOR: black"&gt; callService() &lt;br /&gt;
{ &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;var&lt;/span&gt;&lt;span style="COLOR: black"&gt; latitude = $get(&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;'txtLat'&lt;/span&gt;&lt;span style="COLOR: black"&gt;).value; &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;var&lt;/span&gt;&lt;span style="COLOR: black"&gt; longitude = $get(&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;'txtLng'&lt;/span&gt;&lt;span style="COLOR: black"&gt;).value; &lt;br /&gt;
    Mashup.WeatherService.GetWeatherByLocation(latitude, longitude,  &lt;br /&gt;
                                     GetWeather_success, onFailed); &lt;br /&gt;
} &lt;br /&gt;
&lt;/span&gt;&lt;span style="COLOR: blue"&gt;function&lt;/span&gt;&lt;span style="COLOR: black"&gt; GetWeather_success(e) &lt;br /&gt;
{ &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: green"&gt;//var result = Sys.Serialization.JavaScriptSerializer.deserialize(e, true); &lt;br /&gt;
&lt;/span&gt;&lt;span style="COLOR: black"&gt;    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;var&lt;/span&gt;&lt;span style="COLOR: black"&gt; result = e; &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;var&lt;/span&gt;&lt;span style="COLOR: black"&gt; weatherData = &lt;/span&gt;&lt;span style="COLOR: blue"&gt;new&lt;/span&gt;&lt;span style="COLOR: black"&gt; Sys.StringBuilder(); &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;var&lt;/span&gt;&lt;span style="COLOR: black"&gt; line; &lt;br /&gt;
    &lt;/span&gt;&lt;span style="COLOR: blue"&gt;for&lt;/span&gt;&lt;span style="COLOR: black"&gt;(&lt;/span&gt;&lt;span style="COLOR: blue"&gt;var&lt;/span&gt;&lt;span style="COLOR: black"&gt; property &lt;/span&gt;&lt;span style="COLOR: blue"&gt;in&lt;/span&gt;&lt;span style="COLOR: black"&gt; result.weatherObservation) &lt;br /&gt;
    { &lt;br /&gt;
        line = String.format(&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;"&amp;lt;b&amp;gt;{0}:&amp;lt;/b&amp;gt; {1}&amp;lt;br/&amp;gt;"&lt;/span&gt;&lt;span style="COLOR: black"&gt;, &lt;br /&gt;
                             property, result.weatherObservation[property]); &lt;br /&gt;
        weatherData.append(line); &lt;br /&gt;
    } &lt;br /&gt;
    $get(&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;'divResult'&lt;/span&gt;&lt;span style="COLOR: black"&gt;).innerHTML = weatherData.toString(); &lt;br /&gt;
}&lt;/span&gt; &lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Nothing has changed from what we have seen previously, except for the first line in &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: white"&gt;GetWeather_success(e)&lt;/span&gt;; we don't need to explicitly deserialize the argument received from the Web Service call anymore, as this is done under the hood for us by the AJAX framework. We can assume that &lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace; BACKGROUND-COLOR: white"&gt;e&lt;/span&gt; is a Javascript object that closely mimics the structure of the .NET object returned from the Web Method. &lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Notice that by default, &lt;/em&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace"&gt;JavaScriptSerializer&lt;/span&gt;&lt;em&gt; supports most usual data types. However, you can serialize and deserialize types that are not natively supported by &lt;/em&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace"&gt;JavaScriptSerializer&lt;/span&gt;&lt;em&gt; by implementing custom converters using the &lt;/em&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace"&gt;JavaScriptConverter&lt;/span&gt;&lt;em&gt;  class, and then register the converters by using the &lt;/em&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: consolas, courier new, monospace"&gt;RegisterConverters&lt;/span&gt;&lt;em&gt;  method. For more information, consult &lt;a target="_blank" href="http://asp.net/ajax/documentation/live/mref/T_System_Web_Script_Serialization_JavaScriptSerializer.aspx"&gt;this page&lt;/a&gt; of the ASP.NET AJAX Documentation, or have a look at &lt;a target="_blank" href="http://pietschsoft.com/blog/Post.aspx?PostID=1377"&gt;this&lt;/a&gt; interesting article by &lt;a target="_blank" href="http://pietschsoft.com/Default.aspx"&gt;Chris Pietschmann&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;As you can see, we have attained a completely transparent communication between server and client code. All the details of serialization / deserialization to and from JSON are hidden from our view by the ASP.NET AJAX framework.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;h5&gt;You can &lt;a target="_blank" href="http://www.prestifin.biz/JuanDoNeblo/JsonWeatherPart3/JsonWeather.aspx"&gt;see a live Demo here&lt;/a&gt; or &lt;a target="_blank" href="http://www.prestifin.biz/JuanDoNeblo/JsonWeatherPart3/JsonWeather-Part3.zip"&gt;download the Source Code&lt;/a&gt; of this project &lt;a target="_blank" href="http://www.prestifin.biz/JuanDoNeblo/JsonWeatherPart3/JsonWeather-Part3.zip"&gt;here&lt;/a&gt;.&lt;/h5&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;
&lt;h5 style="COLOR: rgb(180,200,53)"&gt;Marco&lt;/h5&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:6db48c80-610b-4699-8630-5027dccc268c" style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; FLOAT: none; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"&gt;Technorati Tag: &lt;a rel="tag" href="http://technorati.com/tags/C#/"&gt;C#&lt;/a&gt; , &lt;a rel="tag" href="http://technorati.com/tags/ASP.NET/"&gt;ASP.NET&lt;/a&gt; , &lt;a rel="tag" href="http://technorati.com/tags/AJAX/"&gt;AJAX&lt;/a&gt; , &lt;a rel="tag" href="http://technorati.com/tags/JSON/"&gt;JSON&lt;/a&gt; , &lt;a rel="tag" href="http://technorati.com/tags/Web%20Service/"&gt;Web Service&lt;/a&gt; , &lt;a rel="tag" href="http://technorati.com/tags/Javascript/"&gt;Javascript&lt;/a&gt; , &lt;a rel="tag" href="http://technorati.com/tags/Weather/"&gt;Weather&lt;/a&gt; &lt;/div&gt;
&lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fgeekswithblogs.net%2fJuanDoNeblo%2farchive%2f2007%2f10%2f31%2fjson_in_aspnetajax_part3.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fgeekswithblogs.net%2fJuanDoNeblo%2farchive%2f2007%2f10%2f31%2fjson_in_aspnetajax_part3.aspx" /&gt;&lt;/a&gt; &lt;a href="http://digg.com/submit?phase=2&amp;amp;url=http%3A//geekswithblogs.net/JuanDoNeblo/archive/2007/10/31/json_in_aspnetajax_part3.aspx&amp;amp;topic=programming&amp;amp;"&gt;&lt;img height="16" alt="Digg!" width="16" src="http://digg.com/img/badges/16x16-digg-guy.gif" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=116488"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=116488" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/JuanDoNeblo/aggbug/116488.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Marco Anastasi &amp; Serena Caruso</dc:creator>
            <guid>http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/31/json_in_aspnetajax_part3.aspx</guid>
            <pubDate>Wed, 31 Oct 2007 23:32:57 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/JuanDoNeblo/comments/116488.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/31/json_in_aspnetajax_part3.aspx#feedback</comments>
            <slash:comments>3</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/JuanDoNeblo/comments/commentRss/116488.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/JuanDoNeblo/services/trackbacks/116488.aspx</trackback:ping>
        </item>
        <item>
            <title>Data Interpolation with SPLINE in C#</title>
            <link>http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/25/Data-Interpolation-with-SPLINE-in-Csharp.aspx</link>
            <description>&lt;p&gt;Often, when dealing with mathematical models for hazard estimation, one has to make the most out of just a handful of experimental data, and try to extract a rule or a behavioural function. While the use of lookup charts printed on paper may sometimes be a viable option, we won’t be able to rely on it when we want to implement a software solution. &lt;/p&gt;
&lt;p&gt;When this is the case, soft-computing may look like the perfect solution; neural networks can process data, learn their trend, and elaborate new samples to fill the gaps; but this would involve a considerable use of computational resources (and a lot more time). So, how can we find a good compromise? &lt;/p&gt;
&lt;p&gt;A simple and fast solution for the approximation of a function, is to interpolate it using a list of known samples and the &lt;a target="_blank" href="http://en.wikipedia.org/wiki/Spline_(mathematics)"&gt;Spline algorithm&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;A possible application of this algorithm comes from the world of environmental hazard analysis. Let’s have a look at the &lt;em&gt;“scaled distance/overpressure“&lt;/em&gt; diagram, relating to the explosion of a given mass of &lt;a target="_blank" href="http://en.wikipedia.org/wiki/Trinitrotoluene"&gt;TNT&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/bd455911b481_130DA/overpressure_2.jpg"&gt;&lt;img id="id" style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height="359" alt="overpressure" width="270" align="left" border="0" src="http://geekswithblogs.net/images/geekswithblogs_net/JuanDoNeblo/WindowsLiveWriter/bd455911b481_130DA/overpressure_thumb.jpg" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Using this diagram, we can estimate, given a mass of TNT, what kind of damage will be caused by its detonation. That is, given a scaled distance (function of the mass of exploding TNT and the distance of the considered point from the origin of the explosion), we can evaluate the corresponding overpressure, which can be easily translated to an extent of caused damage.&lt;/p&gt;
&lt;p&gt;This diagram is often used in hazard analysis to predict the explosive effects of a given chemical agent, based on the “well-known” effects of an equivalent quantity of TNT. In fact, it is always possible to trace back a given quantity of an explosive to an equivalent mass of TNT.&lt;/p&gt;
&lt;p&gt;But we are digressing ;) Let's get back on topic!&lt;/p&gt;
&lt;p&gt;With a great deal of patience we're able to extract a limited quantity of significant points from the diagram; these points can be close to a requested “Z”, but "close" isn’t nearly enough to assure a reliable result for any requested “Z”. We need to interpolate.&lt;/p&gt;
&lt;p&gt;Many interpolation algorithms exist, but most of them introduce huge errors, often causing terrible results. &lt;/p&gt;
&lt;p&gt;For example, &lt;a target="_blank" href="http://www.wam.umd.edu/~petersd/interp.html"&gt;here&lt;/a&gt; you can see that a polynomial interpolation is ineffective, as it completely changes the curve's shape according to what samples are considered. The Spline, on the other hand, is able to determine an approximating curve, that avoids sharp shifts between two known values.&lt;/p&gt;
&lt;p&gt;To apply this algorithm I adapted &lt;a target="_blank" href="http://www.codeproject.com/useritems/SplineInterpolation.asp"&gt;Marco Roello’s implementation&lt;/a&gt; of a C# spline interpolator to my needs. &lt;/p&gt;
&lt;p&gt;Here's the resulting code:&lt;/p&gt;
&lt;div style="FONT-SIZE: 9pt; BACKGROUND: #eee; COLOR: black; FONT-FAMILY: consolas, courier new, courier"&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;double&lt;/span&gt; SpLine(&lt;span style="COLOR: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;KeyValuePair&lt;/span&gt;&amp;lt;&lt;span style="COLOR: blue"&gt;double&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;double&lt;/span&gt;&amp;gt;&amp;gt; knownSamples, &lt;span style="COLOR: blue"&gt;double&lt;/span&gt; z)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;{&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; np = knownSamples.Count;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (np &amp;gt; 1)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;double&lt;/span&gt;[] a = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: blue"&gt;double&lt;/span&gt;[np];&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;double&lt;/span&gt; x1;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;double&lt;/span&gt; x2;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;double&lt;/span&gt; y;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;double&lt;/span&gt;[] h = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: blue"&gt;double&lt;/span&gt;[np];&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;for&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; i = 1; i &amp;lt;= np - 1; i++)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            h[i] = knownSamples[i].Key - knownSamples[i - 1].Key;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (np &amp;gt; 2)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: blue"&gt;double&lt;/span&gt;[] sub = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: blue"&gt;double&lt;/span&gt;[np - 1];&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: blue"&gt;double&lt;/span&gt;[] diag = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: blue"&gt;double&lt;/span&gt;[np - 1];&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: blue"&gt;double&lt;/span&gt;[] sup = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: blue"&gt;double&lt;/span&gt;[np - 1];&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: blue"&gt;for&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; i = 1; i &amp;lt;= np - 2; i++)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                diag[i] = (h[i] + h[i + 1]) / 3;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                sup[i] = h[i + 1] / 6;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                sub[i] = h[i] / 6;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                a[i] = (knownSamples[i + 1].Value - knownSamples[i].Value) / h[i + 1] - &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                       (knownSamples[i].Value - knownSamples[i - 1].Value) / h[i];&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: green"&gt;// SolveTridiag is a support function, see Marco Roello's original code&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: green"&gt;// for more information at &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: green"&gt;// http://www.codeproject.com/useritems/SplineInterpolation.asp&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            SolveTridiag(sub, diag, sup, &lt;span style="COLOR: blue"&gt;ref&lt;/span&gt; a, np - 2);&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; gap = 0;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;double&lt;/span&gt; previous = 0.0;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: green"&gt;// At the end of this iteration, "gap" will contain the index of the interval &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: green"&gt;// between two known values, which contains the unknown z, and "previous" will &lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: green"&gt;// contain the biggest z value among the known samples, left of the unknown z&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;for&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;int&lt;/span&gt; i = 0; i &amp;lt; knownSamples.Count; i++)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (knownSamples[i].Key &amp;lt; z &amp;amp;&amp;amp; knownSamples[i].Key &amp;gt; previous)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                previous = knownSamples[i].Key;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                gap = i + 1;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        x1 = z - previous;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        x2 = h[gap] - x1;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        y = ((-a[gap - 1] / 6 * (x2 + h[gap]) * x1 + knownSamples[gap - 1].Value) * x2 + &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            (-a[gap] / 6 * (x1 + h[gap]) * x2 + knownSamples[gap].Value) * x1) / h[gap];&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; y;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; 0;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;}&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; SolveTridiag(&lt;span style="COLOR: blue"&gt;double&lt;/span&gt;[] sub, &lt;span style="COLOR: blue"&gt;double&lt;/span&gt;[] diag, &lt;span style="COLOR: blue"&gt;double&lt;/span&gt;[] sup, &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                                 &lt;span style="COLOR: blue"&gt;ref&lt;/span&gt; &lt;span style="COLOR: blue"&gt;double&lt;/span&gt;[] b, &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; n)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;{&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    .....&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;The &lt;font face="consolas, courier new, courier"&gt;SpLine()&lt;/font&gt; method receives two parameters: a &lt;font face="consolas, courier new, courier"&gt;&lt;span style="COLOR: rgb(43,145,175)"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="COLOR: rgb(43,145,175)"&gt;KeyValuePair&lt;/span&gt;&amp;lt;&lt;span style="COLOR: rgb(0,0,255)"&gt;double&lt;/span&gt;, &lt;span style="COLOR: rgb(0,0,255)"&gt;double&lt;/span&gt;&amp;gt;&amp;gt;&lt;/font&gt; containing a list of known samples, and a &lt;span style="COLOR: rgb(0,0,255)"&gt;double&lt;/span&gt;, containing the unknown value of for which we want to compute the function image.&lt;/p&gt;
&lt;p&gt;In our case, we need to pass a list of known samples manually extracted from the diagram as first argument, and the given value of "Z" (on the X-axis) for which we want to compute the overpressure (on the Y-axis).&lt;/p&gt;
&lt;p&gt;The list of known samples might be hard-coded, read from a database, or anything else. In our implementation, we decided to use an XML file to achieve the maximum flexibility and scalability. Modifying or inserting samples couldn't be easier than editing an XML file.&lt;/p&gt;
&lt;p&gt;So here's an example of what our XML might look like:&lt;/p&gt;
&lt;div style="FONT-SIZE: 9pt; BACKGROUND: #eee; COLOR: black; FONT-FAMILY: consolas, courier new, courier"&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;xml&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;version&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;1.0&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;encoding&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;utf-8&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; ?&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;tnt&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;  &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;overPressure&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sample&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;id&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;1&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;2&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;y&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;3&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sample&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;id&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;2&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;3&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;y&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;2&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sample&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;id&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;3&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;4&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;y&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;0.7&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sample&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;id&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;4&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;5&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;y&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;0.49&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sample&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;id&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;5&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;6&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;y&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;0.45&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sample&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;id&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;6&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;7&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;y&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;0.28&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sample&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;id&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;7&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;8&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;y&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;0.22&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sample&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;id&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;8&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;9&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;y&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;0.18&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sample&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;id&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;9&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;10&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;y&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;0.16&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sample&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;id&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;10&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;20&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;y&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;0.06&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sample&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;id&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;11&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;30&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;y&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;0.045&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sample&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;id&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;12&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;40&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;y&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;0.023&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sample&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;id&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;13&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;50&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;y&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;0.017&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sample&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;id&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;14&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;60&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;y&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;0.015&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sample&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;id&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;15&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;x&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;70&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;y&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;0.013&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;  &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;overPressure&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;  &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;otherFunction1&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;    .... more samples ....&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;  &lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;otherFunction1&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;tnt&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;This file can be easily read using the .NET Xml classes. We chose to use the XmlReader because we only need a fast sequential forward-only view of our XML file.&lt;/p&gt;
&lt;p&gt;So here's a simple XML reader that scans our file and returns its content as an ordered List of &lt;span style="COLOR: rgb(43,145,175)"&gt;&lt;font face="consolas, courier new, courier"&gt;KeyValuePair&lt;/font&gt;&lt;/span&gt;s which we can directly feed to the SpLine() method. The ReadValues() method takes the root name as an argument, so that we can put different sample lists (for different functions) in a file.&lt;/p&gt;
&lt;div style="FONT-SIZE: 9pt; BACKGROUND: #eee; COLOR: black; FONT-FAMILY: consolas, courier new, courier"&gt;
&lt;p style="MARGIN: 0px"&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;KeyValuePair&lt;/span&gt;&amp;lt;&lt;span style="COLOR: blue"&gt;double&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;double&lt;/span&gt;&amp;gt;&amp;gt; ReadValues(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; xmlUri, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; rootName)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;{&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    &lt;span style="COLOR: #2b91af"&gt;XmlReaderSettings&lt;/span&gt; settings = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;XmlReaderSettings&lt;/span&gt;();&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    settings.IgnoreWhitespace = &lt;span style="COLOR: blue"&gt;true&lt;/span&gt;;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    &lt;span style="COLOR: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;KeyValuePair&lt;/span&gt;&amp;lt;&lt;span style="COLOR: blue"&gt;double&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;double&lt;/span&gt;&amp;gt;&amp;gt; dic = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;KeyValuePair&lt;/span&gt;&amp;lt;&lt;span style="COLOR: blue"&gt;double&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;double&lt;/span&gt;&amp;gt;&amp;gt;();&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;using&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;XmlReader&lt;/span&gt; reader = &lt;span style="COLOR: #2b91af"&gt;XmlReader&lt;/span&gt;.Create(xmlUri, settings))&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        &lt;span style="COLOR: blue"&gt;while&lt;/span&gt; (reader.Read())&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (reader.Name == rootName)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                reader.ReadToDescendant(&lt;span style="COLOR: #a31515"&gt;"sample"&lt;/span&gt;);&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                &lt;span style="COLOR: blue"&gt;while&lt;/span&gt; (reader.Name == &lt;span style="COLOR: #a31515"&gt;"sample"&lt;/span&gt;)&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                {&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                    &lt;span style="COLOR: blue"&gt;double&lt;/span&gt; key = &lt;span style="COLOR: #2b91af"&gt;Convert&lt;/span&gt;.ToDouble(reader.GetAttribute(&lt;span style="COLOR: #a31515"&gt;"x"&lt;/span&gt;), &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                                                  &lt;span style="COLOR: #2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture);&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                    &lt;span style="COLOR: blue"&gt;double&lt;/span&gt; value = &lt;span style="COLOR: #2b91af"&gt;Convert&lt;/span&gt;.ToDouble(reader.GetAttribute(&lt;span style="COLOR: #a31515"&gt;"y"&lt;/span&gt;), &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                                                  &lt;span style="COLOR: #2b91af"&gt;CultureInfo&lt;/span&gt;.InvariantCulture);&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                    dic.Add(&lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;KeyValuePair&lt;/span&gt;&amp;lt;&lt;span style="COLOR: blue"&gt;double&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;double&lt;/span&gt;&amp;gt;(key, value));&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                    reader.Read();&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;                &lt;span style="COLOR: blue"&gt;break&lt;/span&gt;;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;            }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;        reader.Close();&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    }&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;    &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; dic;&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;}&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;Using this method we will be able to obtain an acceptable interpolation with small error and small computational effort.&lt;/p&gt;
&lt;h5 style="COLOR: rgb(180,200,53)"&gt;Serena&lt;/h5&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ba153885-c74d-43b8-92ae-96830e2ece39" style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; FLOAT: none; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"&gt;Technorati Tag: &lt;a rel="tag" href="http://technorati.com/tags/C#/"&gt;C#&lt;/a&gt; , &lt;a rel="tag" href="http://technorati.com/tags/mathematical%20models/"&gt;mathematical models&lt;/a&gt; , &lt;a rel="tag" href="http://technorati.com/tags/spline/"&gt;spline&lt;/a&gt; , &lt;a rel="tag" href="http://technorati.com/tags/interpolation/"&gt;interpolation&lt;/a&gt; , &lt;a rel="tag" href="http://technorati.com/tags/hazard%20prediction/"&gt;hazard prediction&lt;/a&gt; , &lt;a rel="tag" href="http://technorati.com/tags/environmental%20hazard/"&gt;environmental hazard&lt;/a&gt; , &lt;a rel="tag" href="http://technorati.com/tags/tnt/"&gt;tnt&lt;/a&gt; &lt;/div&gt;
&lt;br /&gt;
&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fgeekswithblogs.net%2fJuanDoNeblo%2farchive%2f2007%2f10%2f25%2fData-Interpolation-with-SPLINE-in-Csharp.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" border="0" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fgeekswithblogs.net%2fJuanDoNeblo%2farchive%2f2007%2f10%2f25%2fData-Interpolation-with-SPLINE-in-Csharp.aspx" /&gt; &lt;/a&gt;&lt;a href="http://digg.com/submit?phase=2&amp;amp;url=http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/25/Data-Interpolation-with-SPLINE-in-Csharp.aspx&amp;amp;title=Data%20Interpolation%20with%20SPLINE%20in%20C%23&amp;amp;topic=programming&amp;amp;bodytext=A%20simple%20and%20fast%20solution%20for%20the%20approximation%20of%20a%20function%2C%20interpolating%20it%20using%20a%20list%20of%20known%20samples%20and%20the%20Spline%20algorithm."&gt;&lt;img height="16" alt="Digg!" width="16" src="http://digg.com/img/badges/16x16-digg-guy.gif" /&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=116330"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=116330" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/JuanDoNeblo/aggbug/116330.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Marco Anastasi &amp; Serena Caruso</dc:creator>
            <guid>http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/25/Data-Interpolation-with-SPLINE-in-Csharp.aspx</guid>
            <pubDate>Fri, 26 Oct 2007 02:07:15 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/JuanDoNeblo/comments/116330.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/25/Data-Interpolation-with-SPLINE-in-Csharp.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/JuanDoNeblo/comments/commentRss/116330.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/JuanDoNeblo/services/trackbacks/116330.aspx</trackback:ping>
        </item>
        <item>
            <title>JSON in ASP.NET Ajax: Part 2. Calling a remote JSON Web Service from client script</title>
            <link>http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/24/json_in_aspnetajax_part2.aspx</link>
            <description>&lt;p&gt;Now, after the very futile example which accompanied the introduction to JavaScript Object Notation in my last post (by the way, I forgot to mention that this is what the fancy acronym stands for, but I'm sure you already knew that), let's go straight to the fun part, and see how we can leverage the flexibility of JSON (and ASP.NET AJAX, of course) to achieve some less trivial result. When developing a web application, we often need to aggregate data from different sources. You might argue this is no big news, as we've all used web services in a way or the other, and "mashup" is surely not an uncommon word these days. But probably, for most of us, the natural way to think of data returned from a web service call is XML. But XML is not exactly the easiest thing to parse on the client, nor a very succinct format. That's why a number of JSON web services have flourished lately. Probably the first that comes to mind is Google Maps' Geocoder (see &lt;a href="http://www.google.com/apis/maps/documentation/services.html#Geocoding" target="_blank"&gt;here&lt;/a&gt;), but there are a lot more. If you are looking for inspiration you can have a look at &lt;a href="http://www.xmethods.com/ve2/index.po" target="_blank"&gt;xmethods&lt;/a&gt;. But today, we are focusing on some very, very interesting web methods kindly offered by &lt;a href="http://www.geonames.org/export/JSON-webservices.html" target="_blank"&gt;Geonames&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;In fact, as I've always mantained that an example is worth a googolplex words, in this post I'm going to describe a specific problem I had to solve recently, and the rather simple solution I found, using JSON and ASP.NET AJAX.    &lt;br /&gt;So, let's get this started: enter&lt;/p&gt;  &lt;h5&gt;The Problem.&lt;/h5&gt;  &lt;p&gt;Let's imagine we want to retrieve the most recent weather information for a specific location, given its geographic coordinates. In particular, let's imagine that we let the user input the coordinates directly on the client (for example by clicking on a Virtual Earth map) and we want to visualize the latest weather data observed at the nearest weather station, avoiding the user the annoyance of the much dreaded postback.&lt;/p&gt;  &lt;h5&gt;The Solution.&lt;/h5&gt;  &lt;p&gt;Luckily, the &lt;em&gt;findNearByWeatherJSON &lt;/em&gt;web service at &lt;a href="http://www.geonames.org/export/JSON-webservices.html" target="_blank"&gt;Geonames&lt;/a&gt; does exactly what we need. It takes a longitude and latitude as parameters, and returns a JSON object describing the weather conditions gathered at the nearest observing site.&lt;/p&gt;  &lt;p&gt;Although you could directly call this service from the client using classic AJAX patterns (see &lt;a href="http://www.geonames.org/export/ajax-postalcode-autocomplete.html" target="_blank"&gt;here&lt;/a&gt; for a simple example or  have a look at &lt;a href="http://ajaxpatterns.org" target="_blank"&gt;ajaxpatterns&lt;/a&gt;), we'll focus on how to do that by using a proxy ASP.NET web service to avoid security problems and allow for more flexibility, and, as a nice bonus, have more readable and maintainable code. In fact, rather than following a RESTful approach, and call the web service directly from javascript, we'll leverage the ASP.NET AJAX infrastructure and use the more concise and readable RPC-style generated for us by the framework.&lt;/p&gt;  &lt;p&gt;But the question is: how? When faced with the necessity to create a server-side proxy for a remote JSON service, one might be tempted to try and find something like the "Add Web Reference" wizard Visual Studio has been spoiling us with for years... well, no luck this time, there's nothing like that for JSON. In fact, while the wizard would help us if we had to consume a SOAP web service, there's nothing like WSDL which can describe the results and help generate a proxy class for JSON services.&lt;/p&gt;  &lt;p&gt;But the good news is, we don't need any! In fact, unless you want to elaborate in some way the results returned from the web service (and I'll cover that topic in one of my next posts), all you need to do is create a simple local ASP.NET web service whose only duty, when called, is to make a request to the remote web service and forward the result to the client. So, let's see how to implement all this!&lt;/p&gt;  &lt;p&gt;First of all, let's see how to implement the ASP.NET proxy web service:&lt;/p&gt;  &lt;div style="font-size: 9pt; background: rgb(238,238,238) 0% 50%; color: black; font-family: consolas, courier new, courier; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; System;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; System.Web.Script.Services;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; System.Web.Services;&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;namespace&lt;/span&gt; Mashup&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    &lt;span style="color: green"&gt;/* To allow this Web Service to be called from script using ASP.NET AJAX,  &lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: green"&gt;    * we need to set the following attribute. */&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    [&lt;span style="color: rgb(43,145,175)"&gt;ScriptService&lt;/span&gt;]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    [&lt;span style="color: rgb(43,145,175)"&gt;WebService&lt;/span&gt;(Namespace = &lt;span style="color: rgb(163,21,21)"&gt;"Mashup"&lt;/span&gt;)]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    [&lt;span style="color: rgb(43,145,175)"&gt;WebServiceBinding&lt;/span&gt;(ConformsTo = &lt;span style="color: rgb(43,145,175)"&gt;WsiProfiles&lt;/span&gt;.BasicProfile1_1)]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;WeatherService&lt;/span&gt; : &lt;span style="color: rgb(43,145,175)"&gt;WebService&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        [&lt;span style="color: rgb(43,145,175)"&gt;WebMethod&lt;/span&gt;]&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; GetWeatherByLocation(&lt;span style="color: blue"&gt;double&lt;/span&gt; lat, &lt;span style="color: blue"&gt;double&lt;/span&gt; lng)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;return&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;GeonamesWeather&lt;/span&gt;.GetWeatherByLocation(lat, lng);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;You can see that the web service we're publishing takes two parameters, latitude and langitude of a location, and returns a string. We'll see that this string is going to contain exactly the content of the response received from the Geonames Web Service. What we have to notice now, is that we decorated the WeatherService class with the &lt;strong&gt;[ScriptService]&lt;/strong&gt; attribute. This is all we have to do to instruct the ASP.NET engine to create a Javascript helper class that will let us call this method very easily from client code.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;NOTE: If you want to have a look at what the generated Javascript proxy class looks like, all you have to do is requesting the .asmx web service from your browser, and append /js to the url. (e.g. http://localhost:2687/JsonTest/WeatherService.asmx/js)&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Now, let's delve deeper into the implementation of the &lt;em&gt;GetWeatherByLocation()&lt;/em&gt; method:&lt;/p&gt;  &lt;div style="font-size: 9pt; background: rgb(238,238,238) 0% 50%; color: black; font-family: consolas, courier new, courier; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; System;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; System.Net;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; System.Globalization;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;using&lt;/span&gt; System.IO;&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;namespace&lt;/span&gt; Mashup&lt;/p&gt;    &lt;p style="margin: 0px"&gt;{&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;class&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;GeonamesWeather&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;readonly&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; FindNearbyWeatherUrl =&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: rgb(163,21,21)"&gt;"http://ws.geonames.org/findNearByWeatherJSON?lat={0}&amp;amp;lng={1}"&lt;/span&gt;;&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;public&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: blue"&gt;string&lt;/span&gt; GetWeatherByLocation(&lt;span style="color: blue"&gt;double&lt;/span&gt; lat, &lt;span style="color: blue"&gt;double&lt;/span&gt; lng)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;string&lt;/span&gt; formattedUri = &lt;span style="color: rgb(43,145,175)"&gt;String&lt;/span&gt;.Format(&lt;span style="color: rgb(43,145,175)"&gt;CultureInfo&lt;/span&gt;.InvariantCulture, &lt;/p&gt;    &lt;p style="margin: 0px"&gt;                                  FindNearbyWeatherUrl, lat, lng);&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: rgb(43,145,175)"&gt;HttpWebRequest&lt;/span&gt; webRequest = GetWebRequest(formattedUri);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: rgb(43,145,175)"&gt;HttpWebResponse&lt;/span&gt; response = (&lt;span style="color: rgb(43,145,175)"&gt;HttpWebResponse&lt;/span&gt;)webRequest.GetResponse();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;string&lt;/span&gt; jsonResponse = &lt;span style="color: blue"&gt;string&lt;/span&gt;.Empty;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;using&lt;/span&gt; (&lt;span style="color: rgb(43,145,175)"&gt;StreamReader&lt;/span&gt; sr = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;StreamReader&lt;/span&gt;(response.GetResponseStream()))&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;                jsonResponse = sr.ReadToEnd();&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;return&lt;/span&gt; jsonResponse;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        }&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;        &lt;span style="color: blue"&gt;private&lt;/span&gt; &lt;span style="color: blue"&gt;static&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;HttpWebRequest&lt;/span&gt; GetWebRequest(&lt;span style="color: blue"&gt;string&lt;/span&gt; formattedUri)&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        {&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: green"&gt;// Create the request’s URI.&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: rgb(43,145,175)"&gt;Uri&lt;/span&gt; serviceUri = &lt;span style="color: blue"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43,145,175)"&gt;Uri&lt;/span&gt;(formattedUri, &lt;span style="color: rgb(43,145,175)"&gt;UriKind&lt;/span&gt;.Absolute);&lt;/p&gt;    &lt;p style="margin: 0px"&gt; &lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: green"&gt;// Return the HttpWebRequest.&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;            &lt;span style="color: blue"&gt;return&lt;/span&gt; (&lt;span style="color: rgb(43,145,175)"&gt;HttpWebRequest&lt;/span&gt;)System.Net.&lt;span style="color: rgb(43,145,175)"&gt;WebRequest&lt;/span&gt;.Create(serviceUri);&lt;/p&gt;    &lt;p style="margin: 0px"&gt;        }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;    }&lt;/p&gt;    &lt;p style="margin: 0px"&gt;}&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;As you can see, what the &lt;em&gt;GetWeatherByLocation()&lt;/em&gt; method does is simply act as a proxy. We call the remote web service in a RESTful manner, retrieve the response, write it into a string and finally return the string to the caller method. The response returned from the &lt;em&gt;findNearByWeatherJSON &lt;/em&gt;service will be something like this:&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div style="font-size: 9pt; background: #eee; color: black; font-family: consolas, courier new, courier"&gt;   &lt;p style="margin: 0px"&gt;"{"weatherObservation":{ &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    "clouds":"few clouds", &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    "weatherCondition":"n/a", &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    "observation":"LICC 231720Z 29009KT 9999 FEW035 SCT070 16/07 Q1009", &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    "windDirection":290, &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    "ICAO":"LICC", &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    "elevation":17, &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    "countryCode":"IT", &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    "lng":15.05, &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    "temperature":"16", &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    "dewPoint":"7", &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    "windSpeed":"09", &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    "humidity":55, &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    "stationName":"Catania / Fontanarossa", &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    "datetime":"2007-10-23 17:20:00", &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    "lat":37.4666666666667, &lt;/p&gt;    &lt;p style="margin: 0px"&gt;    "hectoPascAltimeter":1009 }}"&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;NOTE: Carriage returns have been inserted only to improve readability, but the response stream won't contain any.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The similarity between this string and a Javascript object is quite evident. We'll see in a moment how to leverage this - not so coincidental - fact.&lt;/p&gt;  &lt;p&gt;Now, our server infrastructure is almost complete. The last step we have to take is referencing the Web Service we just created from the page that is actually going to use it.&lt;/p&gt;  &lt;p&gt;To do this, we simply add a ScriptManager to the page, and add a reference to the web service in its &amp;lt;Services&amp;gt; section:&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div style="font-size: 9pt; background: #eee; color: black; font-family: consolas, courier new, courier"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp:ScriptManager&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;ID&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;ScriptManager1&lt;/span&gt;"&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;server&lt;/span&gt;"&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;Services&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp:ServiceReference&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;~/WeatherService.asmx&lt;/span&gt;"&lt;span style="color: blue"&gt; /&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;Services&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp:ScriptManager&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Now we can start to set up a very simple test page to try our flaming new web service!&lt;/p&gt;  &lt;p&gt;For now, we'll only add a couple of textboxes to input latitude and longitude, and a button to start the Web Request. We'll do it AJAX style, so we'll use the HTML controls rather than their heavier ASP.NET counterparts. We'll also add a div where we're going to visualize the weather info retrieved from the web service. Note that we are giving id's to all the controls so that we can reference them from the Javascript code that we are going to write.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;div style="font-size: 9pt; background: #eee; color: black; font-family: consolas, courier new, courier"&gt;   &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;label&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;for&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;txtLat&lt;/span&gt;"&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Latitude:&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;label&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;input&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;text&lt;/span&gt;"&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;txtLat&lt;/span&gt;"&lt;span style="color: blue"&gt; /&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;label&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;for&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;txtLng&lt;/span&gt;"&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;Longitude:&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;label&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;input&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;text&lt;/span&gt;"&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;txtLng&lt;/span&gt;"&lt;span style="color: blue"&gt; /&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;input&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;button&lt;/span&gt;"&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;Get Weather Info&lt;/span&gt;"&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;onclick&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;callService();&lt;/span&gt;"&lt;span style="color: blue"&gt; /&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;id&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;divResult&lt;/span&gt;"&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;div&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt; &lt;/div&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Now all that's left to do is write the Javascript code to wire up everything. &lt;/p&gt;  &lt;p&gt;We'll start by implementing the &lt;em&gt;callService() &lt;/em&gt;function that will be fired when clicking on the button. Please note that in a real scenario, clicking the button would trigger some sort of validation of the input data. We won't do any of that here in order to keep the code as simple and streamlined as possible.&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;function&lt;/span&gt; callService() { &lt;/pre&gt;

&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;var&lt;/span&gt; latitude = $get(&lt;span style="color: rgb(163,21,21)"&gt;'txtLat'&lt;/span&gt;).value; &lt;/pre&gt;

&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;var&lt;/span&gt; longitude = $get(&lt;span style="color: rgb(163,21,21)"&gt;'txtLng'&lt;/span&gt;).value; &lt;/pre&gt;

&lt;pre class="code"&gt;    Mashup.WeatherService.GetWeatherByLocation(latitude, longitude,&lt;/pre&gt;

&lt;pre class="code"&gt;    GetWeather_success, onFailed); &lt;/pre&gt;

&lt;pre class="code"&gt;}&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Let's see what we are doing here. First of all we are creating two variables, latitude and longitude, which contain the value of the two textboxes. &lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;NOTE: Those of you who haven't put their hands on the client side ASP.NET AJAX library yet, might wonder what the $get function does. Actually, not much, except sparing you some keystrokes, as it is a mere shortcut for the Javascript &lt;strong&gt;getElementById&lt;/strong&gt; function. In particular, when called passing only one parameter, the $get alias resolves to &lt;strong&gt;document.getElementById&lt;/strong&gt;, while when called like this: &lt;strong&gt;$get(id, element)&lt;/strong&gt;, it resolves to &lt;strong&gt;element.getElementById(id)&lt;/strong&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After that, we're finally ready to call our proxy service. We do that by calling the Javascript proxy method generated for us care of the ASP.NET AJAX framework. As you can see, we can find our &lt;em&gt;WeatherService.GetWeatherByLocation()&lt;/em&gt; method inside the &lt;em&gt;Mashup&lt;/em&gt; namespace. Please note we have to use the fully qualified name to invoke the service.&lt;/p&gt;

&lt;p&gt;Besides the two parameters defined in the web method signature in the server side code, we see that the generated Javascript method takes some additional parameters: &lt;em&gt;onSuccess&lt;/em&gt;, &lt;em&gt;onFailed&lt;/em&gt; and &lt;em&gt;userContext.&lt;/em&gt; As you have probably already realised, they take the name of two callbacks, one that will be executed upon successful completion of the remote method invocation, the other that will be called in the unfortunate event something went wrong. The third parameter, which we are not using here, would let you pass a custom user context to the callback.&lt;/p&gt;

&lt;p&gt;Now, if everything works as expected, the GetWeather_success function will be called (asynchronously) when the web service response is ready, and will get as an argument the web method's return value, in our case, a string containing our JSON-serialized weather observation object.&lt;/p&gt;

&lt;p&gt;Now the very last thing we need to do is deserialize such string into a real Javascript object. To do that, we might simply call the Javascript &lt;em&gt;eval()&lt;/em&gt; function, as I anticipated in my previous post:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;function&lt;/span&gt; GetWeather_success(e) { &lt;/pre&gt;

&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;var&lt;/span&gt; result = eval(&lt;span style="color: rgb(163,21,21)"&gt;'('&lt;/span&gt; + e + &lt;span style="color: rgb(163,21,21)"&gt;')'&lt;/span&gt;); &lt;/pre&gt;

&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;var&lt;/span&gt; weatherData = &lt;span style="color: rgb(0,0,255)"&gt;new&lt;/span&gt; Sys.StringBuilder(); &lt;/pre&gt;

&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;var&lt;/span&gt; line; &lt;/pre&gt;

&lt;pre class="code"&gt;    &lt;span style="color: rgb(0,0,255)"&gt;for&lt;/span&gt;(&lt;span style="color: rgb(0,0,255)"&gt;var&lt;/span&gt; property &lt;span style="color: rgb(0,0,255)"&gt;in&lt;/span&gt; result.weatherObservation) &lt;/pre&gt;

&lt;pre class="code"&gt;    { &lt;/pre&gt;

&lt;pre class="code"&gt;        line = String.format(&lt;span style="color: rgb(163,21,21)"&gt;"&amp;lt;b&amp;gt;{0}:&amp;lt;/b&amp;gt; {1}&amp;lt;br/&amp;gt;"&lt;/span&gt;, property, &lt;/pre&gt;

&lt;pre class="code"&gt;        result.weatherObservation[property]); weatherData.append(line); &lt;/pre&gt;

&lt;pre class="code"&gt;    } &lt;/pre&gt;

&lt;pre class="code"&gt;    $get(&lt;span style="color: rgb(163,21,21)"&gt;'divResult'&lt;/span&gt;).innerHTML = weatherData.toString(); &lt;/pre&gt;

&lt;pre class="code"&gt;}&lt;/pre&gt;

&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;function&lt;/span&gt; onFailed() { &lt;/pre&gt;

&lt;pre class="code"&gt;    $get(&lt;span style="color: rgb(163,21,21)"&gt;'divResult'&lt;/span&gt;).innerHTML = &lt;span style="color: rgb(163,21,21)"&gt;'Something went terribly wrong!'&lt;/span&gt;; &lt;/pre&gt;

&lt;pre class="code"&gt;}&lt;/pre&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;As I just said, when this function is called, it is passed the web method response, thus &lt;em&gt;e&lt;/em&gt; contains the JSON representation of a Javascript object containing all the relevant weather data retrieved from our remote Web Service. As you can see, calling &lt;em&gt;eval()&lt;/em&gt; deserializes the string and returns an object we can readily use.&lt;/p&gt;

&lt;p&gt;From now on, what we are going to do with this native Javascript object is entirely up to us. Here, as a mere example, I'm enumerating all its properties and displaying them inside the div we created for this purpose.&lt;/p&gt;

&lt;p&gt;What's worth noting here is the use of two very interesting and useful ASP.NET AJAX features: the &lt;strong&gt;Sys.StringBuilder &lt;/strong&gt;class that mimics its server-side homonym and greatly improves string concatenation performance over the "+" overload, and the &lt;strong&gt;String.format() &lt;/strong&gt;function, which endows Javascript with the very useful .NET &lt;em&gt;String.Format()&lt;/em&gt; method we are all used to.&lt;/p&gt;

&lt;p&gt;For those of you concerned with security, as I said earlier, &lt;em&gt;eval()&lt;/em&gt; is probably not the safest option to deserialize JSON, so you might decide to resort to a JSON parser (you can find one &lt;a href="http://www.json.org/js.html" target="_blank"&gt;here&lt;/a&gt; on &lt;a href="http://www.json.org" target="_blank"&gt;json.org&lt;/a&gt;), or once again leverage the power of ASP.NET AJAX, by using the built-in &lt;em&gt;JavaScriptSerializer.&lt;/em&gt; If you simply substitute the first line in &lt;em&gt;GetWeather_success()&lt;/em&gt; with the following line:&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: rgb(0,0,255)"&gt;var&lt;/span&gt; result = Sys.Serialization.JavaScriptSerializer.deserialize(e, &lt;span style="color: rgb(0,0,255)"&gt;true&lt;/span&gt;);&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;the string returned from the web method will be checked against a regular expression to ensure it is actually a valid JSON string.&lt;/p&gt;

&lt;p&gt;Well, that's all for now! I hope that this short introduction to the use of JSON with ASP.NET has been useful to some of you!&lt;/p&gt;

&lt;h5&gt;You can &lt;a href="http://www.prestifin.biz/JuanDoNeblo/JsonWeather/JsonWeather.aspx" target="_blank"&gt;see a live Demo here&lt;/a&gt; or &lt;a href="http://www.prestifin.biz/JuanDoNeblo/JsonWeather/JsonWeather.zip" target="_blank"&gt;download the Source Code&lt;/a&gt; of this project &lt;a href="http://www.prestifin.biz/JuanDoNeblo/JsonWeather/JsonWeather.zip" target="_blank"&gt;here&lt;/a&gt;.&lt;/h5&gt;

&lt;p&gt;You can find the &lt;a href="http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/31/json_in_aspnetajax_part3.aspx"&gt;third&lt;/a&gt; and last part of this article &lt;a href="http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/31/json_in_aspnetajax_part3.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;

&lt;h5 style="color: rgb(180,200,53)"&gt;Marco&lt;/h5&gt;

&lt;p style="color: rgb(180,200,53)"&gt; &lt;/p&gt;

&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:c7e44600-ec2b-4a4c-a741-507e3d2abe5e" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tag: &lt;a href="http://technorati.com/tags/JSON/" rel="tag"&gt;JSON&lt;/a&gt; , &lt;a href="http://technorati.com/tags/ASP.NET/" rel="tag"&gt;ASP.NET&lt;/a&gt; , &lt;a href="http://technorati.com/tags/AJAX/" rel="tag"&gt;AJAX&lt;/a&gt; , &lt;a href="http://technorati.com/tags/Javascript/" rel="tag"&gt;Javascript&lt;/a&gt; , &lt;a href="http://technorati.com/tags/Web%20Service/" rel="tag"&gt;Web Service&lt;/a&gt; &lt;/div&gt;

&lt;p&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fgeekswithblogs.net%2fJuanDoNeblo%2farchive%2f2007%2f10%2f24%2fjson_in_aspnetajax_part2.aspx"&gt;&lt;img alt="kick it on DotNetKicks.com" src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fgeekswithblogs.net%2fJuanDoNeblo%2farchive%2f2007%2f10%2f24%2fjson_in_aspnetajax_part2.aspx" border="0" /&gt;&lt;/a&gt; &lt;a href="http://digg.com/submit?phase=2&amp;amp;url=http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/24/json_in_aspnetajax_part2.aspx&amp;amp;title=JSON%20in%20ASP.NET%20Ajax%3A%20Part%202.%20Calling%20a%20remote%20JSON%20Web%20Service%20from%20client%20script&amp;amp;topic=programming&amp;amp;bodytext=In%20this%20follow-up%20we%27ll%20build%20upon%20what%20we%20learned%20in%20the%20previous%20article%2C%20and%20write%20a%20simple%20AJAX%20application%20that%20calls%20a%20JSON%20Web%20Service%20asynchronously%20and%20displays%20the%20result%20with%20a%20callback.%20We%27ll%20leverage%20the%20ASP.NET%20AJAX%20client%20library%20to%20avoid%20writing%20all%20the%20needed%20%22plumbing%22%20code%20and%20we%27ll%20see%20how%20to%20bridge%20a%20remote%20web%20service%20using%20a%20local%20proxy."&gt;&lt;img height="16" alt="Digg!" src="http://digg.com/img/badges/16x16-digg-guy.gif" width="16" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=116273"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=116273" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/JuanDoNeblo/aggbug/116273.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Marco Anastasi &amp; Serena Caruso</dc:creator>
            <guid>http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/24/json_in_aspnetajax_part2.aspx</guid>
            <pubDate>Wed, 24 Oct 2007 07:00:17 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/JuanDoNeblo/comments/116273.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/JuanDoNeblo/archive/2007/10/24/json_in_aspnetajax_part2.aspx#feedback</comments>
            <slash:comments>9</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/JuanDoNeblo/comments/commentRss/116273.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/JuanDoNeblo/services/trackbacks/116273.aspx</trackback:ping>
        </item>
    </channel>
</rss>