Section 6.6. Optimizing Find Call Performance


6.6. Optimizing Find Call Performance

One of the advantages of working with web services is that you can invoke methods over the wire using XML, but due to the remote nature of this method and XML's inherent behavior to bloat the packet size, it may pose performance and end user experience issues. For example, say you are building a mapping application for a handheld device that depends on GPRS for connectivity; usually the users of these connected handheld devices pay the network service provider for the data plans (the number of bytes downloaded over the air using the GPRS connections).

To find a place, your MapPoint Web Service application sends a request SOAP XML message and receives the response SOAP XML message from the Web Service. Because the XML bloats the size of the request and response packet, this could cost your application users a lot of money. Not only could having large request and response messages slow down your application for network transfer, but it also may result in poor end user experience. There are multiple ways to optimize your MapPoint Web Service applications for SOAP XML size and response speed; let's look at them in detail.

6.6.1. Optimizing the SOAP Response Size

Always write your applications to receive only the information you need and filter out all unnecessary noise. There are three elements you can limit to do this:


Result-set size

If you are looking for a place and are certain of its name, request only one find result using the FindRange object:

     //Create a FindServiceSoap object.     FindServiceSoap findservicesoap = new FindServiceSoap();     //Assign credentials go here.     . . .     //Create a FindSpecification object.     FindSpecification findspecification = new FindSpecification();     //Assign a valid data source name.     findspecification.DataSourceName = "MapPoint.NA";     //Specify a place to find.     findspecification.InputPlace = "Redmond, WA";     //Create a FindOptions object.     findspecification.Options = new FindOptions();     //Create a Range object.     findspecification.Options.Range = new FindRange();     //Assign the Range StartIndex and the result count to be returned.     findspecification.Options.Range.StartIndex = 0;     findspecification.Options.Range.Count = 1;     //Invoke the Find method.     FindResults findresults =               findservicesoap.Find(findspecification);


Result information

Usually, all find methods return FindResult objects with location, entity, and best map view information, leaving it up to you to pick and choose what information you need and don't need. If you are looking only for latitude/longitude information for one particular place, get only that information by filtering all other information using the FindResultMask enumeration:

     //Create a FindServiceSoap object.     FindServiceSoap findservicesoap = new FindServiceSoap();     //Assign credentials go here.     . . .     //Create a FindSpecification object.     FindSpecification findspecification = new FindSpecification();     //Assign a valid data source name.     findspecification.DataSourceName = "MapPoint.NA";     //Specify a place to find.     findspecification.InputPlace = "Redmond, WA";     //Set ResultMask to retrieve only map view information.     findspecification.Options.ResultMask = FindResultMask.BestMapViewFlag;     //Invoke the Find method.     FindResults findresults =               findservicesoap.Find(findspecification);


Limit entity information

Even though this is only applicable to point of interest methods, such as FindNearby, FindById, FindByProperty, and FindNearRoute, it is always a good practice to request entity attributes using the FindFilter object. This object has a property, PropertyNames of type string array, that allows you to define which attributes you want to see on returned entities. If an entity (such as a coffee shop) has 200 properties and you plan to use only 2 properties (say, Name and PhoneNumber), you can specify that in your FindNearby request using the FindFilter.PropertyNames so that your response SOAP XML contains only 2 properties instead of all 200. The only caveat to this approach is that your definition for property names must also include the names used in filter expression in the FindFilterExpression.Expression object. The following code snippet shows the usage of the FindFilter.PropertyNames property:

     //Declare a find nearby specification object     //and assign all required information     FindNearbySpecification findNearbySpec  = new FindNearbySpecification();     findNearbySpec.DataSourceName = "MapPoint.FourthCoffeeSample";     findNearbySpec.Distance = 1;     findNearbySpec.LatLong = new LatLong();     findNearbySpec.LatLong.Latitude = 47.6;     findNearbySpec.LatLong.Longitude = -122.33;     findNearbySpec.Filter = new FindFilter();     findNearbySpec.Filter.EntityTypeName = "FourthCoffeeShops";     //Minimize the properties on returned entities by     //specifying the property names field     //Define the properties you plan to use     //in your application     string[] returnProperties = new string[2];     returnProperties[0] = "Name";     returnProperties[1] = "Phone";     //Assign it to find nearby specification     findNearbySpec.Filter.PropertyNames = returnProperties;     FindResults foundResults;     foundResults = findService.FindNearby(findNearbySpec);

6.6.2. Applying Proper Metadata for Faster Searches

Whenever possible, try to apply proper metadata for your find queries, including applying proper entity type information and adding search contexts. For example, if you are searching for Redmond, WA in the United States, you can improve your application's performance by adding the entity type information of PopulatedPlace (using the entity type name for cities means that you are looking only for a city) and a context of 244 (the entity ID of the United States narrows your search to the United States) during your find call:

     //Create a find specifications object     FindSepcification findspecification = new FindSepcification();     //Assign the EntityTypeNames value     findspecification.EntityTypeNames = new string[] {"PopulatedPlace"};     //Assign search context     findspecification.Options = new FindOptions();     //Add context for United States     findspecification.Options.SearchContext = 244;

6.6.3. Use Asynchronous Programming Patterns

Since any web service call involves a network round-trip, using asynchronous programming improves the user's experience dramatically. With MapPoint Web Service Find Service, you can use asynchronous programming paradigms provided by Microsoft .NET Framework. If you are building a web or Windows application using MapPoint Web Service, you can use the MapPoint Web Service asynchronous methods to perform tasks such as Find or FindAddress; however, in order to use asynchronous methods, you use the Begin and End pair methods instead of the actual method itself. For example, to call the Find method in asynchronous patterns, use the BeginFind and EndFind methods, which internally use the SoapHttpClientProtocol object's BeginInvoke and EndInvoke methods.

When you are building an enterprise-level application using MapPoint Web Service, obviously performance is not the only thing you need to keep in mind; you also need to think about supporting multiple languages and cultures, so globalizing your applications to support local languages is an essential part of your application. In the next section, let's see how to leverage some of the MapPoint Web Service features to build global applications




Programming MapPoint in  .NET
Programming MapPoint in .NET
ISBN: 0596009062
EAN: 2147483647
Year: 2005
Pages: 136
Authors: Chandu Thota

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net