ArcGIS Simple Server Object Extension
ArcGIS_Simple_Server_Object_Extension_VBNet\SimpleSOE_VBNet\SimpleSOE_VBNet\UtilSOE_VBNet.vb
' 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.
' 

Imports Microsoft.VisualBasic
Imports System
Imports System.Runtime.InteropServices
Imports System.EnterpriseServices
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Display
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Server
Imports System.Xml
Imports SimpleSOEInterfaces_VBNet

Namespace SimpleSOE_VBNet
    <AutomationProxy(True), ClassInterface(ClassInterfaceType.AutoDual), GuidAttribute("99ed9e17-d2b2-461c-9da3-2915af9a3f00")> _
 Public Class UtilSOE_VBNet
        Inherits ServicedComponent
        Implements IUtilSOE_VBNet, IServerObjectExtension, IRequestHandler, IRequestHandler2
        Private m_SOH As IServerObjectHelper

        Public Function ReturnCircle(ByRef inpoint As IPoint, ByRef radius As Double) As IGeometry Implements IUtilSOE_VBNet.ReturnCircle
            Dim topop As ESRI.ArcGIS.Geometry.ITopologicalOperator = CType(inpoint, ESRI.ArcGIS.Geometry.ITopologicalOperator)
            Dim circle As ESRI.ArcGIS.Geometry.IGeometry = topop.Buffer(radius)
            Return circle
        End Function

#Region "IServerObjectExtension Members"

        Public Sub Init(ByVal pSOH As IServerObjectHelper) Implements IServerObjectExtension.Init
            m_SOH = pSOH
        End Sub

        Public Sub Shutdown() Implements IServerObjectExtension.Shutdown
            m_SOH = Nothing
        End Sub

#End Region

#Region "IRequestHandler Members"

        Private Function HandleBinaryRequest(ByRef request() As Byte) As Byte() Implements IRequestHandler.HandleBinaryRequest
            Throw New Exception("The method or operation is not implemented.")
        End Function

        Private Function HandleStringRequest(ByVal Capabilities As String, ByVal request As String) As String Implements IRequestHandler.HandleStringRequest
            Return ProcessStringRequest(Capabilities, request)
        End Function
#End Region

#Region "IRequestHandler2 Members"

        Private Function HandleBinaryRequest2(ByRef request() As Byte) As Byte() Implements IRequestHandler2.HandleBinaryRequest
            Throw New Exception("The method or operation is not implemented.")
        End Function

        Private Function HandleBinaryRequest22(ByVal Capabilities As String, ByRef request() As Byte) As Byte() Implements IRequestHandler2.HandleBinaryRequest2
            Throw New Exception("The method or operation is not implemented.")
        End Function

        Private Function HandleStringRequest2(ByVal Capabilities As String, ByVal request As String) As String Implements IRequestHandler2.HandleStringRequest
            Return ProcessStringRequest(Capabilities, request)
        End Function
#End Region

        Private Function ProcessStringRequest(ByVal Capabilities As String, ByVal request As String) As String
            Dim response As String = "<?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>"

            Dim doc As New XmlDocument()
            doc.LoadXml(request)
            Dim root As XmlNode = doc.DocumentElement ' Envelope
            Dim body As XmlNode = root.FirstChild ' Body
            Dim childnodes As XmlNodeList = body.ChildNodes

            If childnodes.Count >= 1 Then
                Dim child As XmlNode = childnodes(0)
                If child.Name = "GetServerTime" Then
                    response &= "<tns:GetServerTimeResponse>"
                    Dim serverdate As String = DateTime.Now.ToLongDateString()
                    Dim servertime As String = DateTime.Now.ToLongTimeString()
                    response &= "<Result>" & serverdate & " - " & servertime & "</Result>"
                    response &= "</tns:GetServerTimeResponse>"
                Else
                    response &= "<tns:NullResponse>"
                    response &= "<Result>Null Response</Result>"
                    response &= "</tns:NullResponse>"
                End If
            End If

            response &= "</soap:Body></soap:Envelope>"
            Return response
        End Function
    End Class
End Namespace