Select to view content in your preferred language

Calling Server Object Extensions or REST web services using the ArcGIS Mobile SDK

2933
1
04-02-2013 12:35 PM
ScottDickison
Deactivated User
Good afternoon,

Does anyone have any example code or can point me in the direction of some example code for calling a Server Object Extension from an ArcGIS Mobile app? I'm trying to call an existing SOE from a custom task and I'm not having any luck. What I've tried so far is using the JSON.NET JSON framework to call it with HTTPWebRequest and HTTPWebResponse which has not proven successful.

string uri = @"http://kytcmaps.******.*****.****/ArcGIS/rest/services/MeasuredRoute/MapServer/exts/KYTCGISREST/InCorpBounds";
string url = uri + string.Format("?X={0}&Y={1}&f=pjson", C.X.ToString(), C.Y.ToString());
HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(url);
request1.Timeout = 60000;
request1.Method = "GET";
string jsonString = string.Empty;
using (HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse())
{
     Stream responseStream1 = response1.GetResponseStream();
     using (StreamReader reader1 = new StreamReader(responseStream1))
     {
          jsonString = reader1.ReadToEnd();
          reader1.Close();
      }
}
CityInfo CI = JsonConvert.DeserializeObject<CityInfo>(jsonString);


Any suggestions are appreciated.

Scott Dickison
Senior Developer
GIS Support Services
Office of Information Technology
Kentucky Transportation Cabinet
200 Mero St, W4
Frankfort, KY 40622
0 Kudos
1 Reply
JosephCox
Occasional Contributor
Here is an example of how I used the System.Net.WebClient library to add a feature using JSON. I used http://json2csharp.com/ and the rest API to create an object to hold the add feature result from the server:

            
using (System.Net.WebClient client = new System.Net.WebClient())
{
     client.Headers["Content-type"] = "application/x-www-form-urlencoded";
     client.Encoding = System.Text.Encoding.UTF8;
     var collection = new System.Collections.Specialized.NameValueCollection
     {
          {"f", "json"},
          {"Token", System.Configuration.ConfigurationManager.AppSettings["TOKEN"]},
          {"features", featureParam}
     };
     byte[] response = client.UploadValues(reqUrl, "POST", collection);
     MemoryStream stream = new MemoryStream(response);
     StreamReader reader = new StreamReader(stream);
     string aRespStr = reader.ReadToEnd();

     JavaScriptSerializer jss = new JavaScriptSerializer();
     AddResults addResults = jss.Deserialize<AddResults>(aRespStr);
     if (addResults == null)
     {
          GenericError error = jss.Deserialize<GenericError>(aRespStr);
          return false;
     }
     return addResults.addResults.All(addResult=> addResult.success);
}

public class Result
{
      public int objectId { get; set; }
      public object globalId { get; set; }
      public bool success { get; set; }
      public Error error { get; set; }
}
public class AddResults
{
      public List<Result> addResults { get; set; }
}


Let me know if have any other questions. Hope this helps
0 Kudos