C# code examples for proxy methods

This page contains C# code examples for ArcGIS Server SOAP proxy class methods. The samples apply to both desktop and web applications. By default, the name for the SOAP proxy class is the name of the service used to generate it plus the service type. For example, if a SOAP proxy class is generated dynamically using a map service named NorthAmerica, the proxy class name will be NorthAmerica_MapServer. For the purposes of the example code, the proxy class names will use the service type (e.g. the map service proxy class will be named MapService_MapServer).

Catalog

GetFolders

Catalog catalog = new Catalog();

catalog.Url = "http://localhost:6080/arcgis/services";

string[] folders = catalog.GetFolders();

for (int index = 0; index < folders.Length; index++)

{

      string >foldername = folders[index];

}

GetMessageFormats

Catalog catalog = new Catalog();

catalog.Url = "http://localhost:6080/arcgis/services";

esriServiceCatalogMessageFormat messageformat = catalog.GetMessageFormats();

GetMessageVersion

Catalog catalog = new Catalog();

catalog.Url = "http://localhost:6080/arcgis/services";

esriArcGISVersion arcgisversion = catalog.GetMessageVersion();

GetServiceDescriptions

Catalog catalog = new Catalog();

catalog.Url = "http://localhost:6080/arcgis/services";

ServiceDescription[] servicedescriptions = catalog.GetServiceDescriptions();

foreach (ServiceDescription servicedesc in servicedescriptions)

{

      string name = servicedesc.Name;

      string type = servicedesc.Type;

      string parenttype = servicedesc.ParentType;

      string capabilities = servicedesc.Capabilities;

      string url = servicedesc.Url;

}

GetServiceDescriptionsEx

Catalog catalog = new Catalog();

catalog.Url = "http://localhost:6080/arcgis/services";

ServiceDescription[] servicedescriptions = catalog.GetServiceDescriptionsEx("SecureDirectory");

foreach (ServiceDescription servicedesc in servicedescriptions)

{

      string name = servicedesc.Name;

      string type = servicedesc.Type;

      string parenttype = servicedesc.ParentType;

      string capabilities = servicedesc.Capabilities;

      string url = servicedesc.Url;

}

GetTokenServiceURL

Catalog catalog = new Catalog();

catalog.Url = "http://localhost:6080/arcgis/services";

 

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

 

string tokenurl = catalog.GetTokenServiceURL();

string tokenrequesturl = tokenurl + "?request=getToken&username=myuser&password=secret";

 

System.Net.WebRequest request = System.Net.WebRequest.Create(tokenrequesturl);

System.Net.WebResponse response = request.GetResponse();

 

System.IO.Stream responseStream = response.GetResponseStream();

System.IO.StreamReader readStream = new System.IO.StreamReader(responseStream);

 

string myToken = readStream.ReadToEnd();

mapservice.Url = mapservice.Url + "?token=" + myToken;

 

string mapname = mapservice.GetDefaultMapName();

RequiresTokens

Catalog catalog = new Catalog();

catalog.Url = "http://localhost:6080/arcgis/services";

 

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

if (catalog.RequiresTokens()

{

      string tokenurl = catalog.GetTokenServiceURL();

      string tokenrequesturl = tokenurl + "?request=getToken&username=myuser&password=secret";

 

      System.Net.WebRequest request = System.Net.WebRequest.Create(tokenrequesturl);

      System.Net.WebResponse response = request.GetResponse();

      System.IO.Stream responseStream = response.GetResponseStream();

      System.IO.StreamReader readStream = new System.IO.StreamReader(responseStream);

      string myToken = readStream.ReadToEnd();
      
      mapservice.Url = mapservice.Url + "?token=" + myToken;

}

 

string mapname = mapservice.GetDefaultMapName();

GeocodeServer

FindAddressCandidates

GeocodeService_GeocodeServer geocodeservice = new GeocodeService_GeocodeServer();

geocodeservice.Url = "http://localhost:6080/arcgis/services/GeocodeService/GeocodeServer";

 

Fields fields = geocodeservice.GetAddressFields();

PropertySet address = new PropertySet();

PropertySetProperty[] inputfields = new PropertySetProperty[fields.FieldArray.Length];

 

for (int index = 0; index < fields.FieldArray.Length; index++)

{

      Field field = fields.FieldArray[index];

      PropertySetProperty property = new PropertySetProperty();

      property.Key = field.Name;

 

      switch (field.Name.ToUpper())

      {

            case "STREET":

                  property.Value = "5000 Magnolia Ave.";

                  break;

            case "ZONE":

                  property.Value = "92506";

                  break;

      }

 

      inputfields.SetValue(property, index);

}

address.PropertyArray = inputfields;

PropertySet propertymods = geocodeservice.GetLocatorProperties();

PropertySetProperty[] locatorArray = propertymods.PropertyArray;

// Change locator property value

for (int index = 0; index < locatorArray.Length; index++)

{

      PropertySetProperty property = locatorArray[index];

      switch (property.Key)

      {

            case "MinimumCandidateScore":

                  property.Value = "80";

                  break;

      }

}

 

RecordSet candidates = geocodeservice.FindAddressCandidates(address, null);

 

if (candidates != null)

{

      string fieldsoutput = string.Empty;

      foreach (Field field in candidates.Fields.FieldArray)

      {

            fieldsoutput += field.Name;

      }

      foreach (Record record in candidates.Records)

      {

            string valuesoutput = string.Empty;

            object[] values = record.Values;

            int v = 0;

 

            foreach (Field field in candidates.Fields.FieldArray)

            {

                  valuesoutput += values[v].ToString();

                  v++;

            }

      }

}

GeocodeAddress

GeocodeService_GeocodeServer geocodeservice = new GeocodeService_GeocodeServer();

geocodeservice.Url = "http://localhost:6080/arcgis/services/GeocodeService/GeocodeServer";

 

// Define address inputs

PropertySet geocodePropSet = new PropertySet();

PropertySetProperty[] propArray = new PropertySetProperty[2];

PropertySetProperty geocodeProp = new PropertySetProperty();

 

geocodeProp.Key = "Street";

// Intersection

//geocodeProp.Value = "Magnolia & Central"

// Address

geocodeProp.Value = "5950 Magnolia Avenue";

propArray[0] = geocodeProp;

 

PropertySetProperty geocodeProp1 = new PropertySetProperty();

geocodeProp1.Key = "Zone";

geocodeProp1.Value = "92506";

propArray[1] = geocodeProp1;

 

geocodePropSet.PropertyArray = propArray;

 

// Geocode address

PropertySet results = geocodeservice.GeocodeAddress(geocodePropSet, null);

PropertySetProperty[] resultsArray = results.PropertyArray;

PointN geocodePoint = null;

 

foreach (PropertySetProperty result in resultsArray)

{

      string val = result.Key.ToString();

      if (result.Key == "Shape")

      {

            geocodePoint = result.Value as PointN;

            double x = geocodePoint.X;

            double y = geocodePoint.Y;

      }

}

GeocodeAddresses

namespace SOAP_Samples.GeocodeService
{
  public partial class World_GeocodeServer
  {
    // Override the GetWebRequest method of the Web Reference to additionally
    // pass in the referer used to generate the token
    protected override System.Net.WebRequest GetWebRequest(Uri uri)
    {
      System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)base.GetWebRequest(uri);
      webRequest.Referer = "myReferer";
      return webRequest;
    }
  }
}

namespace SOAP_Samples
{
  

  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }



    private void button1_Click(object sender, EventArgs e)
    {
      GeocodeAddresses();
    }
    
    private void GeocodeAddresses()
    {
      string username = "org_username";
      string password = "org_password";
      string referer = "myReferer";

      // Get token service
      string tokenServiceURL;
      HttpWebRequest request = (HttpWebRequest)HttpWebRequest.CreateDefault(new Uri("http://geocode.arcgis.com/arcgis/rest/info?f=pjson"));
      HttpWebResponse response = (HttpWebResponse)request.GetResponse();
      Stream responseStream = response.GetResponseStream();
      using (StreamReader reader = new StreamReader(responseStream))
      {
        string responseText = reader.ReadToEnd();

        int startPos = responseText.IndexOf("tokenServicesUrl") + 20;
        int endPos = responseText.IndexOf("\"", startPos);
        tokenServiceURL = responseText.Substring(startPos, endPos - startPos);

        reader.Close();
      }
      responseStream.Close();
      response.Close();

      // Get token
      string token;
      request = (HttpWebRequest)HttpWebRequest.CreateDefault(new Uri(tokenServiceURL + "?f=json&expiration=60" + 
		              "&username=" + username + "&password=" + password + "&referer=" + referer));
      response = (HttpWebResponse)request.GetResponse();
      responseStream = response.GetResponseStream();
      using (StreamReader reader = new StreamReader(responseStream))
      {
        string responseText = reader.ReadToEnd();
        if ((responseText.Length == 0) || (responseText.IndexOf("error") > -1))
        {
          MessageBox.Show("Error getting token.");
          return;
        }

        int startPos = 12;
        int endPos = responseText.IndexOf("\"", startPos);
        token = responseText.Substring(startPos, endPos - startPos);

        reader.Close();
      }
      responseStream.Close();
      response.Close();


      // Setup geocoding service with new token
      World_GeocodeServer geocodeservice = new World_GeocodeServer();
      geocodeservice.Url = "http://geocode.arcgis.com/arcgis/services/World/GeocodeServer?token=" + token;


      // Create property set to map locator address fields (key) to fields in the input
      // address table (value).  In this example they are the same.
      PropertySet geocodePropSet = new PropertySet();
      PropertySetProperty[] propArray = new PropertySetProperty[2];

      PropertySetProperty geocodeProp = new PropertySetProperty();
      geocodeProp.Key = "Address";
      geocodeProp.Value = "Address";
      propArray[0] = geocodeProp;
      
      PropertySetProperty geocodeProp1 = new PropertySetProperty();
      geocodeProp1.Key = "Postal";
      geocodeProp1.Value = "Postal";
      propArray[1] = geocodeProp1;

      geocodePropSet.PropertyArray = propArray;

      // Create a new recordset to store input addresses to be batch geocoded
      RecordSet addressTable = new RecordSet();
      Field[] fieldarray = new Field[3];

      // Following field properties are required for batch geocode to work:
      // Length, Name, Type.  There also needs to be a field of type OID.
      Field field0 = new Field();
      field0.Name = "OID";
      field0.Type = esriFieldType.esriFieldTypeOID;
      field0.Length = 50;
      fieldarray[0] = field0;
      
      Field field1 = new Field();
      field1.Name = "Address";
      field1.Type = esriFieldType.esriFieldTypeString;
      field1.Length = 50;
      fieldarray[1] = field1;
      
      Field field2 = new Field();
      field2.Name = "Postal";
      field2.Type = esriFieldType.esriFieldTypeString;
      field2.Length = 50;
      fieldarray[2] = field2;
      
      Fields fields = new Fields();
      fields.FieldArray = fieldarray;
      addressTable.Fields = fields;
      
      // Add records to input address table
      Record[] records = new Record[2];
      
      Record record1 = new Record();
      record1.Values = new object[3] { 0, "5950 Magnolia Ave.", "92506" };
      records[0] = record1;
      
      Record record2 = new Record();
      record2.Values = new object[3] { 1, "5962 Magnolia Ave.", "92506" };
      records[1] = record2;
      
      addressTable.Records = records;

      // Make the request to the geocoding service to geocode the addresses
      RecordSet results = geocodeservice.GeocodeAddresses(addressTable, geocodePropSet, null);

      // Output the results
      if (results != null)
      {
        StringBuilder sb = new StringBuilder();
        string valuesoutput = string.Empty;
        foreach (Record record in results.Records)
        {
          foreach (object value in record.Values)
          {
            sb.Append(value);
            sb.Append("\t");
          }
          sb.AppendLine();
        }
        MessageBox.Show(sb.ToString());
      }
    }
  }
}

GetAddressFields

GeocodeService_GeocodeServer geocodeservice = new GeocodeService_GeocodeServer();

geocodeservice.Url = "http://localhost:6080/arcgis/services/GeocodeService/GeocodeServer";

 

Fields addressfields = geocodeservice.GetAddressFields();

 

foreach (Field addressfield in addressfields.FieldArray)

{

      // Input field name

      System.Diagnostics.Debug.WriteLine("Name: " + addressfield.Name);

      // Descriptive name

      System.Diagnostics.Debug.WriteLine("Alias Name: " + addressfield.AliasName);

      // Is required?

      System.Diagnostics.Debug.WriteLine("Required: " + addressfield.Required.ToString());

      // Data type

      System.Diagnostics.Debug.WriteLine("Type: " + addressfield.Type.ToString());

}

GetCandidateFields

GeocodeService_GeocodeServer geocodeservice = new GeocodeService_GeocodeServer();

geocodeservice.Url = "http://localhost:6080/arcgis/services/GeocodeService/GeocodeServer";

 

PropertySet propertymods = geocodeservice.GetLocatorProperties();

 

Fields candidatefields = geocodeservice.GetCandidateFields(propertymods);

foreach (Field candidatefield in candidatefields.FieldArray)

{

      // Descriptive name

      System.Diagnostics.Debug.WriteLine("Alias Name: " + candidatefield.AliasName);

      // Input field name

      System.Diagnostics.Debug.WriteLine("Name: " + candidatefield.Name);

      // Is required?

      System.Diagnostics.Debug.WriteLine("Required: " + candidatefield.Required.ToString());

      // Data type

      System.Diagnostics.Debug.WriteLine("Type: " + candidatefield.Type.ToString());

}

GetDefaultInputFieldMapping

GeocodeService_GeocodeServer geocodeservice = new GeocodeService_GeocodeServer();

geocodeservice.Url = "http://localhost:6080/arcgis/services/GeocodeService/GeocodeServer";

 

PropertySet fieldmapproperties = geocodeservice.GetDefaultInputFieldMapping();

PropertySetProperty[] fieldmaparray = fieldmapproperties.PropertyArray;

 

foreach (PropertySetProperty fieldmapproperty in fieldmaparray)

{

      System.Diagnostics.Debug.WriteLine(fieldmapproperty.Key.ToString());

      System.Diagnostics.Debug.WriteLine(fieldmapproperty.Value.ToString());

}

GetIntersectionCandidateFields

GeocodeService_GeocodeServer geocodeservice = new GeocodeService_GeocodeServer();

geocodeservice.Url = "http://localhost:6080/arcgis/services/GeocodeService/GeocodeServer";

 

PropertySet propertymods = geocodeservice.GetLocatorProperties();

 

