Routing and geocoding 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.
  • Geocoding two addresses.
  • Creating stop locations from the geocoded addresses.
  • Solving to find the best route.
  • Displaying the map showing the route and total impedance of the route.

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.

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 Publisher connection to ArcGIS 10.1 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.

Publish a geocoding service
  1. Open the Catalog window in ArcMap, navigate to SanFrancisco.gdb, right-click SanFranciscoLocator, and click Share As > Geocode Service.
  2. Type SanFranciscoLocator as the service name and click Next.
  3. Choose Publish a service, and click Next.
  4. Choose Publisher connection to ArcGIS 10.1 Server, which will host the published document.
  5. Click Next, then click Continue.
  6. Click Publish.

Add a reference to the service to your .NET solution
  1. Start Visual Studio.
  2. Open the solution file.
  3. In the Solution Explorer, right-click References and choose Add Web Reference.
  4. Type the following URL: http://<server>:6080/arcgis/services/SanFrancisco/MapServer/NAServer?wsdl, then click Go.
  5. Change the Web reference name to WebService.
  6. Click Add Reference.
  7. Save the solution.
  8. Close Visual Studio.

Merge Web Service Description Languages (WSDLs) from NAServer and GeocodeServer
  1. Open a Visual Studio command prompt.
  2. Change to the directory where the proxy stub file was generated, <Solution Folder>\Web References\WebService.
  3. For C#, type the following: wsdl.exe /Language:cs /verbose /sharetypes /namespace:GeocodeRoute_WebService.WebService /out:Reference.cs http://<server>:6080/arcgis/services/SanFrancisco/MapServer/NAServer?wsdl http://<server>:6080/arcgis/services/SanFranciscoLocator/GeocodeServer?wsdl
  4. For VB .NET, type the following (change localhost if ArcGIS for Server is on a different machine): wsdl.exe /Language:VB /verbose /sharetypes /namespace:GeocodeRoute_WebService.WebService /out:Reference.vb http://<server>:6080/arcgis/services/SanFrancisco/MapServer/NAServer?wsdl http://<server>:6080/arcgis/services/SanFranciscoLocator/GeocodeServer?wsdl

Run the sample
  1. Open the solution file in Visual Studio.
  2. Build and run the project.
  3. Choose the route solver options.
  4. Click the Find Route button.
  5. Click the different tabs to get the solver results.

GeocodeRoute_WebServiceClass.cs Code for the main form.
GeocodeRoute_WebServiceClass.resx Resource file.
Download the C# files
GeocodeRoute_WebServiceClass.vb Code for the main form.
GeocodeRoute_WebServiceClass.resx Resource file.
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