Select to view content in your preferred language

How do you determine supported operations for a service in code?

728
3
04-06-2010 07:27 AM
DeonaEvans
Emerging Contributor
When I look at the REST url for a service it tells me (at the bottom) the list of supported operations for that service, e.g., Export Map, Identify, Generate KML, etc.  Is there a way in code to determine what the supported operations are on a map service layer.  My problem is that some services have "Identify" and some do not.  I do not need to call an Identify operation for a layer that doesn't support this.  Furthermore, within that service some of the layers have "Query" capabilities and some do not.  I would like to be able to determine this via code.  Can I do this?
Thanks!
Tags (2)
0 Kudos
3 Replies
MehulChoksey
Esri Contributor
The api does not have explicit property/method to list supported operations for REST service. however,
ypu can make a HTTP call to the REST url for a service with f=json and use JSON.decode method of the api to get the flex object from which you can get the info about the supported operations.
0 Kudos
KeyurShah
Deactivated User
~ Is there a way in code to determine what the supported operations are on a map service layer

We'll be adding a "capabilities" property to the JSON response at final. It will be a comma-separated string whose value will be something like "Map,Query".

Map => export map supported
Query => find and identify supported

== Keyur
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Deona,

    Here is a working example of how to get the supported services as Mehul eludes to. This will work until the final release as Keyur mentions.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
 xmlns:mx="http://www.adobe.com/2006/mxml" 
 layout="absolute" 
 xmlns:esri="http://www.esri.com/2008/ags">
 <mx:Script>
  <![CDATA[
   import com.esri.ags.layers.*;
   import mx.rpc.http.HTTPService;
   import mx.controls.TextInput;
   import mx.rpc.AsyncResponder; 
   import mx.rpc.events.ResultEvent;
   import com.esri.serialization.json.JSON
   
   private var httpServ:HTTPService;
   private var canIdentify:Boolean = false;
   private var canFind:Boolean = false;
   private var tiledMS:Boolean = false;
   private var dynamicMS:Boolean = false;
   private var canQuery:Boolean = false;
   private var msURL:String = "";
   
   private function SendReq():void
   {
    bdyn.selected = false;
    btiled.selected = false;
    bquery.selected = false;
    bfind.selected = false;
    bident.selected = false;
    
    dynamicMS = false;
    tiledMS = false;
    canQuery = false;
    canFind = false;
    canIdentify = false;
    
    httpServ  = new HTTPService();
    msURL = "";
    
    var tSplit:Array = layURL.text.split("/");
    if(String(tSplit[tSplit.length - 1]).toLowerCase() == "mapserver")
    {
     msURL = layURL.text;
     httpServ.url = layURL.text + "?f=json";
     httpServ.addEventListener(ResultEvent.RESULT,xmlTypeResult);
     httpServ.send();
    }else if(!isNaN(Number(tSplit[tSplit.length - 1]))){
     msURL = layURL.text.replace(tSplit[tSplit.length - 1],"");
     httpServ.url = layURL.text + "/query?f=json";
     httpServ.addEventListener(ResultEvent.RESULT,canQueryResult);
     httpServ.send();
    }
   }
   
   private function canIdentResult(event:ResultEvent):void
   {
    var typeXML:Object;
    typeXML = JSON.decode(event.result.toString());
    if(typeXML.error.details[0] != "Identify operation not supported on this service")
     canIdentify = true;
    
    httpServ = new HTTPService();
    httpServ.url = msURL + "/find?f=json";
    httpServ.addEventListener(ResultEvent.RESULT,canFindResult);
    httpServ.send();
   }
   
   private function canQueryResult(event:ResultEvent):void
   {
    var typeXML:Object;
    typeXML = JSON.decode(event.result.toString());
    if(typeXML.error.details[0] != "Query operation not supported on this service")
     canQuery = true;
    
    httpServ = new HTTPService(); 
    httpServ.url = msURL + "?f=json";
    httpServ.addEventListener(ResultEvent.RESULT,xmlTypeResult);
    httpServ.send();
   }
   
   private function canFindResult(event:ResultEvent):void
   {
    var typeXML:Object;
    typeXML = JSON.decode(event.result.toString());
    if(typeXML.error.details[0] != "Find operation is not supported on this service")
     canFind = true;
     
    bdyn.selected = dynamicMS;
    btiled.selected = tiledMS;
    bquery.selected = canQuery;
    bfind.selected = canFind;
    bident.selected = canIdentify;
   }
   
   private function xmlTypeResult(event:ResultEvent):void
   {
    var typeXML:Object;
    typeXML = JSON.decode(event.result.toString());
    
    if(typeXML.hasOwnProperty("tileInfo")){
     tiledMS = true;
    } else {
     dynamicMS = true;
    }
    httpServ = new HTTPService();
    httpServ.url = msURL + "/identify?f=json";
    httpServ.addEventListener(ResultEvent.RESULT,canIdentResult);
    httpServ.send();
   }
  ]]>
 </mx:Script>
 <mx:TextInput id="layURL" x="26" y="24" width="579" text="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />
 <mx:Button x="613" y="24" label="Load..." click="SendReq()"/>
 <mx:CheckBox x="26" y="54" label="Dynamic" id="bdyn"/>
 <mx:CheckBox x="26" y="114" label="Query Supported" id="bquery"/>
 <mx:CheckBox x="26" y="144" label="Find Supported" id="bfind"/>
 <mx:CheckBox x="26" y="174" label="Identify Supported" id="bident"/>
 <mx:CheckBox x="26" y="84" label="Tiled" id="btiled"/>
</mx:Application>
0 Kudos