Fields candidatefields = geocodeservice.GetIntersectionCandidateFields(propertymods);

 

foreach (Field candidatefield in candidatefields.FieldArray)

{

      // Descriptive name

      System.Diagnostics.Debug.WriteLine("Alias Name: " + candidatefield.AliasName);

      // Input field name

      System.Diagnostics.Debug.WriteLine("Name: " + candidatefield.Name);

      // Is required?

      System.Diagnostics.Debug.WriteLine("Required: " + candidatefield.Required.ToString());

      // Data type

      System.Diagnostics.Debug.WriteLine("Type: " + candidatefield.Type.ToString());

}

GetLocatorProperties

GeocodeService_GeocodeServer geocodeservice = new GeocodeService_GeocodeServer();

geocodeservice.Url = "http://localhost:6080/arcgis/services/GeocodeService/GeocodeServer";

 

PropertySet locatorProperties = geocodeservice.GetLocatorProperties();

PropertySetProperty[] locatorArray = locatorProperties.PropertyArray;

 

// Display locator properties and default values

foreach (PropertySetProperty locatorProperty in locatorArray)

{

      System.Diagnostics.Debug.WriteLine(locatorProperty.Key.ToString());

      System.Diagnostics.Debug.WriteLine(locatorProperty.Value.ToString());

}

 

// Change locator property value

for (int index = 0; index < locatorArray.Length; index++)

{

      PropertySetProperty property = locatorArray[index];

      switch (property.Key)

      {

      case "MinimumMatchScore":

            property.Value = "50";

            break;

      case "MinimumCandidateScore":

            property.Value = "50";

            break;

      }

}

GetResultFields

GeocodeService_GeocodeServer geocodeservice = new GeocodeService_GeocodeServer();

geocodeservice.Url = "http://localhost:6080/arcgis/services/GeocodeService/GeocodeServer";

 

PropertySet propertymods = geocodeservice.GetLocatorProperties();

 

Fields candidatefields = geocodeservice.GetResultFields(propertymods);

 

foreach (Field candidatefield in candidatefields.FieldArray)

{

      // Descriptive name

      System.Diagnostics.Debug.WriteLine("Alias Name: " + candidatefield.AliasName);

      // Input field name

      System.Diagnostics.Debug.WriteLine("Name: " + candidatefield.Name);

      // Is required?

      System.Diagnostics.Debug.WriteLine("Required: " + candidatefield.Required.ToString());

      // Data type

      System.Diagnostics.Debug.WriteLine("Type: " + candidatefield.Type.ToString());

}

GetStandardizedFields

GeocodeService_GeocodeServer geocodeservice = new GeocodeService_GeocodeServer();

geocodeservice.Url = "http://localhost:6080/arcgis/services/GeocodeService/GeocodeServer";

 

Fields standardizedfields = geocodeservice.GetStandardizedFields();

foreach (Field standardfield in standardizedfields.FieldArray)

{

      // Descriptive name

      System.Diagnostics.Debug.WriteLine("Alias Name: " + standardfield.AliasName);

      // Input field name

      System.Diagnostics.Debug.WriteLine("Name: " + standardfield.Name);

      // Is required?

      System.Diagnostics.Debug.WriteLine("Required: " + standardfield.Required.ToString());

      // Data type

      System.Diagnostics.Debug.WriteLine("Type: " + standardfield.Type.ToString());

}

 

// Define address inputs

PropertySet stnGeocodePropSet = new PropertySet();

PropertySetProperty[] stnPropArray = new PropertySetProperty[5];

 

PropertySetProperty stngeocodeProp = new PropertySetProperty();

stngeocodeProp.Key = "AHN";

stngeocodeProp.Value = "5950";

stnPropArray[0] = stngeocodeProp;

 

PropertySetProperty stngeocodeProp1 = new PropertySetProperty();

stngeocodeProp1.Key = "ASN";

stngeocodeProp1.Value = "Magnolia";

stnPropArray[1] = stngeocodeProp1;

 

PropertySetProperty stngeocodeProp2 = new PropertySetProperty();

stngeocodeProp2.Key = "AST";

stngeocodeProp2.Value = "AVE";

stnPropArray[2] = stngeocodeProp2;

 

PropertySetProperty stngeocodeProp3 = new PropertySetProperty();

stngeocodeProp3.Key = "AZN";

stngeocodeProp3.Value = "92506";

stnPropArray[3] = stngeocodeProp3;

 

PropertySetProperty stngeocodeProp4 = new PropertySetProperty();

stngeocodeProp4.Key = "Addr_type";

stngeocodeProp4.Value = "A";

stnPropArray[4] = stngeocodeProp4;

 

stnGeocodePropSet.PropertyArray = stnPropArray;

PropertySet stnpropertyset = geocodeservice.GeocodeAddress(stnGeocodePropSet, null);

GetStandardizedIntersectionFields

GeocodeService_GeocodeServer geocodeservice = new GeocodeService_GeocodeServer();

geocodeservice.Url = "http://localhost:6080/arcgis/services/GeocodeService/GeocodeServer";

 

Fields standardizedfields = geocodeservice.GetStandardizedIntersectionFields();

foreach (Field standardfield in standardizedfields.FieldArray)

{

      // Descriptive name

      System.Diagnostics.Debug.WriteLine("Alias Name: " + standardfield.AliasName);

      // Input field name

      System.Diagnostics.Debug.WriteLine("Name: " + standardfield.Name);

      // Is required?

      System.Diagnostics.Debug.WriteLine("Required: " + standardfield.Required.ToString());

      // Data type

      System.Diagnostics.Debug.WriteLine("Type: " + standardfield.Type.ToString());

}

ReverseGeocode

GeocodeService_GeocodeServer geocodeservice = new GeocodeService_GeocodeServer();

geocodeservice.Url = "http://localhost:6080/arcgis/services/GeocodeService/GeocodeServer";

 

// Set reverse geocode search parameters

PropertySetProperty revGeocodeProp = new PropertySetProperty();

revGeocodeProp.Key = "ReverseDistanceUnits";

revGeocodeProp.Value = "Meters";

 

PropertySetProperty revGeocodeProp1 = new PropertySetProperty();

revGeocodeProp1.Key = "ReverseDistance";

revGeocodeProp1.Value = "100";

 

// Optionally define output spatial reference for reverse geocoded point

ProjectedCoordinateSystem projectedCoordinateSystem = new ProjectedCoordinateSystem();

projectedCoordinateSystem.WKID = 54004;

projectedCoordinateSystem.WKIDSpecified = true;

 

PropertySetProperty revGeocodeProp2 = new PropertySetProperty();

revGeocodeProp2.Key = "OutputSpatialReference";

revGeocodeProp2.Value = class=codesample>projectedCoordinateSystem;

PropertySetProperty[] propArray = new PropertySetProperty[] {revGeocodeProp, revGeocodeProp1, revGeocodeProp2 };

 

PropertySet revGeocodePropSet = new PropertySet();

revGeocodePropSet.PropertyArray = propArray;

 

// Create point to reverse geocode, define input spatial reference

PointN inputPoint = new PointN();

inputPoint.X = -117.391;

inputPoint.Y = 33.961;

 

GeographicCoordinateSystem geographicCoordinateSystem = new GeographicCoordinateSystem();

geographicCoordinateSystem.WKID = 4326;

geographicCoordinateSystem.WKIDSpecified = true;

inputPoint.SpatialReference = geographicCoordinateSystem;

 

// Reverse geocode

PropertySet results = geocodeservice.ReverseGeocode(inputPoint, false, revGeocodePropSet);// Iterate through results

PropertySetProperty[] resultsArray = results.PropertyArray;

 

// For each result, print address and matched point

foreach (PropertySetProperty result in resultsArray)

{

      System.Diagnostics.Debug.WriteLine(result.Key.ToString());

      if (result.Value is PointN)

      {

      PointN pn = (PointN)result.Value;

      System.Diagnostics.Debug.WriteLine(pn.X + ", " + pn.Y);

      }

      else

      {

      System.Diagnostics.Debug.WriteLine(result.Value.ToString());

      }

}

StandardizeAddress

GeocodeService_GeocodeServer geocodeservice = new GeocodeService_GeocodeServer();

geocodeservice.Url = "http://localhost:6080/arcgis/services/GeocodeService/GeocodeServer";

 

// Define address inputs

PropertySet geocodePropSet = new PropertySet();

PropertySetProperty[] propArray = new PropertySetProperty[2];

 

PropertySetProperty geocodeProp = new PropertySetProperty();

geocodeProp.Key = "Street";

geocodeProp.Value = "5950 Magnolia Ave.";

propArray[0] = geocodeProp;

 

PropertySetProperty geocodeProp1 = new PropertySetProperty();

geocodeProp1.Key = "Zone";

geocodeProp1.Value = "92506";

propArray[1] = geocodeProp1;

 

geocodePropSet.PropertyArray = propArray;

 

PropertySet standardizedAddress = geocodeservice.StandardizeAddress(geocodePropSet, null);

PropertySetProperty[] standardArray = standardizedAddress.PropertyArray;

 

foreach (PropertySetProperty result in standardArray)

{

      System.Diagnostics.Debug.WriteLine(result.Key.ToString());

      System.Diagnostics.Debug.WriteLine(result.Value.ToString()); class=codesample>=

}

GeoDataServer

GetDefaultWorkingVersion

GeodataService_GeodataServer geodataservice = new GeodataService_GeodataServer();

geodataservice.Url = "http://localhost:6080/arcgis/services/GeodataService/GeodataServer";

 

string defaultversionname = geodataservice.GetDefaultWorkingVersion();

GetMaxRecordCount

GeodataService_GeodataServer geodataservice = new GeodataService_GeodataServer();

geodataservice.Url = "http://localhost:6080/arcgis/services/GeodataService/GeodataServer";

 

int maxrecordcount = geodataservice.GetMaxRecordCount();

GetVersions

GeodataService_GeodataServer geodataservice = new GeodataService_GeodataServer();

geodataservice.Url = "http://localhost:6080/arcgis/services/GeodataService/GeodataServer";

try

{

      GPVersionInfo[] gpversioninfos = geodataservice.GetVersions();

      foreach (GPVersionInfo gpvi in gpversioninfos)

      {

            string versionname = gpvi.VersionName;

            esriVersionAccess access = gpvi.Access;

      }

}

// If not an ArcSDE geodatabase, "Error processing server request" will be returned.

catch (System.Web.Services.Protocols.SoapException soapex)

{

      string message = soapex.Message;

}

catch (Exception ex) { }

finally

{

      geodataservice.Dispose();

}

GetWrappedWorkspaceType

GeodataService_GeodataServer geodataservice = new GeodataService_GeodataServer();

geodataservice.Url = "http://localhost:6080/arcgis/services/GeodataServiceLocal/GeodataServer"; 

esriWorkspaceType workspacetype = geodataservice.GetWrappedWorkspaceType();

GeometryServer

Buffer

Geometry_GeometryServer geometryService = new Geometry_GeometryServer();

geometryService.Url = "http://localhost:6080/arcgis/services/Geometry/GeometryServer"; 

SpatialReference inputSpatialReference = new GeographicCoordinateSystem();

inputSpatialReference.WKT = "GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]";

 

SpatialReference bufferSpatialReference = new ProjectedCoordinateSystem();

// USA_Contiguous_Lambert_Conformal_Conic

bufferSpatialReference.WKID = 102004;

bufferSpatialReference.WKIDSpecified = true;

 

SpatialReference outputSpatialReference = inputSpatialReference;

 

PointN inputPoint1 = new PointN();

inputPoint1.X = -120;

inputPoint1.Y = 45;

PointN inputPoint2 = new PointN();

inputPoint2.X = -110;

inputPoint2.Y = 40;

Geometry[] inputGeometry = new Geometry[] { inputPoint1, inputPoint2 };

 

double[] distances = new double[] {200, 400 };

 

LinearUnit linearUnit = new LinearUnit();

// US survey mile

linearUnit.WKID = 9035;

linearUnit.WKIDSpecified = true;

 

bool unionResults = false;

 

Geometry[] outputGeometry = geometryService.Buffer(inputSpatialReference, bufferSpatialReference, outputSpatialReference,

distances, linearUnit, unionResults, inputGeometry);

Densify

Geometry_GeometryServer geometryService = new Geometry_GeometryServer();

geometryService.Url = "http://localhost:6080/arcgis/services/Geometry/GeometryServer"; 

SpatialReference inputSpatialReference = new wsgeometry.ProjectedCoordinateSystem();

// World Mercator

inputSpatialReference.WKID = 54004;

inputSpatialReference.WKIDSpecified = true;

 

PointN pnt1 = new PointN();

pnt1.X = 500000;

pnt1.Y = 500000;

PointN pnt2 = new PointN();

pnt2.X = 600000;

pnt2.Y = 500000;

PointN pnt3 = new PointN();

pnt3.X = 700000;

pnt3.Y = 500000;

PointN[] pntarray1 = new PointN[] { pnt1, pnt2, pnt3 };

 

Path inputPath = new Path();

inputPath.PointArray = pntarray1;

Path[] paths = new Path[] { inputPath };

PolylineN inputPolyline = new PolylineN();

inputPolyline.PathArray = paths;

 

Geometry[] inputGeometry = new Geometry[] { inputPolyline };

 

double maxSegmentLength = 10000;

 

bool useDeviationDensification = false;

 

double densificationParam = 0;

 

Geometry[] outputGeometry = geometryService.Densify(inputSpatialReference, inputGeometry, maxSegmentLength,

useDeviationDensification, densificationParam);

FindSRByWKID

Geometry_GeometryServer geometryService = new Geometry_GeometryServer();

geometryService.Url = "http://localhost:6080/arcgis/services/Geometry/GeometryServer"; 

// Geographic WGS84

SpatialReference outputSpatialReference = geometryService.FindSRByWKID("EPSG", 4326, -1, true, true);

 

bool isHighPrecision = outputSpatialReference.HighPrecision;

FindSRByWKT

Geometry_GeometryServer geometryService = new Geometry_GeometryServer();

geometryService.Url = "http://localhost:6080/arcgis/services/Geometry/GeometryServer";

 

// Geographic WGS84

SpatialReference outputSpatialReference = geometryService.FindSRByWKT("GEOGCS[\"GCS_WGS_1984\", DATUM[\"D_WGS_1984\", SPHEROID[\"WGS_1984\",6378137.0,298.257223563]], PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]]", "", true, true);

 

int predefinedWKID = outputSpatialReference.WKID;

