Monday, January 10, 2011

Calling ArcGIS Server service model

Our application manages the process of installing a site that has CAD drawings that usually don't fit in the place that it is supposed to be. For the longest time someone in our organization used to go through the process of uploading the file to a file GeoDatabase => moving, rotating the lines till they fit in the map => dissolve the line to polyline => save the polyline in the DB. She doesn't want to do that anymore because of all the trouble in the location of the CAD.

For that reason we had to make the process a part of our application.

Uploading the CAD data to lines was relatively easy and is in the post - Working with CAD files in ArcObjects.

The next step was dissolving the polylines to one polyline, and that’s where the troubles started – there are no dissolve methods in ArcObjects (I even posted a question about that in their forums but got no answers).

So after some discussion in our team we decided to go with a Geoprocessor task. We added a model to the ArcGIS server that dissolves one table to another table.

The code is fairly simple (the base for it was taken from the interactive samples for ESRI's Silverlight API):

  1. private void LoadRawCadCompleted()
  2. {
  3.     var dissolveTask = new Geoprocessor(MapApplicationConfigWrapper.Instance.DissolveCadServiceUrl);
  4.     dissolveTask.CancelAsync();
  5.     dissolveTask.JobCompleted += DissolveTask_ExecuteCompleted;
  6.     dissolveTask.Failed += DissolveTask_Failed;
  7.     dissolveTask.SubmitJobAsync(new List<GPParameter>());
  8. }

 

But I got this error back:

{ESRI.ArcGIS.Client.Tasks.ServiceException: Execute operation is not allowed on this service.}

I have tried making the service synchronic – like this guy:

image

I even called did the clear cache thing – see "Clearing ArcGIS Server REST API Cache" Post.

This (of course) didn't work!

 

The problem was:

image

The model didn't run…

(It didn’t work because it used a connection file that was on the Model’s Designer computer but not on the ArcGis Server)

 

 

Well after the problem was solved (and I changed the Execution type back to asynchronous):

image

 

I used that code and got back:

-        jobInfoEventArgs    {ESRI.ArcGIS.Client.Tasks.JobInfoEventArgs}    ESRI.ArcGIS.Client.Tasks.JobInfoEventArgs
-        base    {ESRI.ArcGIS.Client.Tasks.JobInfoEventArgs}    ESRI.ArcGIS.Client.Tasks.TaskEventArgs {ESRI.ArcGIS.Client.Tasks.JobInfoEventArgs}
+        base    {ESRI.ArcGIS.Client.Tasks.JobInfoEventArgs}    System.EventArgs {ESRI.ArcGIS.Client.Tasks.JobInfoEventArgs}
        UserState    "j5fac49ec349241759b248eb20d9a716d"    object {string}
-        JobInfo    {ESRI.ArcGIS.Client.Tasks.JobInfo}    ESRI.ArcGIS.Client.Tasks.JobInfo
        JobId    "j5fac49ec349241759b248eb20d9a716d"    string
       JobStatus    esriJobSucceeded    ESRI.ArcGIS.Client.Tasks.esriJobStatus
-        Messages    Count = 3    System.Collections.Generic.List<ESRI.ArcGIS.Client.Tasks.GPMessage>
        Capacity    4    int
        Count    3    int
-        Static members       
+        Non-Public members       
+        Non-Public members   

               

Resources:

Interactive samples for ESRI's Silverlight API

ESRI forum - Error executing Geoprocessing Service in Silverlight

 

Keywords: ESRI, ArcGIS Server, ArcGIS Manager, Job, Dissolve, Silverlight