S A M P L E S

 

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

MapServer

GeocodeServer

GPServer

GeoDataServer

GeometryServer

ImageServer

NAServer

 

Catalog

 

GetFolders

 

Catalog catalog = new Catalog();

catalog.Url = "http://localhost/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/arcgis/services";

esriServiceCatalogMessageFormat messageformat = catalog.GetMessageFormats();

 

GetMessageVersion

 

Catalog catalog = new Catalog();

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

esriArcGISVersion arcgisversion = catalog.GetMessageVersion();

 

GetServiceDescriptions

 

Catalog catalog = new Catalog();

catalog.Url = "http://localhost/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/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/arcgis/services";

 

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost/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/arcgis/services";

 

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost/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();

 

MapServer

 

ComputeDistance

 

MapService_MapServer mapservice = new MapService_MapServer();

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

 

GetCacheName

 

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost/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/arcgis/services/MapFusedCache/MapServer";

 

string mapname = mapservice.GetDefaultMapName();

CacheControlInfo cachecontrlinfo = mapservice.GetCacheControlInfo(mapname);

 

GetCacheDescriptionInfo

 

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost/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/arcgis/services/MapLayerCache/MapServer";

 

string mapname = mapservice.GetDefaultMapName();

 

GetDocumentInfo

 

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost/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/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/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/arcgis/services/MapService/MapServer";

int mapcount = mapservice.GetMapCount();

 

GetMapName

 

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost/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/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/arcgis/services/MapFusedCache/MapServer";

string mapname = mapservice.GetDefaultMapName();

MapServerInfo mapinfo = mapservice.GetServerInfo(mapname);

 

GetServiceConfigurationInfo

 

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost/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/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/arcgis/services/MapService/MapServer";

// Mime or Url

esriImageReturnType imgreturntype = mapservice.GetSupportedImageReturnTypes();

 

GetTileCacheInfo

 

MapService_MapServer mapservice = new MapService_MapServer();

mapservice.Url = "http://localhost/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/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/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/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/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/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/arcgis/services/MapLayerCache/MapServer";

string mapname = mapservice.GetDefaultMapName();

if (mapservice.IsFixedScaleMap(mapname))

{

TileCacheInfo tilecacheinfo = mapservice.GetTileCacheInfo(mapname);

}

 

QueryFeatureCount

 

MapService_MapServer mapservice = new MapService_MapServer();

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

 

GeocodeServer

 

FindAddressCandidates

 

GeocodeService_GeocodeServer geocodeservice = new GeocodeService_GeocodeServer();

geocodeservice.Url = "http://localhost/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/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

 

GeocodeService_GeocodeServer geocodeservice = new GeocodeService_GeocodeServer();

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

 

// 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 = "Street";

geocodeProp.Value = "Street";

propArray[0] = geocodeProp;

 

PropertySetProperty geocodeProp1 = new PropertySetProperty();

geocodeProp1.Key = "Zone";

geocodeProp1.Value = "Zone";

propArray[1] = geocodeProp1;

geocodePropSet.PropertyArray = propArray;

 

// Create a new recordset to store input addresses to be batch geocoded

RecordSet addressTable = new RecordSet();

 

// Create fields for input address table

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 = "Street";

field1.Type = esriFieldType.esriFieldTypeString;

field1.Length = 50;

fieldarray[1] = field1;

 

Field field2 = new Field();

field2.Name = "Zone";

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;

 

// Generate results table

RecordSet results = geocodeservice.GeocodeAddresses(addressTable, geocodePropSet, null);

if (results != null)

{

string fieldsoutput = string.Empty;

foreach (Field field in results.Fields.FieldArray)

{

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

}

 

foreach (Record record in results.Records)

{

string valuesoutput = string.Empty;

object[] values = record.Values;

int v = 0;

 

foreach (Field field in results.Fields.FieldArray)

{

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

v++;

}

}

}

 

GetAddressFields

 

GeocodeService_GeocodeServer geocodeservice = new GeocodeService_GeocodeServer();

geocodeservice.Url = "http://localhost/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/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/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/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/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/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/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/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/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/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>=

 

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

 

GeoDataServer

 

GetDefaultWorkingVersion

 

GeodataService_GeodataServer geodataservice = new GeodataService_GeodataServer();

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

 

string defaultversionname = geodataservice.GetDefaultWorkingVersion();

 

GetMaxRecordCount

 

GeodataService_GeodataServer geodataservice = new GeodataService_GeodataServer();

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

 

int maxrecordcount = geodataservice.GetMaxRecordCount(); 

 

GetVersions

 

GeodataService_GeodataServer geodataservice = new GeodataService_GeodataServer();

geodataservice.Url = "http://localhost/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/arcgis/services/GeodataServiceLocal/GeodataServer"; 

esriWorkspaceType workspacetype = geodataservice.GetWrappedWorkspaceType(); 

 

GeometryServer

 

Buffer

 

Geometry_GeometryServer geometryService = new Geometry_GeometryServer();

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

 

ImageServer

 

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);

 

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();

 

NAServer

 

GetNALayerNames 

 

// Connect to server

NAService_NAServer naService = new NAService_NAServer();

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

 

private void SolveRoute()

{

// Connect to server

NAService_NAServer naService = new NAService_NAServer();

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

 

// Create 2 stops as property sets

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));

 

// Set the property sets on a NAServerPropertySets object and set on the routeParams object

NAServerPropertySets naServerPropertySets = new NAServerPropertySets();

naServerPropertySets.PropertySets = propertySets.ToArray();

naServerRouteParams.Stops = naServerPropertySets;

 

// specify to return compact directions

naServerRouteParams.ReturnCompactDirections = true;

 

// Solve

NAServerRouteResults naServerRouteResults = (NAServerRouteResults)naServer.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());

}

 

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;

}