FindUnitsByWKID

Geometry_GeometryServer geometryService = new Geometry_GeometryServer();

geometryService.Url = "http://localhost:6080/arcgis/services/Geometry/GeometryServer";

 

// International Meter

LinearUnit linearUnit = (LinearUnit) geometryService.FindUnitsByWKID("EPSG", 9001);

FindUnitsByWKT

Geometry_GeometryServer geometryService = new Geometry_GeometryServer();

geometryService.Url = "http://localhost/arcgis/services/Geometry/GeometryServer";

 

// International Meter

LinearUnit linearUnit = (LinearUnit)geometryService.FindUnitsByWKT("UNIT[\"Meter\",1.0,AUTHORITY[\"EPSG\",9001]]");

GetAreasAndLengths

Geometry_GeometryServer geometryService = new Geometry_GeometryServer();

geometryService.Url = "http://localhost:6080/arcgis/services/Geometry/GeometryServer";

 

SpatialReference inputSpatialReference = geometryService.FindSRByWKID("EPSG", 54004, -1, true, true);

 

// New PointN array

PointN pnt1 = new PointN();

pnt1.X = 100000;

pnt1.Y = 300000;

PointN pnt2 = new PointN();

pnt2.X = 100000;

pnt2.Y = 350000;

PointN pnt3 = new PointN();

pnt3.X = 900000;

pnt3.Y = 350000;

PointN[] pnts1 = new PointN[] { pnt1, pnt2, pnt3};

 

// New PolylineN

Path path1 = new Path();

path1.PointArray = pnts1;

Path[] paths = new Path[] { path1 };

PolylineN polylinen = new PolylineN();

polylinen.PathArray = paths;

 

// New PolygonN

Ring ring1 = new Ring();

ring1.PointArray = pnts1;

Ring[] rings = new Ring[] { ring1 }; class=codesample>PolygonN polygonn = new PolygonN();

polygonn.RingArray = rings;

PolygonN[] polygonArray = new PolygonN[] { polygonn };

 

double[] lengths = null;

double[] areas = geometryService.GetAreasAndLengths(inputSpatialReference, polygonArray, out lengths);

GetLabelPoints

Geometry_GeometryServer geometryService = new Geometry_GeometryServer();

geometryService.Url = "http://localhost:6080/arcgis/services/Geometry/GeometryServer";

 

// GCS-NAD83

SpatialReference inputSpatialReference = geometryService.FindSRByWKID("EPSG", 4269, -1, true, true);

 

PointN pnt1 = new PointN();

pnt1.X = 10.0;

pnt1.Y = 30.0;

PointN pnt2 = new PointN();

pnt2.X = 10.0;

pnt2.Y = 40.0;

PointN pnt3 = new PointN();

pnt3.X = 20.0;

pnt3.Y = 40.0;

PointN pnt4 = new PointN();

pnt4.X = 20.0;

pnt4.Y = 30.0;

PointN pnt5 = new PointN();

pnt5.X = 10.0;

pnt5.Y = 30.0;

 

PointN[] pnts1 = new PointN[] { pnt1, pnt2, pnt3, pnt4, pnt5 };

Ring ring1 = new Ring();

ring1.PointArray = pnts1;

Ring[] rings = new Ring[] { ring1 };

 

PolygonN polygonn = new PolygonN();

polygonn.RingArray = rings;

PolygonN[] polygonArray = new PolygonN[] { polygonn };

 

Point[] labelPoints = (Point[])geometryService.GetLabelPoints(inputSpatialReference, polygonArray);

GetLengths

Geometry_GeometryServer geometryService = new Geometry_GeometryServer();

geometryService.Url = "http://localhost:6080/arcgis/services/Geometry/GeometryServer";

 

SpatialReference inputSpatialReference = geometryService.FindSRByWKID("EPSG", 54004, -1, true, true);

 

// New PointN array

PointN pnt1 = new PointN();

pnt1.X = 100000;

pnt1.Y = 300000;

PointN pnt2 = new PointN();

pnt2.X = 100000;

pnt2.Y = 350000;

PointN pnt3 = new PointN();

pnt3.X = 900000;

pnt3.Y = 350000;

PointN[] pnts1 = new PointN[] { pnt1, pnt2, pnt3 };

 

// New PolylineN

Path path1 = new Path();

path1.PointArray = pnts1;

Path[] paths = new Path[] { path1 };

 

PolylineN polylinen = new PolylineN();

polylinen.PathArray = paths;

PolylineN[] polylineArray = new PolylineN[] { polylinen };

 

double[] lengths = geometryService.GetLengths(inputSpatialReference, polylineArray);

Project

Geometry_GeometryServer geometryService = new Geometry_GeometryServer();

geometryService.Url = "http://localhost:6080/arcgis/services/Geometry/GeometryServer";

 

SpatialReference inputSpatialReference = new GeographicCoordinateSystem();

inputSpatialReference.WKID = 4326;

inputSpatialReference.WKIDSpecified = true;

 

SpatialReference outputSpatialReference = new ProjectedCoordinateSystem();

// USA_Contiguous_Lambert_Conformal_Conic

outputSpatialReference.WKID = 102004;

outputSpatialReference.WKIDSpecified = true;

 

PointN pnt1 = new PointN();

pnt1.X = -120;

pnt1.Y = 50;

PointN pnt2 = new PointN();

pnt2.X = -110;

pnt2.Y = 40;

PointN pnt3 = new PointN();

pnt3.X = -130;

pnt3.Y = 40;

PointN[] pnts1 = new PointN[] { pnt1, pnt2, pnt3 };

 

Path path1 = new Path();

path1.PointArray = pnts1;

Path[] paths = new Path[] { path1 };

PolylineN polylinen = new PolylineN();

polylinen.PathArray = paths;

 

Ring ring1 = new Ring();

ring1.PointArray = pnts1;

Ring[] rings = new Ring[] { ring1 };

PolygonN polygonn = new PolygonN();

polygonn.RingArray = rings;

 

Geometry[] inputGeometry = new Geometry[] { pnt1, polylinen, polygonn };

 

bool transformForward = false;

 

GeoTransformation transformation = new GeoTransformation();

// NAD1983_To_WGS1984_1

transformation.WKID = 1188;

transformation.WKIDSpecified = true;

 

EnvelopeN extent = null;

 

Geometry[] outputGeometry = geometryService.Project(inputSpatialReference, outputSpatialReference, transformForward,transformation, extent, inputGeometry);

Relation

Geometry_GeometryServer geometryService = new Geometry_GeometryServer();

geometryService.Url = "http://localhost:6080/arcgis/services/Geometry/GeometryServer";

 

SpatialReference inputSpatialReference = new GeographicCoordinateSystem();

inputSpatialReference.WKID = 4326;

inputSpatialReference.WKIDSpecified = true;

 

// First input geometry array - 1 polygon

PointN pnt1a = new PointN();

pnt1a.X = 10.0;

pnt1a.Y = 30.0;

PointN pnt2a = new PointN();

pnt2a.X = 10.0;

pnt2a.Y = 45.0;

PointN pnt3a = new PointN();

pnt3a.X = 25.0;

pnt3a.Y = 45.0;

PointN pnt4a = new PointN();

pnt4a.X = 25.0;

pnt4a.Y = 30.0;

PointN pnt5a = new PointN();

pnt5a.X = 10.0;

pnt5a.Y = 30.0;

PointN[] pnts1a = new PointN[] { pnt1a, pnt2a, pnt3a, pnt4a, pnt5a };

 

Ring ring1 = new Ring();

ring1.PointArray = pnts1a;

Ring[] rings = new Ring[] { ring1 };

 

PolygonN polygon1 = new PolygonN();

polygon1.RingArray = rings;

normal;">Geometry[] inputGeometry1 = new Geometry[] { polygon1 };

 

// Second input geometry array - 3 points

PointN pnt1b = new PointN();

pnt1b.X = 20.0;

pnt1b.Y = 40.0;

PointN pnt2b = new PointN();

pnt2b.X = 10.0;

pnt2b.Y = 30.0;

PointN pnt3b = new PointN();

pnt3b.X = 50.0;

pnt3b.Y = 50.0;

 

Geometry[] inputGeometry2 = new Geometry[3];

// Inside polygon

inputGeometry2.SetValue(pnt1b, 0);

// Edge of polygon

inputGeometry2.SetValue(pnt2b, 1);

// Outside polygon

inputGeometry2.SetValue(pnt3b, 2);

 

// If esriGeometryRelationRelation, define relation parameter

esriGeometryRelationEnum enumRelate = esriGeometryRelationEnum.esriGeometryRelationRelation;

 

// G1 = first (base) geometry array, G2 = second (comparison) geometry array

string relationParameter = "G2 INTERSECT G1.BOUNDARY";

 

RelationResult[] relationResults = geometryService.Relation(inputSpatialReference, inputGeometry1, inputGeometry2,enumRelate, relationParameter);

Simplify

Geometry_GeometryServer geometryService = new Geometry_GeometryServer();

geometryService.Url = "http://localhost:6080/arcgis/services/Geometry/GeometryServer";

 

SpatialReference inputSpatialReference = geometryService.FindSRByWKID("EPSG", 4326, -1, true, true);

 

// Ring 1

PointN pnt1a = new PointN();

pnt1a.X = 10.0;

pnt1a.Y = 30.0;

PointN pnt2a = new PointN();

pnt2a.X = 10.0;

pnt2a.Y = 45.0;

PointN pnt3a = new PointN();

pnt3a.X = 25.0;

pnt3a.Y = 45.0;

PointN pnt4a = new PointN();

pnt4a.X = 25.0;

pnt4a.Y = 30.0;

PointN pnt5a = new PointN();

pnt5a.X = 10.0;

pnt5a.Y = 30.0;

 

PointN[] pnts1a = new PointN[] { pnt1a, pnt2a, pnt3a, pnt4a, pnt5a };

Ring ring1 = new Ring();

ring1.PointArray = pnts1a;

 

// Ring 2

PointN pnt1b = new PointN();

pnt1b.X = 15.0;

pnt1b.Y = 35.0;

PointN pnt2b = new PointN();

pnt2b.X = 15.0;

pnt2b.Y = 50.0;

PointN pnt3b = new PointN();

pnt3b.X = 30.0;

pnt3b.Y = 50.0;

PointN pnt4b = new PointN();

pnt4b.X = 30.0;

pnt4b.Y = 35.0;

PointN pnt5b = new PointN();

pnt5b.X = 15.0;

pnt5b.Y = 35.0;

 

PointN[] pnts1b = new PointN[] { pnt1b, pnt2b, pnt3b, pnt4b, pnt5b };

Ring ring2 = new Ring();

ring2.PointArray = pnts1b;

 

// Multipart Polygon (2 overlapping rings)

Ring[] rings = new Ring[] { ring1, ring2 };

PolygonN polygon1 = new PolygonN();

polygon1.RingArray = rings;

 

Geometry[] geometryArray = new Geometry[] { polygon1 };

 

// Overlapping section removed

Geometry[] simplifiedGeometry = geometryService.Simplify(inputSpatialReference, geometryArray);

GPServer

Execute

string endpoint = "http://sampleserver1.arcgisonline.com/ArcGIS/services/Elevation/ESRI_Elevation_World/GPServer";

GPServerProxy gpserver = new GPServerProxy(endpoint);

GPToolInfo viewshedToolInfo = gpserver.GetToolInfo("Viewshed");

GPValue[] gpValues = new GPValue[2];

//create the point for the viewshed tool from the default schema

GPParameterInfo gpPI = viewshedToolInfo.ParameterInfo[0];

//Use the default schema

GPFeatureRecordSetLayer inPoint = (GPFeatureRecordSetLayer)gpPI.Value;

RecordSet inPointRS = inPoint.RecordSet;

Record[] records = new Record[1];

Record rec = new Record();

rec.Values = new object[3];

//id field

rec.Values[0] = 0;

//shape field

PointN p = new PointN();

p.X = -13100000.0;

p.Y = 4200000.0;

rec.Values[1] = p;

//offset field

rec.Values[2] = 70;

//add the record to the set of records.

records[0] = rec;

inPointRS.Records = records;

//create the linear unit value

GPLinearUnit gpLU = new GPLinearUnit();

gpLU.Value = 10;

gpLU.Units = esriUnits.esriKilometers;

gpValues[0] = inPoint;

gpValues[1] = gpLU;

//############# Execute with no Options #############

GPResult gpResult = gpserver.Execute("Viewshed", gpValues, null, null);

GPFeatureRecordSetLayer viewshedPoly = (GPFeatureRecordSetLayer)gpResult.Values[0];

//############# Execute with Result Options #############

//Setup Result Options

GPResultOptions resultOptions = new GPResultOptions();

//Result Spatial Reference

ProjectedCoordinateSystem PCS = new ProjectedCoordinateSystem();

PCS.WKID = 102113;

PCS.WKIDSpecified = true;

resultOptions.SpatialReference = (SpatialReference)PCS;

//Result Format

resultOptions.Format = "kml";

//Transport Type

resultOptions.TransportType = esriGDSTransportType.esriGDSTransportTypeUrl;

resultOptions.TransportTypeSpecified = true;

//Execute with GPResult Options

GPResult gpResult2 = gpserver.Execute("Viewshed", gpValues, resultOptions, null);

GPDataFile kmlViewshedPoly = (GPDataFile)gpResult2.Values[0];

System.Console.WriteLine(kmlViewshedPoly.Data.URL);

GetExecutionType

string endpoint = "http://sampleserver1.arcgisonline.com/ArcGIS/services/Elevation/ESRI_Elevation_World/GPServer";

ESRI.ArcGIS.SOAP.GPServerProxy gpserver = new ESRI.ArcGIS.SOAP.GPServerProxy();

gpserver.Url = endpoint;

ESRI.ArcGIS.SOAP.esriExecutionType exectype= gpserver.GetExecutionType();

GetJobMessages

//to ensure job has completed see GetJobStatus

//to get the job id see SubmitJob

JobMessage[] msgs = gpserver.GetJobMessages(jobID);

System.Console.WriteLine("Number of JobMessages = " + msgs.Length.ToString());

foreach (JobMessage msg in msgs)

{

      System.Console.WriteLine(msg.MessageDesc);

}

GetJobResult

//to get the job id see SubmitJob

//to determine the job status see GetJobStatus

 

if (jobStat == esriJobStatus.esriJobSucceeded)

