Working with ArcXML


Summary
Once a connection to an ArcIMS Server has been established, developers can use the .NET ArcIMS application programming interface (API) classes to build and process requests and responses, or they can send Arc Extensible Markup Language (ArcXML) requests and receive ArcXML responses directly. Sending custom ArcXML requests directly to ArcIMS can be required when complete control over ArcXML content is needed.

In this topic


Sending an ArcXML request and receiving a response

The IMSServerConnection abstract base class provides the Send method for sending raw ArcXML requests to ArcIMS services. The Send method permits sending an ArcXML request to the default service type (an image service) or to a custom service type. Custom service types include Query, Geocode, and Extract. The ArcXML request types and their respective custom service types are shown in the following table:
ArcXML request type
Custom service type
GETCLIENTSERVICES
GET_SERVICE_INFO
GET_IMAGE 
""
GET_FEATURES
"Query"
GET_GEOCODE
"Geocode"
GET_EXTRACT
"Extract"
The Send method returns a string containing the ArcXML response to the ArcXML request.
The following code example shows how to send a GET_IMAGE request:
[C#]
connection.ServiceName = "world";
string getimage_request = 
    "<?xml version = \"1.0\" encoding=\"UTF-8\"?> < ARCXML version =  \
    "1.1\"><REQUEST><GET_IMAGE><PROPERTIES><ENVELOPE minx= \"-13.62\" miny =  \
    
        "33.91\" maxx= \"53.62\" maxy=\"73.33\" /><IMAGESIZE width=\"600\" height=\"400\" />  <  / PROPERTIES >  <  / GET_IMAGE >  <  / REQUEST >  <  / ARCXML > ";string response = connection.Send(getimage_request);
The following code example shows how to send a GET_FEATURES request:
[C#]
connection.ServiceName = "world";
string getfeatures_request = 
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?> < ARCXML version =  \
    "1.1\"><REQUEST><GET_FEATURES outputmode=\"xml\" > < BR >  < LAYER id =  \
    
        "1\"></LAYER><SPATIALQUERY subfields= \"NAME\" > < BR >  < SPATIALFILTER relation =  \
    "area_intersection\" > < MULTIPOINT >  < POINT x =  \
    
        "-102.31884\" y=\"62.31884\" /> <  / MULTIPOINT >  <  / SPATIALFILTER >  <  / SPATIALQUERY >  <  / GET_FEATURES >  <  / REQUEST >  <  / ARCXML > ";string response = connection.Send(getfeatures_request, "Query");

Processing an ArcXML response

Because ArcXML is based on the Extensible Markup Language (XML) standard, common XML processing tools and methods can be used to interrogate the ArcXML content. The following can be used to process an ArcXML response:
  1. Create an XML document.
  2. Load the ArcXML response into the document.
  3. Search on the ArcXML element or node.
  4. Search for an attribute value.
In the following code example, a SERVICES response is processed (GETCLIENTSERVICES is the ArcXML request). A typical SERVICES response resembles this example. In the code example, the following services are available:
  • Image Service named "world"
  • ArcMap Image Service named "north_america"
[XML]
<?xml version="1.0"?>
<ARCXML version="1.1">
  <RESPONSE>
    <SERVICES>
      <SERVICE
        name="world"
        servicegroup="ImageServer1"
        access="PUBLIC"
        type="ImageServer"
        version=""
        status="ENABLED">
        <IMAGE type="PNG8"/>
        <ENVIRONMENT>
          <LOCALE country="US" language="en" variant=""/>
          <UIFONT name="Arial"/>
        </ENVIRONMENT>
        <CLEANUP interval="20"/>
      </SERVICE>
      <SERVICE
        name="north_america"
        servicegroup="ImageServerArcMap1"
        access="PUBLIC"
        type="ImageServer"
        version="ArcMap"
        status="ENABLED">
        <IMAGE type="PNG"/>
        <CLEANUP interval="20"/>
      </SERVICE>
    </SERVICES>
  </RESPONSE>
</ARCXML>
This response is loaded into an XML document. A reference to the System.XML namespace must be made to parse an XML document. The document is then searched for on all SERVICE nodes. For each SERVICE node, a search is made for the name attribute value as shown in the following code example:
[C#]
XmlDocument doc = new XmlDocument();
doc.LoadXml(response);
XmlElement root = doc.DocumentElement;
XmlNodeList nodelist = root.GetElementsByTagName("SERVICE");
foreach (XmlNode node in nodelist)
{
    string name = node.Attributes["name"].InnerXml;
}