0

I am trying to create a simple ArcGIS Server SOAP consumer by C# like below snippet but I am getting error on NAService_NAServeras illustrated in attached image. Can you please let me know which namespace I have to use?

enter image description here

I am already using this namespaces

using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Server;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Carto;

but they are not doing the job!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Server;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Carto;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            private void SolveRoute()
        {
            // Connect to server
            NAService_NAServer naService = new NAService_NAServer();
            naService.Url = "http://localhost/ArcGIS/services/NetworkAnalysisService/MapServer/NAServer");
            //Get Route layers
            string[] routeLayers = naService.GetNALayerNames(esriNAServerLayerType.esriNAServerRouteLayer);

            // Get the default settings for the first route layer
            NAServerRouteParams naServerRouteParams = (NAServerRouteParams)naService.GetSolverParameters(routeLayers[0]);

            // Create 2 stops as property sets
            List<PropertySet> propertySets = new List<PropertySet>(2);
            propertySets.Add(CreatePropertySet("My starting point", -117.195905, 34.057783));
            propertySets.Add(CreatePropertySet("My ending point", -117.180943, 34.056286));

            // Set the property sets on a NAServerPropertySets object and set on the routeParams object
            NAServerPropertySets naServerPropertySets = new NAServerPropertySets();
            naServerPropertySets.PropertySets = propertySets.ToArray();
            naServerRouteParams.Stops = naServerPropertySets;

            // specify to return compact directions
            naServerRouteParams.ReturnCompactDirections = true;

            // Solve
            NAServerRouteResults naServerRouteResults = (NAServerRouteResults)naServer.Solve(naServerRouteParams);

            // Output directions
            NACompactStreetDirections streetDirections = naServerRouteResults.CompactDirections[0];
            StringBuilder sb = new StringBuilder();
            sb.AppendFormat("DriveTime = {0}", streetDirections.Summary.TotalDriveTime);
            sb.AppendLine();
            foreach (NACompactStreetDirection streetDirection in streetDirections.Directions)
            {
                sb.AppendLine(streetDirection.Text);
            }
            Console.WriteLine(sb.ToString());
        }

    }
    }
}

2 Answers 2

2

The namespace depends on what you defined the namespace when added the service reference.
For example:

And then the following code works for me:

private void button1_Click(object sender, EventArgs e)
{
  RouteUsingSOAP.NAServer.NAServerPortClient naService = new RouteUsingSOAP.NAServer.NAServerPortClient();
  string[] routeLayers = naService.GetNALayerNames(NAServer.esriNAServerLayerType.esriNAServerRouteLayer);
  foreach (string layerName in routeLayers) {
    listBox1.Items.Add(layerName);
  }
}
0

Looks like the NASever class was depreciated at 10.1.

At version 10.1, ArcGIS for Server no longer supports performing network analysis via local connections using the GISServer and GISClient APIs. Use the SOAP or REST API instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.