{

      //setup result options

      GPResultOptions resultOptions = new GPResultOptions();

      resultOptions.TransportType = esriGDSTransportType.esriGDSTransportTypeUrl;

      resultOptions.TransportTypeSpecified = true;

 

      //get results from server based on job id

      GPResult results = gpserver.GetJobResult(jobID, null, resultOptions);

      GPFeatureRecordSetLayer parcelBuffer = (GPFeatureRecordSetLayer)results.Values[0];

      GPDataFile report = (GPDataFile)results.Values[1];

      System.Console.WriteLine(report.Data.URL);

}

GetJobStatus

//to obtain the jobid for the input parameter see SubmitJob

esriJobStatus jobStat = gpserver.GetJobStatus(jobID);

 

//poll the server until job completes

while (jobStat == esriJobStatus.esriJobWaiting ||

jobStat == esriJobStatus.esriJobSubmitted ||

jobStat == esriJobStatus.esriJobExecuting ||

jobStat == esriJobStatus.esriJobCancelling ||

jobStat == esriJobStatus.esriJobDeleting ||

jobStat == esriJobStatus.esriJobNew)

{

      System.Threading.Thread.Sleep(500);

      System.Console.WriteLine(jobStat.ToString());

      jobStat = gpserver.GetJobStatus(jobID);

}

GetResultMapServerName

string endpoint = "http://sampleserver1.arcgisonline.com/ArcGIS/services/Elevation/ESRI_Elevation_World/GPServer";

ESRI.ArcGIS.SOAP.GPServerProxy gpserver = new ESRI.ArcGIS.SOAP.GPServerProxy();

gpserver.Url = endpoint;

string mapservername = gpserver.GetResultMapServerName();

GetTaskInfos

string endpoint = "http://sampleserver1.arcgisonline.com/ArcGIS/services/Elevation/ESRI_Elevation_World/GPServer";

ESRI.ArcGIS.SOAP.GPServerProxy gpserver = new ESRI.ArcGIS.SOAP.GPServerProxy();

gpserver.Url = endpoint;

ESRI.ArcGIS.SOAP.GPTaskInfo[] tasks = gpserver.GetTaskInfos();

GetTaskNames

string endpoint = "http://sampleserver1.arcgisonline.com/ArcGIS/services/Elevation/ESRI_Elevation_World/GPServer";

ESRI.ArcGIS.SOAP.GPServerProxy gpserver = new ESRI.ArcGIS.SOAP.GPServerProxy();

gpserver.Url = endpoint;

string[] tasknames = gpserver.GetTaskNames();

GetToolInfo

string endpoint = "http://sampleserver1.arcgisonline.com/ArcGIS/services/Elevation/ESRI_Elevation_World/GPServer";

ESRI.ArcGIS.SOAP.GPServerProxy gpserver = new ESRI.ArcGIS.SOAP.GPServerProxy();

gpserver.Url = endpoint;

ESRI.ArcGIS.SOAP.GPToolInfo toolinfo = gpserver.GetToolInfo("Viewshed");

GetToolInfos

string endpoint = "http://sampleserver1.arcgisonline.com/ArcGIS/services/Elevation/ESRI_Elevation_World/GPServer";

ESRI.ArcGIS.SOAP.GPServerProxy gpserver = new ESRI.ArcGIS.SOAP.GPServerProxy();

gpserver.Url = endpoint;

ESRI.ArcGIS.SOAP.GPToolInfo[] tools = gpserver.GetToolInfos();

GetToolNames

string endpoint = "http://sampleserver1.arcgisonline.com/ArcGIS/services/Elevation/ESRI_Elevation_World/GPServer";

ESRI.ArcGIS.SOAP.GPServerProxy gpserver = new ESRI.ArcGIS.SOAP.GPServerProxy();

gpserver.Url = endpoint;

string[] toolnames = gpserver.GetToolNames();

SubmitJob

string endpoint = "http://sampleserver2.arcgisonline.com/ArcGIS/services/Portland/ESRI_CadastralData_Portland/GPServer";

GPServerProxy gpserver = new GPServerProxy(endpoint);

 

//Set up the input parameter container

GPValue[] gpValues = new GPValue[2];

 

//create the parcel id value

GPString parcelID = new GPString();

parcelID.Value = "1S124CB04400";

 

//create the search distance value (long)

GPLong searchDistance = new GPLong();

searchDistance.Value = 250;

 

//add the parameters to the parameter list

gpValues[0] = parcelID;

gpValues[1] = searchDistance;

 

//submit th job and retrieve the jobid

string jobID = gpserver.SubmitJob("MailingList", gpValues, null, null);

//to track job status see GetJobStatus

//to access job messages see GetJobMessages

//to retrieve job results see GetJobResult

ImageServer

Add

//define image server
UploadTest_ImageServer imageServer = new UploadTest_ImageServer();
imageServer.Url = _serviceurl;

//define raster item description
string[] urls = new string[] { "http://istest/cal/tile1/tile1.tif", "http://istest/cal/tile1/tile1.aux.xml", "http://istest/cal/tile1/tile1.tfw", "http://istest/cal/tile1/tile1.ovr" };
string[] names = new string[] { "tile1.tif", "tile1.aux.xml", "tile1.tfw" };
RasterItemDescription itemDescription = new RasterItemDescription();
itemDescription.DataFileURLs = urls;
itemDescription.DataFileNames = names;
itemDescription.BuildThumbnail = true;
itemDescription.BuildThumbnailSpecified = true;
itemDescription.Type = "Raster Dataset";
PropertySetProperty prop = new PropertySetProperty();
prop.Key = "MyField";
prop.Value = "MyValue";
PropertySet propSet = new PropertySet();
propSet.PropertyArray = new PropertySetProperty[] { prop };
itemDescription.Properties = propSet;

//define transformation (if not georeferenced)
PolynomialXform polyXform = new PolynomialXform();
polyXform.SourceGCPs = new double[]{0,0, 100, 100, 0,100};
polyXform.TargetGCPs = new double[] { 100, 100, 300, 300, 100, 300 };
polyXform.PolynomialOrder = 1;
polyXform.PolynomialOrderSpecified = true;
polyXform.SpatialReference = ((EnvelopeN)imageServer.GetServiceInfo().Extent).SpatialReference;
itemDescription.GeodataXform = polyXform;

//add
ImageServerEditResult[] editResults = imageServer.Add(new RasterItemDescription[] { itemDescription });

//log results
Console.Write("objectID:");
for (int i = 0; i < editResults.Length; i++)
      Console.WriteLine("RID: {0}, status: {1}", editResults[i].RasterID,editResults[i].Succeeded);

ComputeHistograms

//define image server
UploadTest_ImageServer imageServer = new UploadTest_ImageServer();
imageServer.Url = _serviceurl;

//define area of interest
EnvelopeN env = new EnvelopeN();
env.XMin = 3268200;
env.XMax = 3268800;
env.YMin = 127855;
env.YMax = 128255;
env.SpatialReference = ((EnvelopeN)imageServer.GetServiceInfo().Extent).SpatialReference;

//define a mosaic rule  (for mosaic)
MosaicRule mrule = new MosaicRule();
mrule.MosaicMethod = esriMosaicMethod.esriMosaicCenter;

//define pixel size
PointN resolution = new PointN();
resolution.X = 1.5;
resolution.Y = 1.5;

//compute histograms
RasterHistogram[] hists = imageServer.ComputeHistograms(env, mrule, resolution);

Delete

//define image server
UploadTest_ImageServer imageServer = new UploadTest_ImageServer();
imageServer.Url = _serviceurl;

//define which rasters to deleteraster item description
FIDSet fidSet = new FIDSet();
fidSet.FIDArray = new int[] { 5,6 };

//delete
ImageServerEditResult[] editResults = imageServer.Delete(fidSet);

//log results
for (int i = 0; i < editResults.Length; i++)
      Console.WriteLine("RID: {0}, status: {1}", editResults[i].RasterID, editResults[i].Succeeded);

ExportImage

//define image server

string url_DEMService = "http://ais3/arcgis/services/testDEM/ImageServer";

testDTED_ImageServer imageSrv = new testDTED_ImageServer();

imageSrv.Url = url_DEMService;

 

//define image description

GeoImageDescription geoImgDesc = new GeoImageDescription();

geoImgDesc.Height = 600;

geoImgDesc.Width = 800;

geoImgDesc.Interpolation = rstResamplingTypes.RSP_BilinearInterpolation;

ImageServiceInfo isInfo = imageSrv.GetServiceInfo();

geoImgDesc.Extent = isInfo.Extent;

 

//define a hillshade function and attach to a rendering rule

RenderingRule renderRule = new RenderingRule();

HillshadeFunction function = new HillshadeFunction();

HillshadeFunctionArguments argument = new HillshadeFunctionArguments();

argument.Names = new string[] { "Altitude", "Azimuth", "ZFactor" };

argument.Values = new object[] { 45, 315, 1.0 };

renderRule.Arguments = argument;

renderRule.Function = function;

renderRule.VariableName = "DEM";

geoImgDesc.RenderingRule = renderRule;

 

//define export format

ImageType imageType = new ImageType();

imageType.ImageFormat = esriImageFormat.esriImageJPG;

imageType.ImageReturnType = esriImageReturnType.esriImageReturnURL;

ImageResult result = imageSrv.ExportImage(geoImgDesc, imageType);

 

//download result

string fileName = @"c:\temp\hillshadeFunction.jpg";

System.Net.WebClient webClient = new System.Net.WebClient();

webClient.DownloadFile(result.ImageURL, fileName);

ExportScaledImage

//define image server

string url_DEMService = "http://ais3/arcgis/services/testDEM/ImageServer";

testDTED_ImageServer imageSrv = new testDTED_ImageServer();

imageSrv.Url = url_DEMService;

 

//define image description

GeoImageDescription geoImgDesc = new GeoImageDescription();

geoImgDesc.Height = 600;

geoImgDesc.Width = 800;

geoImgDesc.Interpolation = rstResamplingTypes.RSP_BilinearInterpolation;

ImageServiceInfo isInfo = imageSrv.GetServiceInfo();

geoImgDesc.Extent = isInfo.Extent;

 

//apply a mosaic rule

MosaicRule mosaicRule = new MosaicRule();

mosaicRule.LockRasterID = "1,2,3";

geoImgDesc.MosaicRule = mosaicRule;

 

//define export format

ImageType imgType = new ImageType();

imgType.ImageFormat = esriImageFormat.esriImagePNG;

imgType.ImageReturnType = esriImageReturnType.esriImageReturnURL;

 

//export scaled image

MapImage mapImage = imageSrv.ExportScaledImage(geoImgDesc, imgType);

GetCatalogItems

//define image server

string url_DEMService = "http://ais3/arcgis/services/testDEM/ImageServer";

testDTED_ImageServer imageSrv = new testDTED_ImageServer();

imageSrv.Url = url_DEMService;

 

//define an image query filter

ImageQueryFilter imageQueryFilter = new ImageQueryFilter();

PointN pixelSize = new PointN();

pixelSize.X = 0.2;

pixelSize.Y = 0.2;

imageQueryFilter.PixelSize = (Point)pixelSize;

 

//query image service

RecordSet recordSet = imageSrv.GetCatalogItems(imageQueryFilter);

GetImage

//define image server

string url_DEMService = "http://ais3/arcgis/services/testDEM/ImageServer";

testDTED_ImageServer imageSrv = new testDTED_ImageServer();

imageSrv.Url = url_DEMService;

 

//define image description

GeoImageDescription geoImgDesc = new GeoImageDescription();

geoImgDesc.Height = 600;

geoImgDesc.Width = 800;

geoImgDesc.Interpolation = rstResamplingTypes.RSP_BilinearInterpolation;

ImageServiceInfo isInfo = imageSrv.GetServiceInfo();

geoImgDesc.Extent = isInfo.Extent;

 

//get the image

byte[] imageResult = imageSrv.GetImage(geoImgDesc);

GetImageTile

/// <param name="url">service endpoint</param>
private static void RetrieveKeyProperties(string url)
{

      //connect to image server
      sampleImage_ImageServer imageSrv = new sampleImage_ImageServer();
      imageSrv.Url = url;

      //get service's key properties
      PropertySet propSet = imageSrv.GetKeyProperties();
      for (int i = 0; i < propSet.PropertyArray.Length; i++)
      {
            PropertySetProperty prop = propSet.PropertyArray[i];
            if (prop.Value is double)
                  Console.WriteLine("{0}: {1}", prop.Key, (double)prop.Value);
            if (prop.Value is string)
                  Console.WriteLine("{0}: {1}", prop.Key, (string)prop.Value);
      }

      //get first item's key properties
      PropertySet propSet1 = imageSrv.GetRasterKeyProperties(1);
      for (int i = 0; i < propSet1.PropertyArray.Length; i++)
      {
            PropertySetProperty prop = propSet.PropertyArray[i];
            if (prop.Value is double)
                  Console.WriteLine("{0}: {1}", prop.Key, (double)prop.Value);
            if (prop.Value is string)
                  Console.WriteLine("{0}: {1}", prop.Key, (string)prop.Value);
      }
}

private static void GetFirstImageTile(string url)
{

      //define image service and get cache description info
      sampleImage_ImageServer imageSrv = new sampleImage_ImageServer() { Url = url };
      CacheDescriptionInfo cacheDescInfo = imageSrv.GetCacheDescriptionInfo();
      TileCacheInfo tcInfo = cacheDescInfo.TileCacheInfo;
      LODInfo[] lodInfo = tcInfo.LODInfos;

      //request level 12
      double resolution = lodInfo[12].Resolution;
      PointN origin = tcInfo.TileOrigin as PointN;
      EnvelopeN extent = imageSrv.GetServiceInfo().Extent as EnvelopeN;
      int mintileCol = (int)((extent.XMin - origin.X) / (tcInfo.TileCols * resolution));
      int maxtileCol = (int)((extent.XMax - origin.X) / (tcInfo.TileCols * resolution));
      int mintileRow = (int)((origin.Y - extent.YMax) / (tcInfo.TileRows * resolution));
      int maxtileRow = (int)((origin.Y - extent.YMin) / (tcInfo.TileRows * resolution));

      //get first tile
      byte[] firstTile = imageSrv.GetImageTile(12, mintileRow, mintileCol);

      //show first tile or save it...
}

GetKeyProperties

//connect to image server
sampleImage_ImageServer imageSrv = new sampleImage_ImageServer();
imageSrv.Url = url;

