ArcObjects Library Reference  

Form1

About the Simple SOE Sample

[C#]

Form1.cs

using System;
using System.Drawing;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Server;
using SimpleSOEInterfaces_CSharp;

namespace SimpleSOE_WinFormApp
{
    public partial class Form1 : Form
    {
        private string serverName = "localhost";
        private string serviceName = "Yellowstone";
        private ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection gisconnection;
        private IServerContext serverContext;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                gisconnection =
                    new ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection();
                gisconnection.Host = serverName;
                gisconnection.Connect();

                IServerObjectManager serverManager = gisconnection.ServerObjectManager;
                serverContext = serverManager.CreateServerContext(serviceName, "MapServer");
                IMapServer mapServer = serverContext.ServerObject as IMapServer;

                IMapServerInfo mapServerInfo = mapServer.GetServerInfo(mapServer.DefaultMapName);
                IMapDescription mapDesc = mapServerInfo.DefaultMapDescription;

                #region Server Object Extension client code
                IServerObjectExtensionManager soexm = (IServerObjectExtensionManager)mapServer;
                IServerObjectExtension soext = soexm.FindExtensionByTypeName("SimpleSOE_CSharp");
                IUtilSOE_CSharp utilsoe = (IUtilSOE_CSharp)soext;

                IPoint pnt = serverContext.CreateObject("esriGeometry.Point") as IPoint;
                pnt.PutCoords(mapDesc.MapArea.Extent.XMin + (mapDesc.MapArea.Extent.Width / 2),
                    mapDesc.MapArea.Extent.YMin + (mapDesc.MapArea.Extent.Height / 2));
                double radius = mapDesc.MapArea.Extent.Width / 8;
                IPolygon circle = (IPolygon)utilsoe.ReturnCircle(ref pnt, ref radius);
                
                IElement element = serverContext.CreateObject("esriCarto.PolygonElement") as IElement;
                element.Geometry = circle;

                IFillShapeElement fillElement = element as IFillShapeElement;                
                ISimpleFillSymbol fillSymbol = 
                    serverContext.CreateObject("esriDisplay.SimpleFillSymbol") as ISimpleFillSymbol;
                
                IRgbColor rgbColor = serverContext.CreateObject("esriDisplay.RgbColor") as IRgbColor;
                rgbColor.Red = 0;
                rgbColor.Green = 255;
                rgbColor.Blue = 255; 
    
                fillSymbol.Color = rgbColor as IColor;
                fillElement.Symbol = fillSymbol;

                if (mapDesc.CustomGraphics == null)
                    mapDesc.CustomGraphics = serverContext.CreateObject("esriCarto.GraphicElements") as IGraphicElements;
                mapDesc.CustomGraphics.Add(element as IGraphicElement);
                #endregion

                IImageDescription imageDesc = serverContext.CreateObject("esriCarto.ImageDescription") as IImageDescription;

                IImageType imgType = serverContext.CreateObject("esriCarto.ImageType") as IImageType;
                imgType.Format = ESRI.ArcGIS.Carto.esriImageFormat.esriImageJPG;
                imgType.ReturnType = ESRI.ArcGIS.Carto.esriImageReturnType.esriImageReturnMimeData;

                IImageDisplay imageDisp =
                    serverContext.CreateObject("esriCarto.ImageDisplay") as IImageDisplay;

                imageDisp.Height = pictureBox1.Height;
                imageDisp.Width = pictureBox1.Width;
                imageDisp.DeviceResolution = 96;

                imageDesc.Type = imgType;
                imageDesc.Display = imageDisp;

                IMapImage mapImageOutput = mapServer.ExportMapImage(mapDesc, imageDesc);
                System.IO.Stream mimeStream = new System.IO.MemoryStream(mapImageOutput.MimeData);
                pictureBox1.Image = Image.FromStream(mimeStream);
                pictureBox1.Refresh();
            }
            catch (Exception ex) { }
            finally
            {
                serverContext.ReleaseContext();
                gisconnection.Dispose();
            }
        }
    }
}

[Visual Basic .NET]

Form1.vb

Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Display
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Server
Imports SimpleSOEInterfaces_VBNet

