Description:
This sample is a stand-alone application that shows how to programmatically perform point-to-point routing using the Network Analyst server extension
connecting to a network anlaysis web service. This sample demonstrates some of the key programming patterns when using Network Analyst server objects such as:
- 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.
- Diplaying the map showing the route, and the total impedance of the route.
Data requirements:
- The Network Analyst sample data for the San Francisco region can be used to create the required server objects.
To use your own data with this sample, refer to the documentation on designing and building a network dataset in
the ArcGIS Desktop Help > Contents tab > Extensions > Network Analyst.
- 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, add restrictions,
or add direction information in order to generate driving directions.
- The map document must contain the network dataset, a Route analysis layer, and a point feature layer.
Products: ArcView: C#, VB.NET Engine: C#, VB.NET Server: C#, VB.NET Extension: Network AnalystPlatforms: WindowsMinimum ArcGIS Release: 9.2 |
How to use:[NET, .NET, C#, VB.NET]
-
Publish a network analysis service
- Open ArcCatalog
- Browse to [Your ArcGIS install folder]\DeveloperKit\SamplesNET\Server\data\SanFranciscoNetwork
- Right-click on SanFrancisco.mxd and click on "Publish to ArcGIS Server..."
- Enter 'SanFrancisco' as the Service Name
- Click Next
- Ensure "Network Analysis" is checked and click Next
- Click Finish
-
Publish a geocoding service
- Right-click on SanFranciscoLocator and click on "Publish to ArcGIS Server..."
- Enter 'SanFranciscoLocator' as the Service Name and click Next
- Click Finish
- Close ArcCatalog
-
Add a reference to the service
- Open GeocodeRoute_WebService.sln (VB.NET or C#)
- In the Solution Explorer, Right click on References, then select Add Web Reference
- Type in the URL "http://localhost/arcgis/services/SanFrancisco/MapServer/NAServer.agsx?wsdl" (change localhost if the ArcGIS server is on a different machine) and click Go
- Change the Web Reference Name from "localhost" to "WebService"
- Click Add Reference
- Save the solution
- Exit Visual Studio
-
Merge WSDLs from NAServer and GeocodeServer
- Open a Visual Studio 2005 command prompt
- Change to the directory where the proxy stub file was generated: [Solution Folder]\Web References\WebService
- For C#, type in the following (change localhost if the ArcGIS server is on a different machine): "wsdl.exe /Language:cs /verbose /sharetypes /namespace:GeocodeRoute_WebService.WebService /out:Reference.cs http://localhost/arcgis/services/SanFrancisco/MapServer/NAServer.agsx?wsdl http://localhost/arcgis/services/SanFranciscoLocator/GeocodeServer?wsdl"
- For VBNet, type in the following (change localhost if the ArcGIS server is on a different machine): "wsdl.exe /Language:VB /verbose /sharetypes /namespace:GeocodeRoute_WebService.WebService /out:Reference.vb http://localhost/arcgis/services/SanFrancisco/MapServer/NAServer.agsx?wsdl http://localhost/arcgis/services/SanFranciscoLocator/GeocodeServer?wsdl"
-
Run the sample
- Open GeocodeRoute_WebService.sln (VB.NET or C#)
- Build and run the project
- Choose the route solver options
- Click the Find Route button
- Click on the different tabs to get the solver results
| GeocodeRoute_WebServiceClass.cs
|
C# form. |
| GeocodeRoute_WebService.csproj |
The project file. |
| GeocodeRoute_WebService.sln |
The solution file. |
| GeocodeRoute_WebService.resx |
A project file. |
Download the C# files
| GeocodeRoute_WebServiceClass.vb
|
VB.NET form. |
| GeocodeRoute_WebService.vbproj |
The project file. |
| GeocodeRoute_WebService.sln |
The solution file. |
| GeocodeRoute_WebService.resx |
A project file. |
Download the VB.NET files
Download the files for all languages
Key Libraries: NetworkAnalyst
Key CoClasses:NAServer, NAServerRouteParams, NAServerRouteResults, NAStreetDirections
Key Interfaces: INAServer, INAServerSolverParams, INAServerSolverResults, INAServerRouteParams, INAServerRouteResults, INAStreetDirections
Key Members:INAServer::Solve, INAServer::GetNALayerNames, INAServerSolverParams::ReturnMap, INAServerSolverResults::SolveMessages, INAServerSolverResults::MapImage, INAServerRouteParams::Stops, INAServerRouteParams::ReturnDirections, INAServerRouteResults::Directions, INAServerRouteResults::Total_Impedances