//get service's key properties
PropertySet propSet = imageSrv.GetKeyProperties();
for (int i = 0; i < propSet.PropertyArray.Length; i++)
{
      PropertySetProperty prop = propSet.PropertyArray[i];
      if (prop.Value is double)
            Console.WriteLine("{0}: {1}", prop.Key, (double)prop.Value);
      if (prop.Value is string)
            Console.WriteLine("{0}: {1}", prop.Key, (string)prop.Value);
}

//get first item's key properties
PropertySet propSet1 = imageSrv.GetRasterKeyProperties(1);
for (int i = 0; i < propSet1.PropertyArray.Length; i++)
{
PropertySetProperty prop = propSet.PropertyArray[i];
      if (prop.Value is double)
      Console.WriteLine("{0}: {1}", prop.Key, (double)prop.Value);
            if (prop.Value is string)
      Console.WriteLine("{0}: {1}", prop.Key, (string)prop.Value);
}

GetServiceInfo

//define image server

string url_DEMService = "http://ais3/arcgis/services/testDEM/ImageServer";

testDTED_ImageServer imageSrv = new testDTED_ImageServer();

imageSrv.Url = url_DEMService;

 

//get service info

ImageServiceInfo isInfo = imageSrv.GetServiceInfo();

string name = isInfo.Name;

GetVersion

//define image server

string url_DEMService = "http://ais3/arcgis/services/testDEM/ImageServer";

testDTED_ImageServer imageSrv = new testDTED_ImageServer();

imageSrv.Url = url_DEMService;

 

//get the version

Decimal result = imgSrv.GetVersion();

Measure

//define image server
UploadTest_ImageServer imageServer = new UploadTest_ImageServer();
imageServer.Url = _serviceurl;

//define from to points
SpatialReference wgs84 = new GeographicCoordinateSystem();
wgs84.WKID = 4326;
wgs84.WKIDSpecified = true;
PointN from = new PointN();
from.X = -111.19944857;
from.Y = 32.05586888;
from.SpatialReference = wgs84;
PointN to = new PointN();
to.X = -111.19940048;
to.Y = 32.05589815;
to.SpatialReference = wgs84;

//define a mosaic rule
MosaicRule mrule = new MosaicRule();
mrule.MosaicMethod = esriMosaicMethod.esriMosaicLockRaster;
mrule.LockRasterID = "2";

//define pixel size
PointN resolution = new PointN();
resolution.X = 0.2;
resolution.Y = 0.2;

//measure
ImageServerMeasureResult measureResult = imageServer.Measure(from, to, mrule, resolution, esriMensurationOperation.esriMensurationHeightFromBaseAndTop);

//log results
for (int i=0; i<measureResult.Measurement.PropertyArray.Length; i++)
{
      PropertySetProperty prop = measureResult.Measurement.PropertyArray[i];
      if (prop.Value is double)
            Console.WriteLine("{0}: {1}", prop.Key, (double)prop.Value);
      if (prop.Value is string)
            Console.WriteLine("{0}: {1}", prop.Key, (string)prop.Value);
}

Update

//define image server
UploadTest_ImageServer imageServer = new UploadTest_ImageServer();
imageServer.Url = _serviceurl;

//define raster item description
string[] urls = new string[] { "http://istest/cal/tile1/tile1.tif", "http://istest/cal/tile1/tile1.aux.xml", "http://istest/cal/tile1/tile1.tfw", "http://istest/cal/tile1/tile1.ovr" };
string[] names = new string[] { "tile1.tif", "tile1.aux.xml", "tile1.tfw" };
RasterItemDescription itemDescription = new RasterItemDescription();
itemDescription.DataFileURLs = urls;
itemDescription.DataFileNames = names;
itemDescription.BuildThumbnail = true;
itemDescription.BuildThumbnailSpecified = true;
itemDescription.Type = "Raster Dataset";
PropertySetProperty prop = new PropertySetProperty();
prop.Key = "MyField";
prop.Value = "MyValue";
PropertySet propSet = new PropertySet();
propSet.PropertyArray = new PropertySetProperty[] { prop };
itemDescription.Properties = propSet;

//define transformation to update georeferencing
PolynomialXform polyXform = new PolynomialXform();
polyXform.SourceGCPs = new double[]{0,0, 100, 100, 0,100};
polyXform.TargetGCPs = new double[] { 100, 100, 300, 300, 100, 300 };
polyXform.PolynomialOrder = 1;
polyXform.PolynomialOrderSpecified = true;
polyXform.SpatialReference = ((EnvelopeN)imageServer.GetServiceInfo().Extent).SpatialReference;
itemDescription.GeodataXform = polyXform;

//define FIDSet
FIDSet fidSet = new FIDSet();
fidSet.FIDArray = new int[] { 5 };

//update
ImageServerEditResult[] editResults = imageServer.Update(fidSet, new RasterItemDescription[] { itemDescription });

//log results
for (int i = 0; i < editResults.Length; i++)
      Console.WriteLine("RID: {0}, status: {1}", editResults[i].RasterID,editResults[i].Succeeded);
}

MapServer

ComputeDistance

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

 

string mapname = mapservice.GetDefaultMapName();

wsmap.PointN pnt0 = new PointN();

pnt0.X = -120.0;

pnt0.Y = 30.0;

 

wsmap.PointN pnt1 = new PointN();

pnt1.X = -110.0;

pnt1.Y = 35.0;

double distance = mapservice.ComputeDistance(mapname, pnt0, pnt1, esriUnits.esriMiles);

ComputeScale

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

 

MapServerInfo mapinfo = mapservice.GetServerInfo(mapservice.GetDefaultMapName());

>MapDescription mapdesc = mapinfo.DefaultMapDescription;

 

ImageDisplay imgdisp = new ImageDisplay();

imgdisp.ImageHeight = 500; //pixels

imgdisp.ImageWidth = 500; //pixels

imgdisp.ImageDPI = 96;

 

double scale = mapservice.ComputeScale(mapdesc, imgdisp);

ExportMapImage

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

 

MapServerInfo mapinfo = mapservice.GetServerInfo(mapservice.GetDefaultMapName());

MapDescription mapdesc = mapinfo.DefaultMapDescription;

 

ImageType imgtype = new ImageType();

imgtype.ImageFormat = esriImageFormat.esriImagePNG;

imgtype.ImageReturnType = esriImageReturnType.esriImageReturnURL;

 

ImageDisplay imgdisp = new ImageDisplay();

imgdisp.ImageHeight = 500; //pixels

imgdisp.ImageWidth = 500; //pixels

imgdisp.ImageDPI = 96;

 

ImageDescription imgdesc = new ImageDescription();

imgdesc.ImageDisplay = imgdisp;

imgdesc.ImageType = imgtype;

 

MapImage mapimg = mapservice.ExportMapImage(mapdesc, imgdesc);

ExportScaleBar

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

 

// Define scale bar properties

AlternatingScaleBar scalebar = new AlternatingScaleBar();

 

// Define Unit label

scalebar.Units = esriUnits.esriMiles;

scalebar.UnitsSpecified = true;

TextSymbol unittextsymbol = new TextSymbol();

unittextsymbol.Size = 20;

unittextsymbol.FontName = "Arial";

scalebar.UnitLabelSymbol = unittextsymbol;

scalebar.UnitLabelPosition = esriScaleBarPos.esriScaleBarAfterBar;

scalebar.UnitLabelPositionSpecified = true;

scalebar.UnitLabelGap = 10;

scalebar.UnitLabelGapSpecified = true;

 

// Define bar display

scalebar.BarHeight = 8;

scalebar.BarHeightSpecified = true;

scalebar.Divisions = 4;

scalebar.DivisionsSpecified = true;

scalebar.DivisionMarkHeight = 18;

scalebar.DivisionMarkHeightSpecified = true;

scalebar.Subdivisions = 10;

scalebar.SubdivisionsSpecified = true;

scalebar.MarkPosition = esriVertPosEnum.esriBottom;

scalebar.MarkPositionSpecified = true;

SimpleFillSymbol fillsymbol = new SimpleFillSymbol();

wsmap.RgbColor fillcolor = new wsmap.RgbColor();

fillcolor.Red = 255;

fillcolor.Green = 0;

fillcolor.Blue = 0;

fillsymbol.Color = fillcolor;

scalebar.FillSymbol1 = fillsymbol;

 

// Define division labels

TextSymbol textsymbol = new TextSymbol();

textsymbol.Size = 20;

textsymbol.FontName = "Arial";

textsymbol.TextDirection = esriTextDirection.esriTDAngle;

textsymbol.Angle = 45;

scalebar.LabelSymbol = textsymbol;

scalebar.LabelPosition = esriVertPosEnum.esriAbove;

scalebar.LabelPositionSpecified = true;

scalebar.LabelFrequency = esriScaleBarFrequency.esriScaleBarDivisions;

scalebar.LabelFrequencySpecified = true;

 

// Define map properties (MapDescription and ImageDisplay)

MapServerInfo mapinfo = mapservice.GetServerInfo(mapservice.GetDefaultMapName());

MapDescription mapdesc = mapinfo.DefaultMapDescription;

ImageDisplay imgdispmap = new ImageDisplay();

imgdispmap.ImageWidth = 500;

imgdispmap.ImageHeight = 500;

imgdispmap.ImageDPI = 96;

 

// Define scale bar image properties (ImageDescription)

ImageType imgtype = new ImageType();

imgtype.ImageFormat = esriImageFormat.esriImagePNG;

imgtype.ImageReturnType = esriImageReturnType.esriImageReturnURL;

ImageDisplay imgdispscalebar = new ImageDisplay();

imgdispscalebar.ImageHeight = 75; //pixels

imgdispscalebar.ImageWidth = 400; //pixels

ImageDescription imgdescscalebar = new ImageDescription();

imgdescscalebar.ImageDisplay = imgdispscalebar;

imgdescscalebar.ImageType = imgtype;

 

// Define background color

wsmap.RgbColor backcolor = new wsmap.RgbColor();

backcolor.Red = 255;

backcolor.Green = 255;

backcolor.Blue = 255;

 

// Create scale bar image

ImageResult imgresult = mapservice.ExportScaleBar(scalebar, mapdesc, imgdispmap, backcolor, imgdescscalebar);

Find

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

 

MapServerInfo mapinfo = mapservice.GetServerInfo(mapservice.GetDefaultMapName());

MapDescription mapdesc = mapinfo.DefaultMapDescription;

 

ImageDisplay imgdisp = new ImageDisplay();

imgdisp.ImageHeight = 500; //pixels

imgdisp.ImageWidth = 500; //pixels

imgdisp.ImageDPI = 96;

 

string searchstring = "Washington";

 

bool contains_searchstring = true;

 

string fieldname = string.Empty; // all fields

 

esriFindOption findoption = esriFindOption.esriFindAllLayers;

 

LayerDescription[] layerdescriptions = mapdesc.LayerDescriptions;

int[] layerids = new int[layerdescriptions.Length];

int i = 0;

 

foreach (LayerDescription layerdesc in layerdescriptions)

{

      style="font-size: 12pt;">layerids.SetValue(layerdesc.LayerID, i++);

}

 

MapServerFindResult[] findresults = mapservice.Find(mapdesc, imgdisp, searchstring, contains_searchstring, fieldname, findoption, layerids);

FromMapPoints

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

 

MapServerInfo mapinfo = mapservice.GetServerInfo(mapservice.GetDefaultMapName());

MapDescription mapdesc = mapinfo.DefaultMapDescription;

 

ImageDisplay imgdisp = new ImageDisplay();

imgdisp.ImageHeight = 500; //pixels

imgdisp.ImageWidth = 500; //pixels

imgdisp.ImageDPI = 96;

 

MultipointN multipoint = new MultipointN();

PointN[] points = new PointN[1];

 

wsmap.PointN pnt0 = new PointN();

pnt0.X = -120.0;

pnt0.Y = 35.0;

 

points[0] = pnt0;

multipoint.PointArray = points;

 

int[] screeny = null;

int[] screenx = mapservice.FromMapPoints(mapdesc, imgdisp, multipoint, out screeny);

GenerateDataClasses

//Sample code to generate 5 different classes based on LANDVAL field using EqualInterval classification method

HsvColor pColorStart = new HsvColor();
pColorStart.Hue = 60;
pColorStart.Saturation = 50;
pColorStart.Value = 100;

HsvColor pColorMiddle = new HsvColor();
pColorMiddle.Hue = 37;
pColorMiddle.Saturation = 81;
pColorMiddle.Value = 95;

HsvColor pColorEnd = new HsvColor();
pColorEnd.Hue = 0;
pColorEnd.Saturation = 100;
pColorEnd.Value = 42;

AlgorithmicColorRamp pAlgorithmicColorRamp1 = new AlgorithmicColorRamp();
pAlgorithmicColorRamp1.FromColor = pColorStart;
pAlgorithmicColorRamp1.ToColor = pColorMiddle;

AlgorithmicColorRamp pAlgorithmicColorRamp2 = new AlgorithmicColorRamp();
pAlgorithmicColorRamp2.FromColor = pColorMiddle;
pAlgorithmicColorRamp2.ToColor = pColorEnd;

MultiPartColorRamp pMultiPartColorRamp = new MultiPartColorRamp()
{
	ColorRamps = new ColorRamp[2] 
		{   
			pAlgorithmicColorRamp1, 
			pAlgorithmicColorRamp2
		},
	NumColorRamps = 2,
	NumColorRampsSpecified = true
};

RgbColor pColor = new RgbColor() 
{ 
	Red = 255 
};
SimpleFillSymbol pBaseFillSymbol = new SimpleFillSymbol()
{
	Color = pColor,
	Style = esriSimpleFillStyle.esriSFSSolid,
	Outline = null
};

ClassBreaksDef pCBDef = new ClassBreaksDef()
{
	ClassificationField = "LANDVAL",
	ClassificationMethod = esriClassifyMethod.esriClassifyEqualInterval,
	BreakCount = 5,
	BreakCountSpecified = true,
	ColorRamp = pMultiPartColorRamp,
	BaseSymbol = pBaseFillSymbol
};

FeatureRenderer pFeatureRenderer = pMapServer.GenerateDataClasses(pMapServer.GetDefaultMapName(), pLayerDescription, pCBDef);

GetCacheName

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

 

string mapname = mapservice.GetDefaultMapName();

 

MapServerInfo mapinfo = mapservice.GetServerInfo(mapname);

MapDescription mapdesc = mapinfo.DefaultMapDescription;

 

LayerDescription[] layerdescriptions = mapdesc.LayerDescriptions;

 

foreach (LayerDescription layerdesc in layerdescriptions)

