Integrating Microsoft MapPoint Web Service into Microsoft CRM
Microsoft® CRM version 1.2
Microsoft Business Solutions CRM version 1.2
Microsoft Visual Studio® .NET
Microsoft MapPoint® Web Service SDK version 3.5
Summary: You can integrate the Microsoft MapPoint Web Service with the Microsoft CRM application to provide maps and latitude or longitude information for your customers. (10 printed pages)
Download the sample code for this article: CustomerAddressMap.exe.
Knowing where your customers are is important, and sometimes latitude and longitude coordinates can be just as important as street addresses. In this article, we incorporate new features into the account and contact forms and use Microsoft® MapPoint® .NET to help you find your customers more easily. The sample application adds user interface (UI) elements to those forms to look up and update the latitude and longitude coordinates of customer addresses, show a map of the United States with clickable pushpins for each of a given customer's addresses, and show detail maps of the area around a customer's address, as shown in the following two figures. Information about how to display a map of another country is available at the end of this article.
Figure 1. The account form showing a map of all addresses (click picture to see larger image)
Figure 2. A detail map showing one address location
Before working with the sample code, you must get a free Microsoft MapPoint .NET trial account by performing the following steps:
- Open a Web Browser and go to the Microsoft MapPoint site. Click MapPoint Web Service in the left pane, and then click Evaluation Account. This opens the evaluation form.
- Fill out the form and click the Submit request button.
- Go to the MapPoint Web Service SDK download site and download the SDK. Alternatively, you can browse the SDK online.
- Install the SDK. The SDK consists of sample code and documentation for the MapPoint Web Service.
- Wait for your MapPoint Web Service user name and password to arrive through e-mail. This may take several days.
Download the sample code CustomerAddressMap.exe.
After downloading the sample code, unzip CustomerAddressMap.exe to your c:\inetpub\wwwroot directory. A folder named CustomerAddressMap will be created.
Follow these steps to create a virtual directory that points to the CustomerAddressMap folder in Internet Information Services Manager:
- On the Start menu, click All Programs, and then Administrative Tools. Click Internet Information Services (IIS) Manager.
- Expand the node for your server, and then expand the Web Sites node.
- Right-click Microsoft CRM Version 1.2. Select New and then click Virtual Directory.
Step through the Virtual Directory Creation Wizard as follows:
- On the Welcome page of the wizard, click Next.
- On the Virtual Directory Alias page, type CustomerAddressMap and click Next.
- On the Web Site Content Directory page, browse to the CustomerAddressMap folder in the c:\inetpub\wwwroot location and click Next.
- On the Virtual Directory Access Permissions page, leave the default selections of Read and Run Scripts and click Next.
- Click Finish.
You must make several changes in the sample code before testing the code: add a Web reference to the MapPoint Web Service and fill in your Microsoft CRM server name, and your MapPoint user name and password. Perform the following steps to add a reference to the MapPoint Web Service:
- To open the project in Microsoft Visual Studio® .NET 2003, double-click the file CustomerAddressMap.csproj.
- In the Solution Explorer, right-click References and then click Add Web Reference.
- In the URL box, type this URL for the MapPoint Web Service:
http://staging.mappoint.net/standard-30/mappoint.wsdl. You can also find this information in the MapPoint Web Service SDK. Click Go.
Note The URL used in this step is for a MapPoint staging server. For production, you should use the URL:
- Once the Web service is found, click Add Reference.
You must perform the following steps to fill in your Microsoft CRM server name, and your MapPoint user name and password:
- Open the file ISVAddress.cs. Change the name of the server in the CrmUrl member variable of the ISVAddress class to be that of your Microsoft CRM server. Save your changes.
- Open the file ISVMap.cs. Change the MapPointUsername and MapPointPassword member variables of the ISVMap class to be those of your MapPoint .NET trial account.
Note This sample contains a user name and password. This is a potential security issue. For more information, see Building Secure ASP.NET Applications.
- Rebuild your solution.
Before you can test the sample code, you must customize Microsoft CRM.
First you must add the latitude and longitude fields to the account, contact, and customer address forms by performing the following steps. These fields are a part of the Microsoft CRM database but are not used by the Microsoft CRM Web application.
- Open Microsoft CRM and go to Settings, System Customization.
- From the Record Type Management list, click Accounts, and then click Customize Form.
- Click Address to activate that portion of the form. On the Task Pane, click Add Fields, and add two new fields: address1_latitude and address1_longitude, as shown in the following figure.
Figure 3. Adding the address1_latitude and address1_longitude fields to the account form (click picture to see larger image)
- Select the address1_latitude field on the account form and click Change Properties on the Task Pane. Type Latitude for the label.
- On the Formatting tab, select 5 from the Decimal Accuracy drop-down list.
- On the Values tab, specify a Minimum value of -180.00 and a Maximum value of 180.00. Click OK.
- Select the address1_longitude field on the account form and click Change Properties on the Task Pane. Type Longitude for the label.
- Repeat steps 5 through 6.
- Click the Save and Close button to save your changes to the form.
- Return to the Record Type Management list, and click Contacts. Follow the same instructions as listed above for Accounts.
- Return to the Record Type Management list, and click Address.
- Click Customer Address Information to activate that portion of the form. On the Task Pane, click Add Fields, and add two new fields: Latitude and Longitude.
- Select the Latitude field on the account form and click Change Properties on the Task Pane. Repeat steps 5 through 7.
- Click the Save and Close button to save your changes to the form.
You must now publish your form customizations using the following procedure:
- On the Start menu, point to All Programs, point to Microsoft CRM, and then click Deployment Manager.
- On the Action menu, click All Tasks and then click Publish Customization.
- Select the check boxes for the Account, Contact, and CustomerAddress objects and click Next.
- Click Add. Select your Microsoft CRM Web server, click Add, and then click Finish.
- When the Status dialog box is displayed, click OK.
Finally, you must add the Map button and the Update Lat/Long menu to the account and contact forms, as shown in the figure at the end of this section. This is done by editing the isv.config file. This configuration file is used to add custom pages and menu items to the application.
Make a backup copy of the original isv.config file before proceeding. You can find it in c
:\inetpub\wwwroot\_Resources\. Copy the file from the sample code folder
When you make changes to the configuration file, you must restart IIS to make the changes available to users. To restart IIS, click Run from the Start menu, type iisreset, and click OK.
The following code shows a new navigation bar button named Map and a new menu item named Update Lat/Long that are added to the forms. For more information about how to customize this configuration file, see Customizing the Microsoft CRM Application in the Microsoft CRM SDK.
<configuration> <Root> <!-- The main Menu Bar found at the top of all root level areas --> <MenuBar> <!-- Custom Menu Bar items go between the Goto and Help menus --> <CustomMenus> </CustomMenus> </MenuBar> <!-- The left areas for each section in the application --> <Areas> <Home code="home"/> <Workplace code="workplace"/> <Sales code="sfa"/> <Service code="cs"/> <Reports code="reports"/> </Areas> </Root> <!-- Microsoft Customer Relationship Management Entities (Objects) --> <Entities> <account> <ToolBar ValidForCreate="0" ValidForUpdate="1"> <Button Title="Update Lat/Long" ToolTip="Update Lat/Long values using Microsoft MapPoint .NET" Icon="/CustomerAddressMap/compass.gif" Url="/CustomerAddressMap/UpdateLatLong.aspx" PassParams="1" WinParams="status=0; menubar=0; toolbar=0; height=200; width=400;" /> </ToolBar> <NavBar ValidForCreate="0" ValidForUpdate="1"> <NavBarItem Icon="/CustomerAddressMap/compass.gif" Title="Map" Url="/CustomerAddressMap/mapAllAddresses.aspx" Id="accountMap" /> </NavBar> </account> <contact> <ToolBar ValidForCreate="0" ValidForUpdate="1"> <Button Title="Update Lat/Long" ToolTip="Update Lat/Long values using Microsoft MapPoint.NET" Icon="/CustomerAddressMap/compass.gif" Url="/CustomerAddressMap/UpdateLatLong.aspx" PassParams="1" WinParams="status=0; menubar=0; toolbar=0; height=200; width=400;" /> </ToolBar> <NavBar ValidForCreate="0" ValidForUpdate="1"> <NavBarItem Icon="/CustomerAddressMap/compass.gif" Title="Map" Url="/CustomerAddressMap/mapAllAddresses.aspx" Id="contactMap" /> </NavBar> </contact> <lead/> <opportunity/> <incident/> <!-- Case --> <quote/> <salesorder/> <!-- Order --> <invoice/> </Entities> </configuration>
Figure 4. The account form showing the Map button and the Update Lat/Long menu (click picture to see larger image)
Integration of the mapping service is complete. To use this sample application, create an account or contact, enter at least one address to an account or contact form and click Save. If you don't enter any addresses, clicking the Map button and Update Lat/Long menu will display an error. After you click the Update Lat/Long menu, a dialog box is shown briefly while the processing takes place. When it completes, click the Close button and the Latitude and Longitude boxes are filled in. To show the map for the address entered, click the Map button. The following two figures show the contact form with the computed latitude and longitude and the map page with two addresses, respectively.
Figure 5. The contact form showing the computed latitude and longitude (click picture to see larger image)
Figure 6. The contact map page showing two addresses (click picture to see larger image)
This sample shows a map of the United States. The following code in the mapAllAddresses.aspx.cs file performs this task:
// Create a map of the contiguous United States of America. ISVMap map = new ISVMap(38.88, -97.43); map.SetHeight(400, 3500); map.SetWidth(600, 3500);
You need to change this latitude and longitude setting to one appropriate to the area you are interested in. You may also need to change the height and width of the map.
In addition, you must change the MapPoint data source in the following code in the ISVMap.cs file to the area you specified previously:
mapSpec.DataSourceName = "MapPoint.NA";
For example, use this value to set the data source to Europe:
findAddressSpec.DataSourceName = "MapPoint.EU";
For information about alternative data sources, see the MapPoint Web Service SDK.
For more information about customizing the Microsoft CRM application, see the Microsoft CRM Software Development Kit (SDK).
For more information about MapPoint and the MapPoint Web Service SDK, see the MapPoint Web Service Home page on MSDN®.