BrainDump
  Home arrow BrainDump arrow Parsing Addresses and More with the MapPoi...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

Parsing Addresses and More with the MapPoint Web Service Find APIs
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-03-06

    Table of Contents:
  • Parsing Addresses and More with the MapPoint Web Service Find APIs
  • AJAX-Enabling Your Web Applications
  • Implementing MapPoint Lookup AJAX Application
  • Optimizing Find Call Performance
  • Applying Proper Metadata for Faster Searches

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    Parsing Addresses and More with the MapPoint Web Service Find APIs
    (Page 1 of 5 )

    In this conclusion to a five-part series on the Find Service, you will learn about parsing addresses, optimizing performance, and more. It is excerpted from chapter six of the book Programming MapPoint in .NET, written by Chandu Thota (O'Reilly; ISBN: 0596009062). Copyright © 2007 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

    Parsing Addresses

    We have seen various capabilities of Find Service to find places, addresses, nearby entities, and points of interest, but what happens if you have an address in an unstructured or unformatted form? What if you want to create an application where your users can type their address in a textbox without worrying about the formatting? How do you parse the address field to understand various parts of the address? You can use the FindServiceSoap.ParseAddress method for these purposes. The ParseAddress method takes two arguments, input address as a string and an optional country/region name, and returns an Addressobject for valid addresses. For example, if you have the address 1 Microsoft Way, Redmond, WA in string format, you can use theParseAddressmethod to parse it into anAddressobject:

      //Create a web service proxy
      FindServiceSoap findService = new FindServiceSoap();
      //Assign credentials
      . . .

      //Parse a string into a valid address object
      Address address =
          
    findService.ParseAddress("1 Microsoft Way, Redmond", "United States");

    One of the greatest advantages of this method is that you can implement one user interface that can perform both find place and find address depending on what users input without having to design two different UIs for two different purposes.

    Asynchronous Programming with Find Service

    When developing applications using Web Service, keep in mind that you are making a network round-trip with every method call, which has serious implications on your application’s performance in terms of responsiveness. For example, since calls over the network take a long time to return, you don’t want to block the UI thread for your Windows application. This is where the asynchronous programming patterns come to the rescue. Using the .NET framework, it is easy to call Web Service methods asynchronously. So, let’s see how you would implement a FindServiceSoap.Find method call asynchronously.

    Asynchronous Programming for Windows Applications

    When you generate the MapPoint Web Service proxy class using Visual Studio .NET, it also generates the necessary methods for asynchronous programming. For example, if you look for the FindServiceSoap.Find method, you also find the FindServiceSoap.BeginFind and FindServiceSoap.EndFind methods in the proxy class. TheBeginandEndmethod pairs enable the asynchronous programming patterns for your web service client applications. Using these methods is really easy; in a synchronous scenario, yourFindcall looks like the following code:

      //Call the Find Method
      FindResults findresults = findsoap.Find(findspec);
      //Now display find results
      DisplayFindResults(findresults);

    If this code is running on the UI thread, it does not get to theDisplayFindResultsmethod until theFindmethod call completes and returns thefindresultsvalue; during this period, users of your application may find it unresponsive. To avoid this situation, create a worker thread and call theFindmethod using it so that your UI thread is free during this long network round-trip. In fact, that’s exactly what theBeginFindandEndFindmethods do behind the scenes. To implement the previous code using asynchronous methods, you would do something similar to the following:

    First, define a callback method for your asynchronous method calls:

      private void FindServiceCallback(IAsyncResult ar)
      {
         FindServiceSoap findSoap
           = ar.AsyncState as FindServiceSoap;
         if(findSoap == null)
          
    return;
        
    FindResults findresults = findSoap.EndFind(ar);
        
    DisplayFindResults(findresults);
      }

    Next, modify your find call to become an asynchronousBeginFindcall:

      //Async call to find
     
    AsyncCallback callback = new AsyncCallback(FindServiceCallback);
      findsoap.BeginFind(findspec, callback, findsoap);

    TheBeginFindinvokes theFindmethod on a different (worker) thread and passes a pointer to theFindSeviceCallbackmethod as a callback method; when theFindmethod returns aFindResultsinstance, the callback delegate is invoked so that theFindServiceCallbackmethod gets executed on the UI thread again. In theFindServiceCallbackmethod, you need to obtain theFindResultsreturned by theFindmethod by calling theEndFindmethod and displaying them. Keep in mind that the HTTP session is kept alive during this asynchronous operation behind the scenes—this pattern is asynchronous at your application thread level but not at the HTTP communication level.

    Asynchronous Programming for Web Applications

    Multithreaded programming works well for Windows applications if you are calling web services, but wouldn’t it be nice to adopt this asynchronous programming model for web applications as well? Wouldn’t it be convenient to develop more responsive applications without doing a complete page refresh? You can do these things with a combination of JavaScript and Msxml2.XMLHTTP ActiveX control. The use of JavaScript with asynchronous XML messaging is called Asynchronous JavaScript and XML, or simply AJAX. While AJAX terminology is fairly new to web application development, the use of JavaScript and XMLHTTP is not. In this section, I will go over some scenarios where AJAX can be used in your web applications to improve the overall user experience.

    More BrainDump Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Programming MapPoint in .NET," published...
     

    Buy this book now. This article is excerpted from chapter six of the book Programming MapPoint in .NET, written by Chandu Thota (O'Reilly; ISBN: 0596009062). Check it out today at your favorite bookstore. Buy this book now.

    BRAINDUMP ARTICLES

    - Multiple Service Contracts and Indigo
    - Cleaning Out Your Programs in XP
    - Handling Metadata with Indigo
    - Building Blocks for a WCF Service Web Site
    - Help! I Need Some Remote Assistance
    - Using Service Templates with Indigo
    - Windows XP Tips for Task Manager
    - Generating Clients and Services with Indigo
    - Vista SP1, A Review
    - Services and the WCF
    - VBScript: Final Date Functions
    - Creating Services with the WCF
    - The Resource View of the MFC
    - VBScript: More Fun with the Date Functions
    - Vista Price Cuts Dissected




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway