Route application using the NAServer extension in ArcGIS for Server via a Web service


Purpose
This sample is a stand-alone application that shows how to programmatically perform point-to-point routing using the ArcGIS Network Analyst extension in ArcGIS for Server connecting to a Web service catalog. This sample demonstrates some of the key programming patterns when using ArcGIS Network Analyst extension server objects. These programming patterns include the following:
  • Connecting to the Web service.
  • Accessing solver properties from a route analysis layer.
  • Creating stop locations from a set of x,y coordinates.
  • Setting NAServer route solver parameters.
  • Solving to find the best route.
  • Accessing NAServer result objects (map showing the route, driving directions, and input and output NAClasses).

How to use

See How to use ArcGIS samples for help on compiling, setting up the debugger, and running the sample.

Data has been provided for your use with this sample. It can be found at <Your ArcGIS Developer Kit Install directory>/Samples/data/SanFranciscoNetwork.
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.

  1. Publish a network analysis service (see the following section).
  2. Open the solution file in Visual Studio.
  3. In the Solution Explorer, right-click References, and choose Add Web Reference.
  4. Type in the following URL: http://<server>:6080/arcgis/services/SanFrancisco/MapServer/NAServer?wsdl, then click Go.
  5. In the Web Reference Name control, type the name WebService.
  6. Click Add Reference.
  7. Save the solution.
  8. Build and run the project.
  9. Choose the route solver options.
  10. Click the Find Route button.
  11. Click the different tabs to get the solver results according to your NAServerRouteParams.

Publish a network analysis service
  1. Open ArcMap.
  2. Open <Your ArcGIS Developer Kit install folder>\samples\data\SanFrancisco\SanFrancisco.mxd.
  3. Navigate to File > Share As > Service.
  4. Choose Publish a service, and click Next.
  5. Choose the Publisher connection to ArcGIS 10.1 for Server, which will host the published document.
  6. Click Next, then click Continue.
  7. Choose Capabilities and check the Network Analysis check box.
  8. Click the Analyze button and address any significant issues that may be present.
  9. Click the Publish button. Note: If the publishing connection does not have "Copy data to the server when publishing" selected, SanFrancisco.gdb should be present on the server in exactly the same location as on the publishing machine.

Route_WebServiceClass.cs Code for the main form.
Download the C# files
Route_WebServiceClass.vb Code for the main form.
Download the VB.NET files

Download the files for all languages




Additional Requirements
  • Data requirements—The ArcGIS Network Analyst extension sample data for the San Francisco region can be used to create the required server objects. To use your own data with this sample, see the documentation on designing and building network datasets.
  • The network dataset must be built with at least one cost attribute, likely based on distance. Optionally, you can add more cost attributes based on time units, for example, and add restrictions or direction information to generate driving directions.
  • The map document must contain the network dataset, a route analysis layer, and a point feature layer.

Development licensing Deployment licensing
Engine Developer Kit Engine: Network Analyst
ArcGIS for Desktop Basic: Network Analyst ArcGIS for Desktop Basic: Network Analyst
ArcGIS for Desktop Standard: Network Analyst ArcGIS for Desktop Standard: Network Analyst
ArcGIS for Desktop Advanced: Network Analyst ArcGIS for Desktop Advanced: Network Analyst