Parsing Addresses and More with the MapPoint Web Service Find APIs - Optimizing Find Call Performance
(Page 4 of 5 )
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.
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 returnFindResultobjects 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 theFindResultMaskenumeration:
//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 asFindNearby,FindById,FindByProperty, andFindNearRoute, it is always a good practice to request entity attributes using theFindFilterobject. This object has a property,PropertyNamesof 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 yourFindNearbyrequest using theFindFilter.PropertyNamesso 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 theFindFilterExpression.Expressionobject. The following code snippet shows the usage of theFindFilter.PropertyNamesproperty:
//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);
Next: Applying Proper Metadata for Faster Searches >>
More BrainDump Articles
More By O'Reilly Media
|
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.
|
|