{

      style="font-size: 12pt;">if (mapservice.HasLayerCache(mapname, layerdesc.LayerID))

      {

            string layercachename = mapservice.GetCacheName(mapname, layerdesc.LayerID);

      }

}

GetCacheControlInfo

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapFusedCache/MapServer";

 

string mapname = mapservice.GetDefaultMapName();

CacheControlInfo cachecontrlinfo = mapservice.GetCacheControlInfo(mapname);

GetCacheDescriptionInfo

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

 

string mapname = mapservice.GetDefaultMapName();

CacheDescriptionInfo cachedescinfo = mapservice.GetCacheDescriptionInfo(mapname);

 

CacheControlInfo cachecontrolinfo = cachedescinfo.CacheControlInfo;

TileCacheInfo tilecacheinfo = cachedescinfo.TileCacheInfo;

TileImageInfo tileimginfo = cachedescinfo.TileImageInfo;

esriCachedMapServiceType cachetype = cachedescinfo.CacheType;

GetDefaultMapName

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapLayerCache/MapServer";

 

string mapname = mapservice.GetDefaultMapName();

GetDocumentInfo

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapLayerCache/MapServer";

 

PropertySet documentproperties = mapservice.GetDocumentInfo();

PropertySetProperty[] propertyarray = documentproperties.PropertyArray;

 

foreach (PropertySetProperty documentprop in propertyarray)

{

      string key = documentprop.Key.ToString();

      string value = documentprop.Value.ToString();

}

GetLayerTile

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapLayerCache/MapServer";

string mapname = mapservice.GetDefaultMapName();

MapServerInfo mapinfo = mapservice.GetServerInfo(mapname);

MapDescription mapdesc = mapinfo.DefaultMapDescription;

LayerDescription[] layerdescriptions = mapdesc.LayerDescriptions;

// Pixel height and width of map display on the client. In this case, a Windows Form

// PictureBox control.

int picturewidth = pictureBox1.Width;

int pictureheight = pictureBox1.Height;

EnvelopeN mapextent = (EnvelopeN)mapdesc.MapArea.Extent;

// Use map scale resolution (map units per pixel) to determine tile level

double mapresolution = Math.Abs(mapextent.XMax - mapextent.XMin) / picturewidth;

System.Drawing.Bitmap imgbitmap = new System.Drawing.Bitmap(picturewidth, pictureheight);

System.Drawing.Graphics imggraphics = System.Drawing.Graphics.FromImage(imgbitmap);

imggraphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.LightGray),

0, 0, picturewidth, pictureheight);

int layerdesc_maxindex = layerdescriptions.Length - 1;

// Iterate through layers bottom up. Polygons on bottom, then lines, then points.

for (int d = layerdesc_maxindex; d >= 0; d--)

{

      LayerDescription layerdesc = layerdescriptions[d];

      if (mapservice.HasLayerCache(mapname, layerdesc.LayerID))

      {

            TileCacheInfo tci = mapservice.GetTileCacheInfo(mapservice.GetDefaultMapName());

            LODInfo[] tcis = tci.LODInfos;

            // Map units per pixel

            double tileresolution = 0;

            //Scale level

            int tilelevel = 0;

            foreach (LODInfo ldi in tcis)

            {

                  tileresolution = ldi_resolution;
      
                  tilelevel = ldi.LevelID;

                  if (mapresolution >= ldi_resolution)

                  {

                        break;

                  }

            }

            // Measured from the origin

            double minx = mapextent.XMin;

            double miny = mapextent.YMin;

            double maxx = mapextent.XMax;

            double maxy = mapextent.YMax;

            >// Origin of the cache (upper left corner)

            double xorigin = ((PointN)tci.TileOrigin).X;

            double yorigin = ((PointN)tci.TileOrigin).Y;

            // Get minimum tile column

            double minxtile = (minx - xorigin) / (tci.TileCols * tileresolution);

            // Get minimum tile row

            // From the origin, maxy is minimum y

            double minytile = (yorigin - maxy) / (tci.TileRows * tileresolution);

            // Get maximum tile column

            double maxxtile = (maxx - xorigin) / (tci.TileCols * tileresolution);

            // Get maximum tile row

            // From the origin, miny is maximum y

            double maxytile = (yorigin - miny) / (tci.TileRows * tileresolution);

            // Return integer value for min and max, row and column

            int mintilecolumn = (int)Math.Floor(minxtile);

            int mintilerow = (int)Math.Floor(minytile);

            int maxtilecolumn = (int)Math.Floor(maxxtile);

            int maxtilerow = (int)Math.Floor(maxytile);

            // Origin of the min tile

            double xmintileorigin = xorigin + (mintilecolumn * (tci.TileCols * tileresolution));

            double ymintileorigin = yorigin - (mintilerow * (tci.TileRows * tileresolution));

            // Since the origin of the extent and origin of the min tile are different

            // get the difference and use to place consolidated image graphic in correct location

            double xadjust = Math.Abs(minx - xmintileorigin);

            double yadjust = Math.Abs(maxy - ymintileorigin);

            int xpixadjust = (int)(xadjust / tileresolution);

            int ypixadjust = (int)(yadjust / tileresolution);

            TileImageInfo tii = mapservice.GetTileImageInfo(mapservice.GetDefaultMapName());

            int rowindex = 0;

            // for each row in the map extent

            for (int row = mintilerow; row <= maxtilerow;row++)

            {

                  int colindex = 0;

                  // for each column in the row, in the map extent

                  for (int col = mintilecolumn; col <= maxtilecolumn; col++)

                  {

                        byte[] myByteArray = null;

                        try

                        {

                              // Return the byte array of the tile image

                              myByteArray = mapservice.GetLayerTile(mapservice.GetDefaultMapName(), layerdesc.LayerID,

                              tilelevel, row, col, tii.CacheTileFormat);

                        catch

                        {

                              // Tile may not be available because no data was present when creating the cache

                        }

                        // If Tile was found, add it to the consolidated image graphic

                        if (myByteArray != null)

                        {

                              System.Drawing.Image newImage;

                              using (System.IO.MemoryStream ms = new System.IO.MemoryStream(myByteArray, 0, myByteArray.Length))

                              {

                                    ms.Write(myByteArray, 0, myByteArray.Length);

                                    newImage = Image.FromStream(ms, true);

                                    imggraphics.DrawImage(newImage, (tci.TileCols * colindex) - xpixadjust, (tci.TileRows * rowindex) - ypixadjust,

                                    tci.TileCols, tci.TileRows);

                              }

                        }

                        colindex++;

                  }

                  rowindex++;

            }

      }

}

// Post-processing, if necessary... otherwise just use imgbitmap with PictureBox

System.Drawing.Bitmap picturebitmap = new System.Drawing.Bitmap(picturewidth, pictureheight);

System.Drawing.Graphics graphicsimage = System.Drawing.Graphics.FromImage(picturebitmap);

graphicsimage.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.LightGray),0, 0, picturewidth, pictureheight);

graphicsimage.DrawImage(imgbitmap, 0, 0, picturewidth, pictureheight);

pictureBox1.Image = picturebitmap;

GetLegendInfo

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

 

string mapname = mapservice.GetDefaultMapName();

MapServerInfo mapinfo = mapservice.GetServerInfo(mapname);

MapDescription mapdesc = mapinfo.DefaultMapDescription;

 

ImageType imgtype = new ImageType();

imgtype.ImageFormat = esriImageFormat.esriImagePNG;

imgtype.ImageReturnType = esriImageReturnType.esriImageReturnURL;

 

LayerDescription[] layerdescriptions = mapdesc.LayerDescriptions;

int[] layerids = new int[layerdescriptions.Length];

int i = 0;

foreach (LayerDescription layerdesc in layerdescriptions)

{

      layerids.SetValue(layerdesc.LayerID, i++);

}

 

MapServerLegendPatch legendpatch = new MapServerLegendPatch();

legendpatch.ImageDPI = 96;

legendpatch.Height = 24;

legendpatch.Width = 24;

 

MapServerLegendInfo[] legendinfo = mapservice.GetLegendInfo(mapname, layerids, legendpatch, imgtype);

GetMapCount

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

int mapcount = mapservice.GetMapCount();

GetMapName

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

int mapcount = mapservice.GetMapCount();

for (int i = 0; i < mapcount; i++)

{

      string mapname = mapservice.GetMapName(i);

}

GetMapTableSubtypeInfos

//In this example, it is assumed that a StandaloneTableInfo is passed in and a TreeView

//control named tvwSD is available on a form

TreeNode pNodeRoot = null;

TreeNode pNodeSubtypes = null;

TreeNode pNodeST = null;

TreeNode pNodeFieldDomains = null;

TreeNode pNodeFD = null;

TreeNode pNodeDomain = null;

 

IMapTableSubtypeInfo[] pMapTableSubtypeInfos = null;

IMapTableSubtypeInfo pMTSTInfo = null;

SubtypeInfo[] pSubtypeInfos = null;

SubtypeInfo pSTInfo = null;

FieldDomainInfo[] pFieldDomainInfos = null;

FieldDomainInfo pFDInfo = null;

CodedValueDomain pCVDomain = null;

RangeDomain pRDomain = null;

CodedValue pCV = null;

 

pStandaloneTableInfo = m_pMapServerInfoWSDL.StandaloneTableInfos[0];

if (!pStandaloneTableInfo.HasSubtype)

return;

pMapTableSubtypeInfos = m_pMapServer.GetMapTableSubtypeInfos(strMapName, new int[] {0});

pMTSTInfo = pSubtypeInfos[0];

if (pMTSTInfo == null)

return;

pNodeRoot = tvwSD.Nodes.Add(pStandaloneTableInfo.Name);

pNodeRoot.Nodes.Add("Subtype Field: " + pMTSTInfo.SubtypeFieldName);

pNodeRoot.Nodes.Add("Default Subtype Code: " + pMTSTInfo.DefaultSubtypeCode);

pSubtypeInfos = pMTSTInfo.SubtypeInfos;

pNodeSubtypes = pNodeRoot.Nodes.Add("Subtypes >>");

 

for (int i = 0; i < pSubtypeInfos.Length; i++)

{

pSTInfo = pSubtypeInfos[i];

      pNodeST = pNodeSubtypes.Nodes.Add("Subtype" + i.ToString());

      pNodeST.Nodes.Add("Subtype Code: '" + pSTInfo.SubtypeCode + "'");

      pNodeST.Nodes.Add("Subtype Name: '" + pSTInfo.SubtypeName + "'");

      pNodeFieldDomains = pNodeST.Nodes.Add("FieldDomainInfos >>");

      pFieldDomainInfos = pSTInfo.FieldDomainInfos;

      for (int j = 0; j < pFieldDomainInfos.Length; j++)

      {

      pFDInfo = pFieldDomainInfos[j];

            pNodeFD = pNodeFieldDomains.Nodes.Add("FieldDomain" + j.ToString());

            pNodeFD.Nodes.Add("Field Name: '" + pFDInfo.FieldName + "'");

            pNodeFD.Nodes.Add("Default Value: '" + ((pFDInfo.DefaultValue != null) ? pFDInfo.DefaultValue.ToString() : "<null>") + "'");

            pNodeDomain = pNodeFD.Nodes.Add("Domains >>");

            if (pFDInfo.Domain is MapServerWS.CodedValueDomain)

            {

            pCVDomain = (MapServerWS.CodedValueDomain)pFDInfo.Domain;

                  for (int k = 0; k < pCVDomain.CodedValues.Length; k++)

                  {

                  pCV = pCVDomain.CodedValues[k];

                        pNodeDomain.Nodes.Add("Code: " + pCV.Code + " (Description: " + pCV.Name + ")");

            }

}

else

            {

            pRDomain = (MapServerWS.RangeDomain)pFDInfo.Domain;

                  pNodeDomain.Nodes.Add("Min: '" + pRDomain.MinValue + "'");

                  pNodeDomain.Nodes.Add("Max: '" + pRDomain.MaxValue + "'");

}

}

}

pNodeRoot.ExpandAll();

GetMapTile

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapFusedCache/MapServer";

 

string mapname = mapservice.GetDefaultMapName();

MapServerInfo mapinfo = mapservice.GetServerInfo(mapname);

MapDescription mapdesc = mapinfo.DefaultMapDescription;

// Pixel height and width of map display on the client. In this case, a Windows Form

// PictureBox control.

int picturewidth = pictureBox1.Width;

int pictureheight = pictureBox1.Height;

EnvelopeN mapextent = (EnvelopeN)mapdesc.MapArea.Extent;

// Use map scale resolution (map units per pixel) to determine tile level

double mapresolution = Math.Abs(mapextent.XMax - mapextent.XMin) / picturewidth;

System.Drawing.Bitmap imgbitmap = new System.Drawing.Bitmap(picturewidth, pictureheight);

System.Drawing.Graphics imggraphics = System.Drawing.Graphics.FromImage(imgbitmap);

imggraphics.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.LightGray), 0, 0, picturewidth, pictureheight);

if (mapservice.HasSingleFusedMapCache(mapname))

