ArcGIS Simple Server Object Extension
ArcGIS_Simple_Server_Object_Extension_CSharp\SimpleSOE_CSharp\SimpleSOE_CSharp\UtilSOE_CSharp.cs
// Copyright 2009 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.
// 

using System;
using System.Runtime.InteropServices;
using System.EnterpriseServices;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Server;
using System.Xml;
using SimpleSOEInterfaces_CSharp;

namespace SimpleSOE_CSharp
{
    [AutomationProxy(true), ClassInterface(ClassInterfaceType.AutoDual), GuidAttribute("a9ed9e17-d2b2-461c-9da3-2915af9a3f00")]
    public class UtilSOE_CSharp : ServicedComponent, IUtilSOE_CSharp, IServerObjectExtension, IRequestHandler, IRequestHandler2
    {
        private IServerObjectHelper m_SOH;

        public IGeometry ReturnCircle(ref IPoint inpoint,ref double radius)
        {
            ESRI.ArcGIS.Geometry.ITopologicalOperator topop = (ESRI.ArcGIS.Geometry.ITopologicalOperator)inpoint;
            ESRI.ArcGIS.Geometry.IGeometry circle = topop.Buffer(radius);
            return circle;
        }

        #region IServerObjectExtension Members

        public void Init(IServerObjectHelper pSOH)
        {
            m_SOH = pSOH;
        }

        public void Shutdown()
        {
            m_SOH = null;
        }

        #endregion

        #region IRequestHandler Members

        byte[] IRequestHandler.HandleBinaryRequest(ref byte[] request)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        string IRequestHandler.HandleStringRequest(string Capabilities, string request)
        {
            return ProcessStringRequest(Capabilities, request);
        }
        #endregion

        #region IRequestHandler2 Members

        byte[] IRequestHandler2.HandleBinaryRequest(ref byte[] request)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        byte[] IRequestHandler2.HandleBinaryRequest2(string Capabilities, ref byte[] request)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        string IRequestHandler2.HandleStringRequest(string Capabilities, string request)
        {
            return ProcessStringRequest(Capabilities, request);
        }
        #endregion

        string ProcessStringRequest(string Capabilities, string request)
        {
            string response = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
            response += "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" ";
            response += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ";
            response += "xmlns:tns=\"http://www.esri.com/schemas/ArcGIS/9.3\">";
            response += "<soap:Body>";

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(request);
            XmlNode root = doc.DocumentElement; // Envelope
            XmlNode body = root.FirstChild;  // Body
            XmlNodeList childnodes = body.ChildNodes;

            if (childnodes.Count >= 1)
            {
                XmlNode child = childnodes[0];
                if (child.Name == "GetServerTime")
                {
                    response += "<tns:GetServerTimeResponse>";
                    string serverdate = DateTime.Now.ToLongDateString();
                    string servertime = DateTime.Now.ToLongTimeString();
                    response += "<Result>" + serverdate + " - " + servertime + "</Result>";
                    response += "</tns:GetServerTimeResponse>";
                }
                else
                {
                    response += "<tns:NullResponse>";
                    response += "<Result>Null Response</Result>";
                    response += "</tns:NullResponse>";
                }
            }

            response += "</soap:Body></soap:Envelope>";
            return response;
        }
    }
}