(Translated by https://www.hiragana.jp/)
Implementing Customer Identification
The Wayback Machine - https://web.archive.org/web/20080424125442/http://msdn2.microsoft.com:80/en-us/library/bb924353.aspx
Click to Rate and Give Feedback
Windows Live
Implementing Customer Identification

The latest Virtual Earth map control software development kit (SDK) gives users the ability to implement a customer identification mechanism in their application. This mechanism gives customers the ability to view reports detailing their Virtual Earth Platform usage as well as giving business users authorization to use commercial-application-only features.

This article describes the details of integrating Virtual Earth Platform Customer Identification into your commercial application.

This article assumes that you are already familiar with the Virtual Earth map control and JavaScript.

You will need Virtual Earth Platform Developer Account credentials. You can sign up for a free developer account on the Virtual Earth Platform Developer Account Request site. This is described in more detail in Step 1 below.

If you are using .NET to build your application, knowledge of the following is also required:

  • Simple Object Access Protocol (SOAP) application programming interface (API)
  • C# or Visual Basic .NET
  • ASP .NET

If you are using Java to build your application, supporting Java code can be found in the Supporting Files for Java topic, which requires that you have the following systems:

  • J2SE 5.0 or higher - The code in this topic was developed against J2SE 5.0.09.
  • JDK 5.0 or higher - Portions of the JDK are needed to compile and execute the code.
  • Axis 1.4 - The web service portion of the sample code was developed with Axis1.4. Other web service libraries may be used, but the specific development steps may be particular to your web service library.
  • Jakarta Commons HttpClient - The Jakarta Commons HttpClient is required to provide support for digest authentication through Axis1.4.
  • Apache XMLRPC - This library is a prerequisite for Axis.
  • Container for Java Web Application - Any suitable Java capable Web Server will work.

For more information about the Virtual Earth Platform, visit the Virtual Earth Platform Web site. For information about programming with the Virtual Earth Platform and the Virtual Earth map control, see the Virtual Earth SDK.

In a simple Virtual Earth map control project, you write JavaScript that is executed by the client. However, if you intend to track transactions, you will need to execute a web service call on the server to retrieve a token, pass the token to the client, and then register the token with each of the client's VEMap instances. The Virtual Earth map control will then embed the token into requests sent to Virtual Earth and these requests can be identified by Microsoft.

Figure 1. Interaction with the Virtual Earth servers

To integrate the Virtual Earth Platform Customer Identification feature into your Web application, first use your Virtual Earth Platform credentials to request a token. This token contains encrypted information including the end-client’s IP address and your Virtual Earth Platform developer account ID. A token is only valid for the duration specified in the initial request, beginning from the time the token request is made from your server. Set this token in the map control instance that is loaded into the client’s browser and then all requests made to Virtual Earth from your application are identified as requests made by you. Virtual Earth Platform logs these requests and you will be able to view Virtual Earth Platform transaction reports on the Virtual Earth Platform Customer Services site.

These steps are described in further detail in the following sections.

Step 1: Sign up for a Developer Account

In order to use the Customer Identification feature, you must sign up for a Virtual Earth Platform developer account. You will need a Windows Live ID to sign up for an account. Once your Virtual Earth Platform developer account is set up, you will have access to the Virtual Earth Platform Customer Services site. On your first visit to the Customer Services site, you will be asked to set your Virtual Earth Platform developer account password. This is different than the Windows Live ID and password that you use to sign in to the Customer Services site.

To use the Customer Identification feature, you must be a licensed customer. To request access to the Customer Identification feature, contact the Microsoft Virtual Earth Licensing Team.

Step 2: Add a reference to the Virtual Earth Platform Web Service

Before the Virtual Earth map control is loaded into the end-client’s browser, a token must be retrieved from the Virtual Earth Platform. Virtual Earth Platform provides a secure SOAP API service which contains a GetClientToken method to accomplish this. To use the Virtual Earth Platform web service you need your Virtual Earth Platform credentials, which consist of your developer account ID (found on the Manage Account page of the Virtual Earth Platform Customer Services site) and your developer account password. If you are using ASP .NET to build your application, then in your web application project add a web reference to the Virtual Earth Platform web service. If you are planning on using Java to request a token, depending on your Java Web Service API you may need to create proxy classes before accessing the GetClientToken method. You can find information about this in the Supporting Files for Java topic.

Step 3: Retrieve a Token

The GetClientToken method takes a TokenSpecification object, which contains two pieces of information:

  • The IP address of the client - You can usually extract this information from the client Http Headers using the request.getRemoteHost() method.
  • The length of time the token will be valid - Tokens are issued for a specific time length. You must specify a number of minutes ranging from 15 to 480 (8 hours).

The TokenSpecification Class declaration is below.

[Visual Basic]
Public Class TokenSpecification Inherits System.Object 
[C#] 
public class TokenSpecification : System.Object

Public Properties

Property Description

ClientIPAddress

A string representing the IPAddress to store in the token. Must be a valid IPv4 or IPv6 form.

TokenValidityDurationMinutes

An integer representing the number of minutes the token will be valid, beginning from the time the request is made. Maximum allowable value is 480. Minimum allowable value is 15.

Once you have instantiated the TokenSpecification object, you need to pass it to the GetClientToken method to return a token. The GetClientToken method returns a String, which is the token. The GetClientToken function declaration is below.

[Visual Basic]
Public Function GetClientToken (ByVal specification As TokenSpecification) As String 
[C#] 
public string GetClientToken (TokenSpecification specification)

The following code gets a token and makes it available for use by the Virtual Earth map control. This code must be called every time the client requests your Web page.

If you are using .NET to build your application, the Visual Basic or C# code can be inserted into the server-side Page_Load event of your ASP .NET Web Application so that it runs before the map control is loaded on the client.

[Visual Basic]
' Place the following code in the Page_Load event of your ASP .NET Web
' application so that it runs before the map control is loaded.
' This code assumes an Imports reference to the Virtual Earth
' Platform Web service. 
' Be sure to use an SSL connection to protect your information.

Dim commonService As New CommonServiceSoap()
commonService.Url = "https://common.virtualearth.net/find-30/common.asmx"
commonService.Credentials = 
  New System.Net.NetworkCredential(
    "Virtual Earth Platform Developer Account ID", 
    "Virtual Earth Platform Developer Account password")

' Create the TokenSpecification object to pass to GetClientToken.
Dim tokenSpec As New TokenSpecification()

' Use the Page object to retrieve the end-client’s IPAddress.
tokenSpec.ClientIPAddress = Page.Request.UserHostAddress

' The maximum allowable token duration is 480 minutes (8 hours).
' The minimum allowable duration is 15 minutes.
tokenSpec.TokenValidityDurationMinutes = 480

' Now get a token from the Virtual Earth Platform service.
Dim clienttoken As String
clienttoken = commonService.GetClientToken(tokenSpec)
[C#]
// Place the following code in the Page_Load event of your ASP .NET Web
// application so that it runs before the map control is loaded.
// This code assumes a using reference to the Virtual Earth Platform
// Web service. 
// Be sure to use an SSL connection to protect your information.
CommonServiceSoap commonService = new CommonServiceSoap();
commonService.Url = "https://common.virtualearth.net/find-30/common.asmx";
commonService.Credentials = 
  new System.Net.NetworkCredential(
    "Virtual Earth Platform Developer Account ID", 
    "Virtual Earth Platform Developer Account password");

// Create the TokenSpecification object to pass to GetClientToken.
TokenSpecification tokenSpec = new TokenSpecification();

// Use the Page object to retrieve the end-client’s IPAddress.
tokenSpec.ClientIPAddress = Page.Request.UserHostAddress;

// The maximum allowable token duration is 480 minutes (8 hours).
// The minimum allowable duration is 15 minutes.
tokenSpec.TokenValidityDurationMinutes = 480;

// Now get a token from the Virtual Earth Platform service.
string clienttoken = commonService.GetClientToken(tokenSpec);

If you are using Java and Axis proxy classes to build your application, the code will be similar to the code below. The classes used in this code sample are detailed in the Supporting Files for Java topic.

[Java]
tokenSpec = new TokenSpecification();
commonStub = new CommonServiceSoapStub(new
 URL("https://common.virtualearth.net/find-30/common.asmx"), null);
env = (Context) new InitialContext().lookup("java:comp/env");
UserName = (String) env.lookup("UserName");
Password = (String) env.lookup("Password");
commonStub.setUserName(UserName);
commonStub.setPassword(Password);
tokenSpec.setClientIPAddress(clientIP);

//The maximum allowable token duration is 480 minutes (8 hours).
tokenSpec.setTokenValidityDurationMinutes(480);

//Retrieve the token.
String token = commonStub.getClientToken(tokenSpec);

Step 4: Set the Token in the Map Control

After the token has been retrieved from the Virtual Earth Platform Web service, it must be passed to the client and set for every VEMap instance. You can pass the token to the client using any of a variety of web methods, including adding it as a hidden field, or putting it in the query string.

If you are building your application using ASP .NET, you can use the following code on the client to retrieve the clienttoken server variable set in the Visual Basic .NET or C# code samples in Step 2.

[JavaScript]
// Retrieve the clienttoken variable from server-side code.
var token = "<%=clienttoken %>";

After you have passed the token string to the client, the SetClientToken method of the VEMap class is provided to set the token on the VEMap instance.

[JavaScript]
VEMap.SetClientToken(token);

Setting the token before you load the map or make any other Virtual Earth requests ensures that every request sent to Virtual Earth is identified.

[JavaScript]
// Set the token before loading the map or making any other 
// Virtual Earth requests.
var map = new VEMap(‘mymap’);
map.SetClientToken(token);
map.LoadMap();

Once the token is set, all transaction based calls will be logged against your Virtual Earth Platform Developer Account.

Step 5: Handle Token Expiration and Error Events

Every time a Virtual Earth map control request is made, the token that was set is passed to the server for identification and validation. There are two callback events that can be used to catch token errors. The first is the ontokenerror event. This event occurs when a map control request is made with a token that is not a valid Virtual Earth Platform token. The second is the ontokenexpire event and it occurs when a map control request is made with an expired token. A client token is valid for the duration specified in the request, beginning from the time the request for the token was made to the Virtual Earth Platform Web service. Once the token expires, you will want to alert the end-client that their session has expired and that their browser should be refreshed. To catch these events, use the VEMap.AttachEvent Method. The following code sample shows how to catch token expire and token error events.

[JavaScript]
// Attach token expired and token error events.
var map = new VEMap(‘mymap’);
map.AttachEvent('ontokenexpire', MyHandleTokenExpire);
map.AttachEvent('ontokenerror', MyHandleTokenError);

function MyHandleTokenExpire()
{
   // insert code here to handle token expiration
}

function MyHandleTokenError()
{
   // insert code here to handle token errors
}

Once the Virtual Earth Customer Identification feature is integrated into your application, transactions sent to Virtual Earth Platform by your application will be logged and you will be able to view transaction usage reports on the Virtual Earth Platform Customer Services site. Log in to the Virtual Earth Platform Customer Services site using the Windows Live ID you used to create your Virtual Earth Platform developer account. Click on the View Reports menu item on the left-hand side of the Home page. On the View Reports page, select one of the available Virtual Earth Platform reports.

Viewing Virtual Earth Platform Reports

The Virtual Earth Platform reports, which are found on the View Reports page of the Virtual Earth Platform Customer Services site, display information about your Virtual Earth Platform usage, including your billable transactions ("Billable Transactions"). Virtual Earth Platform transactions include both MapPoint Web Service (MWS) transactions as well as Virtual Earth (VE) map control transactions.

You must be a licensed customer to view Virtual Earth Platform Reports. Contact the Microsoft Virtual Earth Licensing Team for more information.

Billable Transactions

The MapPoint Web Service (MWS) methods that cause billable transactions to be accrued include Find, FindAddress, FindById, FindByProperty, FindNearby, FindNearRoute, FindPolygon, GetLocationInfo, ParseAddress, GetMap, GetLineDriveMap, CalculateRoute, and CalculateSimpleRoute.

Certain Virtual Earth (VE) map control requests made after the VEMap.SetClientToken method is called with a valid token are included in your transaction reports. The following Virtual Earth map control features count as billable transactions and appear in your Virtual Earth Platform Reports.

Map navigation (Load Standard Map) – Transactions are counted any time new map tiles are requested from Virtual Earth. Virtual Earth Platform bills per map view, which is calculated based on the assumption that a map view is multiple tile transactions. This includes VEMap.LoadMap, VEMap.ZoomIn, VEMap.ZoomOut, VEMap.Pan, VEMap.SetMapView, and many other methods that cause the map to move. A single Billable Transaction shall equate to eight (8) Virtual Earth image tiles being fetched from Microsoft servers.

Traffic requests (Load Traffic Map) – If traffic is turned on, you are charged double for every tile that includes traffic information. Virtual Earth Platform bills per map view, which is calculated based on the assumption that a map view is multiple tile transactions. A single Billable Transaction shall equate to eight (8) Virtual Earth image tiles being fetched from Microsoft servers.

Geocode – Any time Virtual Earth map control makes a where-only request for a find result, one transaction is counted. This includes where-only requests from the VEMap.Find method as well as the VEMap.GetDirections method.

ReverseGeocode - Each request made using the VEMap.FindLocations method counts as one transaction.

CalculateRoute – If you make a request for a route using the new VEMap.GetDirections method, one transaction per returned route is counted. Use of the deprecated GetRoute method is not counted.

By using the Virtual Earth Customer Identification feature in your application, you can view reports detailing your Virtual Earth Platform usage as well as gain access to commercial-application-only features.

© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker