ArcGIS Routing with NAServer


Purpose
This sample demonstrates how to generate a route and directions between two geocoded addresses using an NAServer Web service. There is a Web page that adds the stops and routes returned by the Network Analysis Web service to a Map control as graphics. There is also a Web page that displays the image returned by the Network Analysis Web service. Both pages also show the driving directions in a data grid.
The sample uses USA data as the base map and for the routing and geocoding it uses ArcGISOnline Tasks web services.
 
For Geocoding:
If you do not intend to use these online services, please make sure to publish a Routing and Geocoding service and make appropriate changes to the code.

How to use

Data has been provided for your use with this sample. It can be found at <Your ArcGIS Developer Kit Install directory>/Samples/data/USA.
If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

At design time
  1. Verify that the Web Application Developer Framework (ADF) for the .NET Framework is installed and functioning properly. For information on installing and configuring the Web ADF, consult the installation guide.
  2. In Windows Explorer, navigate to <ArcGIS Developer Kit install location>\Samples\ServerNET\ArcGIS_NAServer_Routing.
  3. Open the folder of the language you're going to use—CSharp or VBNet—and copy the ArcGIS_NAServer_Routing_<language> folder to c:\inetpub\wwwroot. The <language> variable can be either CSharp or VBNet.
  4. Open the IIS Manager from Control Panel > Administrative Tools > Internet Information Services (IIS) Manager or Internet Information Services.
  5. In the console tree view on the left, navigate to Local Computer > Web Sites > Default Web Site, expand Default Web Site, right-click the ArcGIS_NAServer_Routing_<language> folder, and click Properties. The Properties dialog box opens.
  6. Click the Directory tab, click the Create button in the Application Settings section, then click OK to close the Properties dialog box.
  7. Start Microsoft Visual Studio. Open the solution for the version of Visual Studio you're using. The Visual Studio version is appended to the solution file name. For example, the Visual Studio 2008 solution file for the ArcGIS_NAServer_Routing_CSharp sample is ArcGIS_NAServer_Routing_CSharp2008.sln and is located in the c:\inetpub\wwwroot\ArcGIS_NAServer_Routing_CSharp folder.
  8. In Solutions Explorer, right-click Default.aspx and select Set As Start Page.
  9. If necessary, modify the member variables at the top of the code-behind for Default.aspx or Default_Static.aspx. The ArcGIS Server name is referenced.
  10. Change the identity specified in web.config manually or by right-clicking the project and clicking Add ArcGIS Identity. The user account specified must have access to the geographic information system (GIS) server resources referenced in the Map control.
  11. Click the Debug drop-down menu and click Start.
  12. Address any errors that occur in the debugging process.

At run time
  1. Browse to the default uniform resource locator (URL) (for example, http://localhost/ArcGIS_NAServer_Routing_CSharp/Default.aspx).
  2. Type the addresses where you want to start and end.
  3. Click Find Route. A route is generated and added as graphics to the Map control.
  4. Browse to the other Web page URL (for example, http://localhost/ArcGIS_NAServer_Routing_CSharp/Default_Static.aspx).
  5. Type the addresses where you want to start and end.
  6. Click Find Route.

ArcGIS_NAServer_Routing_CSharp\Default.aspx Contains the user interface (UI) for finding a route and displaying it in a Map control as well as the directions in a data grid.
ArcGIS_NAServer_Routing_CSharp\Default.aspx.cs Code behind the .aspx file. Performs route network analysis and adds the route and stops returned by the NAServer Web service as graphics to a Map control.
ArcGIS_NAServer_Routing_CSharp\Default_Static.aspx Contains the UI for finding a route and displaying it in an Image control as well as the directions in a data grid.
ArcGIS_NAServer_Routing_CSharp\Default_Static.aspx.cs Code behind the .aspx file. Performs route network analysis and draws the image returned by the NAServer Web service.
ArcGIS_NAServer_Routing_CSharp\MapImage.aspx Page used to draw the map image returned by the NAServer Web service.
ArcGIS_NAServer_Routing_CSharp\MapImage.aspx.cs Code behind the .aspx file. Displays the map image returned by the NAServer Web service.
Download the C# files
ArcGIS_NAServer_Routing_VBNet\Default.aspx Contains the user interface (UI) for finding a route and displaying it in a Map control as well as the directions in a data grid.
ArcGIS_NAServer_Routing_VBNet\Default.aspx.vb Code behind the .aspx file. Performs route network analysis and adds the route and stops returned by the NAServer Web service as graphics to a map control.
ArcGIS_NAServer_Routing_VBNet\Default_Static.aspx Contains the UI for finding a route and displaying it in an Image control as well as the directions in a data grid.
ArcGIS_NAServer_Routing_VBNet\Default_Static.aspx.vb Code behind the .aspx file. Performs route network analysis and draws the image returned by the NAServer Web service.
ArcGIS_NAServer_Routing_VBNet\MapImage.aspx Page used to draw the map image returned by the NAServer Web service.
ArcGIS_NAServer_Routing_VBNet\MapImage.aspx.vb Code behind the .aspx file. Displays the map image returned by the NAServer Web service.
Download the VB.NET files

Download the files for all languages