{

      TileCacheInfo tci = mapservice.GetTileCacheInfo(mapname);

      LODInfo[] tcis = tci.LODInfos;

      // Map units per pixel

      double tileresolution = 0;

      // Scale level

      int tilelevel = 0;

      foreach (LODInfo ldi in tcis)

      {

            double ldi_resolution = ldi.Resolution;

            tileresolution = ldi_resolution;

            tilelevel = ldi.LevelID;

            if (mapresolution >= ldi_resolution)

            {

                  break;

            }

      }

      // Measured from the origin

      double minx = mapextent.XMin;

      double miny = mapextent.YMin;

      double maxx = mapextent.XMax;

      double maxy = mapextent.YMax;

      // Origin of the cache (upper left corner)

      double xorigin = ((PointN)tci.TileOrigin).X;

      double yorigin = ((PointN)tci.TileOrigin).Y;

      // Get minimum tile column

      double minxtile = (minx - xorigin) / (tci.TileCols * tileresolution);

      // Get minimum tile row

      // From the origin, maxy is minimum y

      double minytile = (yorigin - maxy) / (tci.TileRows * tileresolution);

 

      // Get maximum tile column

      double maxxtile = (maxx - xorigin) / (tci.TileCols * tileresolution);

      // Get maximum tile row

      // From the origin, miny is maximum y

      double maxytile = (yorigin - miny) / (tci.TileRows * tileresolution);

      // Return integer value for min and max, row and column

      int mintilecolumn = (int)Math.Floor(minxtile);

      int mintilerow = (int)Math.Floor(minytile);

      int maxtilecolumn = (int)Math.Floor(maxxtile);

      int maxtilerow = (int)Math.Floor(maxytile);

      // Origin of the min tile

      double xmintileorigin = xorigin + (mintilecolumn * (tci.TileCols * tileresolution));

      double ymintileorigin = yorigin - (mintilerow * (tci.TileRows * tileresolution));

      // Since the origin of the extent and origin of the min tile are different

      // get the difference and use to place consolidated image graphic in correct location

      double xadjust = Math.Abs(minx - xmintileorigin);

      double yadjust = Math.Abs(maxy - ymintileorigin);

      int xpixadjust = (int)(xadjust / tileresolution);

      int ypixadjust = (int)(yadjust / tileresolution);

      TileImageInfo tii = mapservice.GetTileImageInfo(mapservice.GetDefaultMapName());

      int rowindex = 0;

      // for each row in the map extent

      for (int row = mintilerow; row <= maxtilerow; row++)

      {

            int colindex = 0;

            // for each column in the row, in the map extent

            for (int col = mintilecolumn; col <= maxtilecolumn; col++)

            {

                  byte[] myByteArray = null;

                  string cacheUrl = null;

                  try

                  {

                        // Return the byte array of the tile image

                        myByteArray = mapservice.GetMapTile(mapname, tilelevel, row, col, tii.CacheTileFormat);

                        // -or-

                        // Construct url manually

                        cacheUrl = virtualCacheDirectory + "/L" + tilelevel.ToString().PadLeft(2, '0')

                        + "/R" + row.ToString("x").PadLeft(8, '0') + "/C"

                        + col.ToString("x").PadLeft(8, '0') + imgType;

                        HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(cacheUrl);
      
                        HttpWebResponse webresp = (HttpWebResponse)webreq.GetResponse();

                        // Can also use: System.Drawing.Image.FromStream(webresp.GetResponseStream()) to

                        // read http response with image data

                        System.IO.Stream theStream = webresp.GetResponseStream();

                        int byte1;

                        System.IO.MemoryStream tempStream = new System.IO.MemoryStream();

                        while ((byte1 = theStream.ReadByte()) != -1)

                        {

                              tempStream.WriteByte(((byte)byte1));

                        }

                        myByteArray = tempStream.ToArray();

                  }

                  catch

                  {

                        // Tile may not be available because no data was present when creating the cache

                  }

                  // If Tile was found, add it to the consolidated image graphic

                  if (myByteArray != null)

                  {

                        System.Drawing.Image newImage;

                        using (System.IO.MemoryStream ms = new System.IO.MemoryStream(myByteArray, 0, myByteArray.Length))

                        {

                              ms.Write(myByteArray, 0, myByteArray.Length);

                              newImage = Image.FromStream(ms, true);

                              imggraphics.DrawImage

                              (newImage, (tci.TileCols * colindex) - xpixadjust, (tci.TileRows * rowindex) - ypixadjust, tci.TileCols, tci.TileRows);

                        }

                  }

                  colindex++;

            }

            rowindex++;

      }

}

// Post-processing, if necessary... otherwise just use imgbitmap with PictureBox

System.Drawing.Bitmap picturebitmap = new System.Drawing.Bitmap(picturewidth, pictureheight);

System.Drawing.Graphics graphicsimage = System.Drawing.Graphics.FromImage(picturebitmap);

graphicsimage.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.LightGray), 0, 0, picturewidth, pictureheight);

graphicsimage.DrawImage(imgbitmap, 0, 0, picturewidth, pictureheight);

pictureBox1.Image = picturebitmap;

GetServerInfo

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapFusedCache/MapServer";

string mapname = mapservice.GetDefaultMapName();

MapServerInfo mapinfo = mapservice.GetServerInfo(mapname);

GetServiceConfigurationInfo

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

string mapname = mapservice.GetDefaultMapName();

PropertySet serviceproperties = mapservice.GetServiceConfigurationInfo();

PropertySetProperty[] propertyarray = serviceproperties.PropertyArray;

foreach (PropertySetProperty serviceprop in propertyarray)

{

      string key = serviceprop.Key.ToString();

      string value = serviceprop.Value.ToString();

}

GetSQLSyntaxInfo

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

string mapname = mapservice.GetDefaultMapName();

MapServerInfo mapinfo = mapservice.GetServerInfo(mapname);

MapDescription mapdesc = mapinfo.DefaultMapDescription;

LayerDescription[] layerdescriptions = mapdesc.LayerDescriptions;

foreach (LayerDescription layerdesc in layerdescriptions)

{

      SQLSyntaxInfo sqlsyntaxinfo = mapservice.GetSQLSyntaxInfo(mapname, layerdesc.LayerID);

}

GetSupportedImageReturnTypes

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

// Mime or Url

esriImageReturnType imgreturntype = mapservice.GetSupportedImageReturnTypes();

GetTileCacheInfo

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapFusedCache/MapServer";

string mapname = mapservice.GetDefaultMapName();

if (mapservice.HasSingleFusedMapCache(mapname))

{

      TileCacheInfo tilecacheinfo = mapservice.GetTileCacheInfo(mapname);

}

GetTileImageInfo

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapFusedCache/MapServer";

string mapname = mapservice.GetDefaultMapName();

if (mapservice.HasSingleFusedMapCache(mapname))

{

      TileImageInfo tileimageinfo = mapservice.GetTileImageInfo(mapname);

}

GetVirtualCacheDirectory

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapFusedCache/MapServer";

string mapname = mapservice.GetDefaultMapName();

// Use -1 for fused caches

string virtualcachedirectory = mapservice.GetVirtualCacheDirectory(mapname, -1);

HasLayerCache

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapLayerCache/MapServer";

string mapname = mapservice.GetDefaultMapName();

MapServerInfo mapinfo = mapservice.GetServerInfo(mapname);

MapDescription mapdesc = mapinfo.DefaultMapDescription;

LayerDescription[] layerdescriptions = mapdesc.LayerDescriptions;

int[] layerids = new int[layerdescriptions.Length];

int i = 0;

foreach (LayerDescription layerdesc in layerdescriptions)

{

      if (mapservice.HasLayerCache(mapname, layerdesc.LayerID))

      {

            string layercachename = mapservice.GetCacheName(mapname, layerdesc.LayerID);

      }

}

HasSingleFusedMapCache

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapFusedCache/MapServer";

string mapname = mapservice.GetDefaultMapName();

if (mapservice.HasSingleFusedMapCache(mapname))

{

      string fusedcachename = mapservice.GetCacheName(mapname, -1);

}

Identify

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

MapServerInfo mapinfo = mapservice.GetServerInfo(mapservice.GetDefaultMapName());

MapDescription mapdesc = mapinfo.DefaultMapDescription;

 

ImageDisplay imgdisp = new ImageDisplay();

imgdisp.ImageHeight = 500; //pixels

imgdisp.ImageWidth = 500; //pixels

imgdisp.ImageDPI = 96;

 

PointN inputpoint = new PointN();

inputpoint.X = -110.0;

inputpoint.Y = 35.0;

 

// Value in pixels. Converted to map units using image (pixels) and map (map units) extent.

int tolerance = 3;

esriIdentifyOption identifyoption = esriIdentifyOption.esriIdentifyAllLayers;

LayerDescription[] layerdescriptions = mapdesc.LayerDescriptions;

int[] layerids = new int[layerdescriptions.Length];

int i = 0;

 

foreach (LayerDescription layerdesc in layerdescriptions)

{

      layerids.SetValue(layerdesc.LayerID, i++);

}

 

MapServerIdentifyResult[] identifyresults = mapservice.Identify(mapdesc, imgdisp, inputpoint, tolerance, identifyoption, layerids);

IsFixedScaleMap

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapLayerCache/MapServer";

string mapname = mapservice.GetDefaultMapName();

if (mapservice.IsFixedScaleMap(mapname))

{

      TileCacheInfo tilecacheinfo = mapservice.GetTileCacheInfo(mapname);

}

QueryDataStatistics

//Sample code shows getting maximum value from LANDVAL field

StatisticDescription pStatDesc = new StatisticDescription() 
{
	StatisticType = esriDataStatType.esriDataStatTypeMax,
	StatisticFieldName = "LANDVAL",
	ResultFieldName = "max_landval"
};

StatisticDescription[] pStatDescs = new StatisticDescription[1];
pStatDescs[0] = pStatDesc;
StatisticsRequest pStatReq = new StatisticsRequest();
pStatReq.StatisticDescriptions = pStatDescs;
RecordSet pRS = pMapServer.QueryDataStatistics(pMapServer.GetDefaultMapName(), m_pMapTableDescription, pStatReq, null);

QueryFeatureCount

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

string mapname = mapservice.GetDefaultMapName();

MapServerInfo mapinfo = mapservice.GetServerInfo(mapname);

MapDescription mapdesc = mapinfo.DefaultMapDescription;

MapLayerInfo[] maplayerinfos = mapinfo.MapLayerInfos;

int layerid = 0;

string geometryfieldname = string.Empty;

foreach (MapLayerInfo layerinfo in maplayerinfos)

      if (layerinfo.Name == "countries")

      {

            layerid = layerinfo.LayerID;

            Field[] fields = layerinfo.Fields.FieldArray;

            foreach (Field field in fields)

            {

                  if (field.Type == esriFieldType.esriFieldTypeGeometry)

                  {

                        geometryfieldname = field.Name;

                        break;

                  }

            }

      }

}

EnvelopeN envelope = new EnvelopeN();

envelope.XMin = 0.0;

envelope.YMin = 0.0;

envelope.XMax = 180.0;

envelope.YMax = 90.0;

SpatialFilter spatialfilter = new SpatialFilter();

spatialfilter.FilterGeometry = envelope;

spatialfilter.GeometryFieldName = geometryfieldname;

spatialfilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

spatialfilter.WhereClause = "POP_CNTRY > 50000000";

int featurecount = mapservice.QueryFeatureCount(mapname, layerid, spatialfilter);

QueryFeatureCount2

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

string mapname = mapservice.GetDefaultMapName();

MapServerInfo mapinfo = mapservice.GetServerInfo(mapname);

MapDescription mapdesc = mapinfo.DefaultMapDescription;

MapLayerInfo[] maplayerinfos = mapinfo.MapLayerInfos;

int layerid = 0;

string geometryfieldname = string.Empty;

foreach (MapLayerInfo layerinfo in maplayerinfos)

{

      if (layerinfo.Name == "countries")

      {

            layerid = layerinfo.LayerID;

            Field[] fields = layerinfo.Fields.FieldArray;

            foreach (Field field in fields)

            {

                  if (field.Type == esriFieldType.esriFieldTypeGeometry)

                  {

                        geometryfieldname = field.Name;

                        break;

                  }

            }

      }

}

LayerDescription[] layerdescs = mapdesc.LayerDescriptions;

LayerDescription activelayerdesc = null;

foreach (LayerDescription layerdesc in layerdescs)

{

      if (layerdesc.LayerID == layerid)

      {

            activelayerdesc = layerdesc;

            break;

      }

}

activelayerdesc.DefinitionExpression = "POP_CNTRY > 50000000";

EnvelopeN envelope = new EnvelopeN();

envelope.XMin = 0.0;

envelope.YMin = 0.0;

envelope.XMax = 180.0;

envelope.YMax = 90.0;

SpatialFilter spatialfilter = new SpatialFilter();

spatialfilter.FilterGeometry = envelope;

spatialfilter.GeometryFieldName = geometryfieldname;

spatialfilter.SpatialRel= esriSpatialRelEnum.esriSpatialRelIntersects;

int featurecount = mapservice.QueryFeatureCount2(mapname, activelayerdesc, spatialfilter);

QueryFeatureData

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

MapServerInfo mapinfo = mapservice.GetServerInfo(mapname);

MapDescription mapdesc = mapinfo.DefaultMapDescription;

MapLayerInfo[] maplayerinfos = mapinfo.MapLayerInfos;

int layerid = 0;

string geometryfieldname = string.Empty;

foreach (MapLayerInfo layerinfo in maplayerinfos)

{

      if (layerinfo.Name == "countries")

      {

            layerid = layerinfo.LayerID;

            Field[] fields = layerinfo.Fields.FieldArray;

            foreach (Field field in fields)

            {

                  if (field.Type == esriFieldType.esriFieldTypeGeometry)

                  }

                        geometryfieldname = field.Name;

                        break;

                  }

            }

      }

}

 

QueryFilter queryfilter = new QueryFilter();

queryfilter.WhereClause = "CNTRY_NAME LIKE '%United%'";

RecordSet recordset = null;

 

try

{

      recordset = mapservice.QueryFeatureData(mapname, layerid, queryfilter);

}

catch (Exception ex)

}

      // Improper format of where clause will cause exception

}

 

if (recordset != null)

{

      string fieldsoutput = string.Empty;

      foreach (Field field in recordset.Fields.FieldArray)

      {

            fieldsoutput += field.Name + "\t";

            foreach (Record record in recordset.Records)

            {

                  string valuesoutput = string.Empty;

                  object[] values = record.Values;

                  int v = 0;

                  foreach (Field field in recordset.Fields.FieldArray)

                  {

                        valuesoutput += values[v].ToString() + "\t";

                        v++;

                  }

            }

      }

}

QueryFeatureData2

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

 

string mapname = mapservice.GetDefaultMapName();

MapServerInfo mapinfo = mapservice.GetServerInfo(mapname);

 

MapDescription mapdesc = mapinfo.DefaultMapDescription;

MapLayerInfo[] maplayerinfos = mapinfo.MapLayerInfos;

string geometryfieldname = string.Empty;

 

foreach (MapLayerInfo layerinfo in maplayerinfos)

{

      if (layerinfo.Name == "countries")

      {

            layerid = layerinfo.LayerID;

            Field[] fields = layerinfo.Fields.FieldArray;

            foreach (Field field in fields)

            {

                  if (field.Type == esriFieldType.esriFieldTypeGeometry)

                  {

                        geometryfieldname = field.Name;

                        break;

                  }

            }

      }

}

 

LayerDescription[] layerdescs = mapdesc.LayerDescriptions;

LayerDescription activelayerdesc = null;

 

foreach (LayerDescription layerdesc in layerdescs)

{

      if (layerdesc.LayerID == layerid)

      {

            activelayerdesc = layerdesc;

            break;

      }

}

 

//Probably defined by a call to QueryFeatureIDs

activelayerdesc.DefinitionExpression = "FID IN (214, 228, 235, 245)";

 

QueryFilter queryfilter = new QueryFilter();

queryfilter.WhereClause = "CNTRY_NAME LIKE '%United%'";

