ArcIMS SendArcXML
ArcIMS_SendArcXML_VBNet\ArcXML.aspx.vb
' Copyright 2011 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.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports ESRI.ArcGIS.ADF.Connection.IMS

Public Partial Class ArcXML
  Inherits System.Web.UI.Page
  Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    'System.Net.ServicePointManager.Expect100Continue = false;
  End Sub

  Private Function unescapeXML(ByVal req As String) As String
    Dim reqlt As String = req.Replace("&lt;", "<")
    Dim reqgt As String = reqlt.Replace("&gt;", ">")
    Dim reqquot As String = reqgt.Replace("&quot;", """")
    Dim reqamp As String = reqquot.Replace("&amp;", "&")
    'String reqapos = reqamp.Replace("&apos;", "'");
    Return reqamp
  End Function

  Protected Sub button_send_ServerClick(ByVal sender As Object, ByVal e As EventArgs)
    Try
      Dim connection As IMSServerConnection = Nothing

      If RadioButtonListScheme.SelectedValue = "TCP" Then
        connection = New TCPConnection()
        Dim tcpconnection As TCPConnection = CType(connection, TCPConnection)
        tcpconnection.Host = text_server.Value
        tcpconnection.Port = Int32.Parse(text_port.Value)
        connection.ServiceName = text_service.Value
      ElseIf RadioButtonListScheme.SelectedValue = "HTTP" Then
        connection = New HTTPConnection(text_server.Value)
        Dim httpconnection As HTTPConnection = CType(connection, HTTPConnection)

                If Not text_port.Value = "80" Then
                    httpconnection.Port = Int32.Parse(text_port.Value)
                End If

        httpconnection.User = "private"
        httpconnection.Password = "pass.word"
        connection.ServiceName = text_service.Value
      End If

      '** Get ArrayList of ArcIMS service names ***
      'System.Collections.ArrayList arraylist = connection.ClientServicesArray();
      'IEnumerator arrayenum = arraylist.GetEnumerator();
      'while (arrayenum.MoveNext())
      '{
        'string servicename = (string)arrayenum.Current;
      '}

       '

      Dim CustomService As String = Nothing

      If checkbox_query.Checked Then
        CustomService = "Query"
      ElseIf checkbox_geocode.Checked Then
        CustomService = "Geocode"
      ElseIf checkbox_extract.Checked Then
        CustomService = "Extract"
      End If

      Dim request As String = unescapeXML(textarea_request.Value)
      Dim prolog As String = "<?xml version=""1.0"" encoding=""UTF-8""?>"

      Dim axlrequest As String = prolog & request

      Dim axlresponse As String = connection.Send(axlrequest, CustomService)
      textarea_response.Value = axlresponse

    Catch ex As Exception
      textarea_response.Value = ex.Message
    End Try
  End Sub
  Protected Sub RadioButtonListScheme_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    If RadioButtonListScheme.SelectedValue = "TCP" Then
        text_server.Value = "localhost"
        text_port.Value = "5300"
      ElseIf RadioButtonListScheme.SelectedValue = "HTTP" Then
        text_server.Value = "http://localhost"
        text_port.Value = "80"
      End If

  End Sub
End Class