Namespace SimpleSOE_WinFormApp_VBNet
    Partial Public Class Form1
        Inherits Form
        Private serverName As String = "localhost"
        Private serviceName As String = "Yellowstone"
        Private gisconnection As ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection
        Private serverContext As IServerContext

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
            Try
                gisconnection = New ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection()
                gisconnection.Host = serverName
                gisconnection.Connect()

                Dim serverManager As IServerObjectManager = gisconnection.ServerObjectManager
                serverContext = serverManager.CreateServerContext(serviceName, "MapServer")
                Dim mapServer As IMapServer = TryCast(serverContext.ServerObject, IMapServer)

                Dim mapServerInfo As IMapServerInfo = mapServer.GetServerInfo(mapServer.DefaultMapName)
                Dim mapDesc As IMapDescription = mapServerInfo.DefaultMapDescription

                '				#Region "Server Object Extension client code"
                Dim soexm As IServerObjectExtensionManager = CType(mapServer, IServerObjectExtensionManager)
                Dim soext As IServerObjectExtension = soexm.FindExtensionByTypeName("SimpleSOE_VBNet")
                Dim utilsoe As IUtilSOE_VBNet = CType(soext, IUtilSOE_VBNet)

                Dim pnt As IPoint = TryCast(serverContext.CreateObject("esriGeometry.Point"), IPoint)
                pnt.PutCoords(mapDesc.MapArea.Extent.XMin + (mapDesc.MapArea.Extent.Width / 2), mapDesc.MapArea.Extent.YMin + (mapDesc.MapArea.Extent.Height / 2))
                Dim radius As Double = mapDesc.MapArea.Extent.Width / 8
                Dim circle As IPolygon = CType(utilsoe.ReturnCircle(pnt, radius), IPolygon)

                Dim element As IElement = TryCast(serverContext.CreateObject("esriCarto.PolygonElement"), IElement)
                element.Geometry = circle

                Dim fillElement As IFillShapeElement = TryCast(element, IFillShapeElement)
                Dim fillSymbol As ISimpleFillSymbol = TryCast(serverContext.CreateObject("esriDisplay.SimpleFillSymbol"), ISimpleFillSymbol)

                Dim rgbColor As IRgbColor = TryCast(serverContext.CreateObject("esriDisplay.RgbColor"), IRgbColor)
                rgbColor.Red = 0
                rgbColor.Green = 255
                rgbColor.Blue = 255

                fillSymbol.Color = TryCast(rgbColor, IColor)
                fillElement.Symbol = fillSymbol

                If mapDesc.CustomGraphics Is Nothing Then
                    mapDesc.CustomGraphics = TryCast(serverContext.CreateObject("esriCarto.GraphicElements"), IGraphicElements)
                End If
                mapDesc.CustomGraphics.Add(TryCast(element, IGraphicElement))
                '				#End Region

                Dim imageDesc As IImageDescription = TryCast(serverContext.CreateObject("esriCarto.ImageDescription"), IImageDescription)

                Dim imgType As IImageType = TryCast(serverContext.CreateObject("esriCarto.ImageType"), IImageType)
                imgType.Format = ESRI.ArcGIS.Carto.esriImageFormat.esriImageJPG
                imgType.ReturnType = ESRI.ArcGIS.Carto.esriImageReturnType.esriImageReturnMimeData

                Dim imageDisp As IImageDisplay = TryCast(serverContext.CreateObject("esriCarto.ImageDisplay"), IImageDisplay)

                imageDisp.Height = pictureBox1.Height
                imageDisp.Width = pictureBox1.Width
                imageDisp.DeviceResolution = 96

                imageDesc.Type = imgType
                imageDesc.Display = imageDisp

                Dim mapImageOutput As IMapImage = mapServer.ExportMapImage(mapDesc, imageDesc)
                Dim mimeStream As System.IO.Stream = New System.IO.MemoryStream(mapImageOutput.MimeData)
                pictureBox1.Image = Image.FromStream(mimeStream)
                pictureBox1.Refresh()
            Catch ex As Exception
            Finally
                serverContext.ReleaseContext()
                gisconnection.Dispose()
            End Try
        End Sub
    End Class
End Namespace