QueryResultOptions queryresultoptions = new QueryResultOptions();

queryresultoptions.Format = esriQueryResultFormat.esriQueryResultRecordSetAsObject;

 

QueryResult queryresult = null;

try

{

      queryresult = mapservice.QueryFeatureData2(mapname, activelayerdesc, queryfilter, queryresultoptions);

}

catch (Exception ex)

{

      //Improper format of where clause will cause exception

}

 

RecordSet recordset = (RecordSet)queryresult.Object;

 

queryresultoptions.Format = esriQueryResultFormat.esriQueryResultKMLAsURL;

 

try

{

      queryresult = mapservice.QueryFeatureData2(mapname, activelayerdesc, queryfilter, queryresultoptions);

}

catch (Exception ex)

}

      // Improper format of where clause will cause exception

}

 

string kmlurl = queryresult.URL;

QueryFeatureIDs

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

 

string mapname = mapservice.GetDefaultMapName();

 

MapServerInfo mapinfo = mapservice.GetServerInfo(mapname);

MapDescription mapdesc = mapinfo.DefaultMapDescription;

 

MapLayerInfo[] maplayerinfos = mapinfo.MapLayerInfos;

 

int layerid = 0;

string geometryfieldname = string.Empty;

foreach (MapLayerInfo layerinfo in maplayerinfos)

{

      if (layerinfo.Name == "countries")

      {

            layerid = layerinfo.LayerID;

            Field[] fields = layerinfo.Fields.FieldArray;

            foreach (Field field in fields)

            {

                  if (field.Type == esriFieldType.esriFieldTypeGeometry)

                  {

                        geometryfieldname = field.Name;

                        break;

                  }

            }

      }

}

 

QueryFilter queryfilter = new QueryFilter();

queryfilter.WhereClause = "CNTRY_NAME LIKE '%United%'";

 

FIDSet fidset = null;

try

{

      fidset = mapservice.QueryFeatureIDs(mapname, layerid, queryfilter);

}

catch (Exception ex)

{

      // Improper format of where clause will cause exception

}

 

LayerDescription[] layerdescriptions = mapdesc.LayerDescriptions;

 

foreach (LayerDescription layerdesc in layerdescriptions)

{

      if (layerdesc.LayerID == layerid)

      {

            layerdesc.SelectionFeatures = fidset.FIDArray;

      }

}

QueryFeatureIDs2

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

 

string mapname = mapservice.GetDefaultMapName();

MapServerInfo mapinfo = mapservice.GetServerInfo(mapname);

 

MapDescription mapdesc = mapinfo.DefaultMapDescription;

MapLayerInfo[] maplayerinfos = mapinfo.MapLayerInfos;

 

string geometryfieldname = string.Empty;

 

foreach (MapLayerInfo layerinfo in maplayerinfos)

{

      if (layerinfo.Name == "countries")

      {

            layerid = layerinfo.LayerID;

            Field[] fields = layerinfo.Fields.FieldArray;

            foreach (Field field in fields)

            {

                  if (field.Type == esriFieldType.esriFieldTypeGeometry)

                  {

                        geometryfieldname = field.Name;

                        break;

                  }

            }

      }

}

 

LayerDescription[] layerdescriptions = mapdesc.LayerDescriptions;

LayerDescription activelayerdesc = null;

 

foreach (LayerDescription layerdesc in layerdescriptions)

{

      if (layerdesc.LayerID == layerid)

      {

      activelayerdesc = layerdesc;

      break;

      }

}

 

activelayerdesc.DefinitionExpression = "POP_CNTRY > 50000000";

 

PointN pnt1 = new PointN();

pnt1.X = -120;

pnt1.Y = 35;

PointN pnt2 = new PointN();

pnt2.X = -60;

pnt2.Y = 20;

PointN pnt3 = new PointN();

pnt3.X = 80;

pnt3.Y = 35;

PointN[] pnts = new PointN[3];

pnts[0] = pnt1;

pnts[1] = pnt2;

pnts[2] = pnt3;

 

Ring[] rings = new Ring[1];

Ring ring = new Ring();

ring.PointArray = pnts;

rings[0] = ring;

 

PolygonN polygon = new PolygonN();

polygon.RingArray = rings;

 

SpatialFilter spatialfilter = new SpatialFilter();

spatialfilter.FilterGeometry = polygon;

spatialfilter.GeometryFieldName = geometryfieldname;

spatialfilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;

 

FIDSet fidset = null;

try

{

      fidset = mapservice.QueryFeatureIDs2(mapname, activelayerdesc, spatialfilter);

}

catch (Exception ex)

{

      // Improper format of where clause will cause exception

}

 

activelayerdesc.SelectionFeatures = fidset.FIDArray;

QueryHyperlinks

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

 

string mapname = mapservice.GetDefaultMapName();

 

MapServerInfo mapinfo = mapservice.GetServerInfo(mapservice.GetDefaultMapName());

MapDescription mapdesc = mapinfo.DefaultMapDescription;

 

ImageDisplay imgdisp = new ImageDisplay();

imgdisp.ImageHeight = 500; //pixels

imgdisp.ImageWidth = 500; //pixels

imgdisp.ImageDPI = 96;

 

LayerDescription[] layerdescriptions = mapdesc.LayerDescriptions;

int[] layerids = new int[layerdescriptions.Length];

 

int i = 0;

foreach (LayerDescription layerdesc in layerdescriptions)

{

layerids.SetValue(layerdesc.LayerID, i++);

}

 

MapServerHyperlink[] hyperlinkresults = mapservice.QueryHyperlinks(mapdesc, imgdisp, layerids);

QueryRelatedRecords

//Layer A (Layer ID = 1) is related to Table B (StandaloneTable ID = 2) and you want to find all rows in

//Table B related to a feature in Layer A whose ObjectID is 3. In this case, you need to do the followings:

 

//Step 1: create a RelateDescription and populate information

RelateDescription pRD = new RelateDescription();

pRD.RelationshipID = 2;

pRD.RelatedTableFields = "*"; //or you can a pass a subset of fields

pRD.ResultFormat = esriRelateResultFormat.esriRelateResultRelatedRecordSetAsObject;

 

//Step 2: create a FIDSet

int[] intOIDs = new int[1] {3};

FIDSet pSrcFIDSet = new FIDSet();

pSrcFIDSet.FIDArray = intOIDs;

 

//Step 3: execute the function

QueryResult pQR = QueryRelatedRecords(aMapName, 1, pSrcFIDSet, pRD);

 

//Step 4: get result

RelatedRecordSet pRelRecordSet = pQR.Object;

 

//number of elements in RelatedRecordGroups matches with number of ObjectID passed in as SourceFIDSet

RelatedRecordGroup pRelRecGroup = pRelRecordSet.RelatedRecordGroups[0];

Console.WriteLine("Feature with ObjectID = " + pRelRecGroup.SourceRowID.toString()); //object id of the source feature

Console.WriteLine("has " + pRelRecGroup.Records.length.toString() + " related rows");

ToMapPoints

MouseEventArgs mea = (MouseEventArgs)e;

int[] screenx = new int[1];

int[] screeny = new int[1];

 

screenx[0] = mea.X;

screeny[0] = mea.Y;

 

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";

 

MapServerInfo mapinfo = mapservice.GetServerInfo(mapservice.GetDefaultMapName());

MapDescription mapdesc = mapinfo.DefaultMapDescription;

 

ImageDisplay imgdisp = new ImageDisplay();

imgdisp.ImageHeight = 500; //pixels

imgdisp.ImageWidth = 500; //pixels

imgdisp.ImageDPI = 96;

 

MultipointN multipoint = (MultipointN)mapservice.ToMapPoints(mapdesc, imgdisp, screenx, screeny);

NAServer

GetNALayerNames

// Connect to server

NAService_NAServer naService = new NAService_NAServer();

naService.Url = "http://localhost:6080/ArcGIS/services/NetworkAnalysisService/MapServer/NAServer");

// Get Route layers

string[] routeLayers = naService.GetNALayerNames( class=codesample>esriNAServerLayerType.esriNAServerRouteLayer);

GetNetworkDescription

// Connect to server

NAService_NAServer naService = new NAService_NAServer();

naService.Url = "http://localhost:6080/ArcGIS/services/NetworkAnalysisService/MapServer/NAServer"); 

// Get Route layers

string[] routeLayers = naService.GetNALayerNames(esriNAServerLayerType.esriNAServerRouteLayer);

// Get the network settings for the first route layer, iterate through the attribute names and usage types

NAServerNetworkDescription naServerNetworkDescription = naService.GetNetworkDescription(routeLayers[0]);

foreach (NAServerNetworkAttribute naServerNetworkAttribute in naServerNetworkDescription.NetworkAttributes)

{

      string name = naServerNetworkAttribute.Name;

      esriNetworkAttributeUsageType usageType = naServerNetworkAttribute.UsageType;

}

GetSolverParameters

// Connect to server

NAService_NAServer naService = new NAService_NAServer();

naService.Url = "http://localhost:6080/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]);

Solve

namespace NetworkSoapSamples
{

  public class ExtendedNAServerProxy : ESRI.ArcGIS.SOAP.NAServerProxy
  {
    private string m_referer;
    public ExtendedNAServerProxy(string referer)
    {
      m_referer = referer;
    }

    protected override System.Net.WebRequest GetWebRequest(Uri uri)
    {

      System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)base.GetWebRequest(uri);

      webRequest.Referer = m_referer;

      return webRequest;

    }
  }

  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void btnRun_Click(object sender, EventArgs e)
    {
      SolveRoute();
      SolveClosestFacililty();
    }


    private void SolveRoute()
    {
      string username = "org_username";
      string password = "org_password";
      string referer = "soapSample";
      string url = "https://route.arcgis.com/arcgis/services/World/Route/MapServer/NAServer";

      // Create a reference to the NAServer service and append the arcgis.com token
      NAServerProxy naService = new ExtendedNAServerProxy(referer);
      naService.Url = GetURLWithToken(url, username, password, referer);


      // Get the default settings for the world route layer
      NAServerRouteParams naServerRouteParams = (NAServerRouteParams)naService.GetSolverParameters("Route_World");


      // Create 2 stops
      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));
      NAServerPropertySets naServerPropertySets = new NAServerPropertySets();
      naServerPropertySets.PropertySets = propertySets.ToArray();
      naServerRouteParams.Stops = naServerPropertySets;

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


      // Solve
      NAServerRouteResults naServerRouteResults = (NAServerRouteResults)naService.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);
      MessageBox.Show(sb.ToString());

    }

    void SolveClosestFacililty()
    {
      string username = "org_username";
      string password = "org_password";
      string referer = "soapSample";
      string url = "https://route.arcgis.com/arcgis/services/World/ClosestFacility/MapServer/NAServer";

      // Create a reference to the NAServer service and append the arcgis.com token
      NAServerProxy naService = new ExtendedNAServerProxy(referer);
      naService.Url = GetURLWithToken(url, username, password, referer);


      // Get the default settings for the world closest facility layer
      NAServerClosestFacilityParams naServerClosestFacilityParams = (NAServerClosestFacilityParams)naService.GetSolverParameters("ClosestFacility_World");


      // Create 2 facilities
      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));
      NAServerPropertySets facilitiesPropertySets = new NAServerPropertySets();
      facilitiesPropertySets.DoNotLocateOnRestrictedElements = true;
      facilitiesPropertySets.DoNotLocateOnRestrictedElementsSpecified = true;
      facilitiesPropertySets.PropertySets = propertySets.ToArray();
      naServerClosestFacilityParams.Facilities = facilitiesPropertySets;


      // Create 1 incident
      propertySets = new List<PropertySet>(1);
      propertySets.Add(CreatePropertySet("My incident", -117.0, 34.0));
      NAServerPropertySets incidentsPropertySets = new NAServerPropertySets();
      incidentsPropertySets.DoNotLocateOnRestrictedElements = true;
      incidentsPropertySets.DoNotLocateOnRestrictedElementsSpecified = true;
      incidentsPropertySets.PropertySets = propertySets.ToArray();
      naServerClosestFacilityParams.Incidents = incidentsPropertySets;

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


      // Solve
      NAServerClosestFacilityResults naServerClosestFacilityResults = (NAServerClosestFacilityResults)naService.Solve(naServerClosestFacilityParams);


      // Output directions
      NACompactStreetDirections streetDirections = naServerClosestFacilityResults.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);

      MessageBox.Show(sb.ToString());
    }

    private string GetURLWithToken(string url, string username, string password, string referer)
    {
      // Add token to service URL if required

      string tokenServiceURL;
      ServiceCatalogProxy serviceCatalogProxy = new ServiceCatalogProxy();
      serviceCatalogProxy.Url = url.Substring(0, url.IndexOf("/services") + 9);
      if (serviceCatalogProxy.RequiresTokens())
      {
        tokenServiceURL = serviceCatalogProxy.GetTokenServiceURL();

        // Get token
        string token;
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.CreateDefault(new Uri(tokenServiceURL + "?f=json&expiration=60" +
                    "&username=" + username + "&password=" + password + "&referer=" + referer));
        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        Stream responseStream = response.GetResponseStream();
        using (StreamReader reader = new StreamReader(responseStream))
        {
          string responseText = reader.ReadToEnd();
          if ((responseText.Length == 0) || (responseText.IndexOf("error") > -1))
          {
            MessageBox.Show("Error getting token.");
            return url;
          }

          int startPos = 12;
          int endPos = responseText.IndexOf("\"", startPos);
          token = responseText.Substring(startPos, endPos - startPos);

          reader.Close();
        }
        responseStream.Close();
        response.Close();

        // Add token to the URL
        return url + "?token=" + token;
      }
      else
      {
        return url;
      }
    }

    private PropertySet CreatePropertySet(string name, double x, double y)
    {
      List<PropertySetProperty> propertySetPropertyList = new List<PropertySetProperty>(3);
      propertySetPropertyList.Add(CreatePropertySetProperty("Name", name));
      propertySetPropertyList.Add(CreatePropertySetProperty("X", x));
      propertySetPropertyList.Add(CreatePropertySetProperty("Y", y));

      PropertySet propertySet = new PropertySet();
      propertySet.PropertyArray = propertySetPropertyList.ToArray();

      return propertySet;
    }

    private PropertySetProperty CreatePropertySetProperty(string key, object value)
    {
      PropertySetProperty propertySetProperty = new PropertySetProperty();
      propertySetProperty.Key = key;
      propertySetProperty.Value = value;

      return propertySetProperty;
    }
  }
}

11/8/2016