Tuesday, March 22, 2005

ESRI Developer Network

Hey all. Great news! ESRI has come out with a developer network that seems to be a lot like Microsoft's MSDN. I don't know if you are familiar with the MSDN, but, if you're a subscriber, then you get all their software. This sofware is ONLY for development/testing purposes, but it is fun to "play" with. I am especially looking forward to getting my hands on the ArcGIS server and the ArcWeb credits.

http://edn.esri.com/

Happy Coding!

The underlying connection was closed: Could not establish trust relationship with remote server

Hello all. This week I have been coding extensively with the new .NET Link for ArcIMS. This is the native .NET connector that ESRI has shipped with ArcIMS 9. It seems to work great and has been much, much faster than the Active X connector. One problem I did run into was the error "The underlying connection was closed: Could not establish trust relationship with remote server". This error occured when I was using HTTPS as my scheme for connection to a remote (HTTPS) ArcIMS server.


The cause of this error is that my code doesn't like the credentials sent by the server in its HTTPS certificate. Help is on the way! The way around this error is to write your own certificate policy. Add this class to the class you are using to send the HTTPS request.


Public Class TrustAllCertificatePolicy
Implements System.Net.ICertificatePolicy
Public Sub TrustAllCertificatePolicy()
'Do Nothing
End Sub
Public Function CheckValidationResult(ByVal srvPoint As System.Net.ServicePoint, ByVal certificate As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal request As System.Net.WebRequest, ByVal certificateProblem As Integer) As Boolean Implements System.Net.ICertificatePolicy.CheckValidationResult
Return True
End Function
End Class
>


Then, make yourself a new certificate policy some time in the lifecycle of the page before you make the call. A good place for this call is in the page.load or in the constructor of your class, if you are going the three tier route.


System.Net.ServicePointManager.CertificatePolicy = New TrustAllCertificatePolicy


That's it! No more unhappy code.

Monday, January 17, 2005

Transforming AXL Responses with XSLT

Hello Everyone! This is the first post in what I hope will become a great place for exchanging ideas and code. For my first post, I would like to share something that I had difficulty finding out how to do on the internet and in the forums. I have a .NET class that sends an identify request to an ArcIMS server and then transforms the results using an XSLT Stylesheet. I send the AXL request using the .NET Link.


For this code to work, you will need the .NET Link installed on the machine you are using (server and dev machine). Create a new ASP.NET application in Visual Studio.NET. After you project has been created and loaded into VS.NET, add the .NET Link as a reference in your application. You can do this right-clicking on the references directory in the solution explorer and then choosing Add Reference from the resulting menu. If you don't see the .NET Link in the list of .NET components, do a file system search for the ESRI.ArcIMS.SERVER.dll file. Once you have found the location of the file, you can use the browse button in the Add Reference dialog to add the dll to your project.


Now, for the code.


First, these are the namespaces you'll have to import:



Imports ESRI.ArcIMS.Server
Imports System.Xml
Imports System.Text


The imports statements go (of course) at the top of the code behind file. I have written this sample in VB.NET but if there is enough of an outcry or some people are having trouble with a C# conversion, I will be happy to post it in C# also.


Second, declare your variables and initialize the connector. This is all performed (for the sake of ease) in the Page_Load event procedure. The host name and host service have been changed to protect the innocent.


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strrequest As New StringBuilder
Dim strresult As New StringBuilder
Dim cn As New ServerConnection
Dim xslt As New Xsl.XslTransform
Dim xml As New XmlDocument
Dim writer As New System.IO.StringWriter

cn.Host = "localhost"
cn.URIPort = 5300
cn.Scheme = Scheme.HTTP
cn.ServiceName = "localservice"


Next, we formulate an AXL Get_Features request and send it to the server. Again, for brevity, I just put in some extents and a layer id. If you know the exact center point of a building and you know the id of your buildings layer, you can use those.



strrequest.Append("<?xml version=""1.0"" encoding=""UTF-8""?>")
strrequest.Append("<ARCXML version=""1.1"">")
strrequest.Append("<REQUEST>")
strrequest.Append("<GET_FEATURES beginrecord=""0"" outputmode=""newxml"" geometry=""false"" envelope=""true"" compact=""true"">")
strrequest.Append("<LAYER id=""0"" />")
strrequest.Append("<SPATIALQUERY subfields=""#ALL#"" where="""">")
strrequest.Append("<SPATIALFILTER relation=""envelope_intersection"">")
strrequest.Append("<ENVELOPE minx=""0"" miny=""0"" maxx=""1"" maxy=""1""/>")
strrequest.Append("</SPATIALFILTER>")
strrequest.Append("</SPATIALQUERY>")
strrequest.Append("</GET_FEATURES>")
strrequest.Append("</REQUEST>")
strrequest.Append("</ARCXML>")

strresult.Append(cn.Send(strrequest.ToString))


Last, we grab the results and transform them using an XSL stylesheet and clean up our object references:



xml.LoadXml(strresult.ToString)
xslt.Load("http://localhost/netconnector/axl.xsl")
xslt.Transform(xml, Nothing, writer, Nothing)

Response.Write(writer.ToString)

strrequest = Nothing
strresult = Nothing
cn = Nothing
xslt = Nothing
xml = Nothing
writer = Nothing


The XSL stylesheet that I used is the following:


<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/ARCXML/RESPONSE/FEATURES">
<table>
<xsl:for-each select="FEATURE">
<tr>
<xsl:for-each select="FIELDS/FIELD">
<td>
<font size="2"><xsl:value-of select="@name"/></font>
</td>
</xsl:for-each>
</tr>
<tr>
<xsl:for-each select="FIELDS/FIELD">
<td>
<font size="2"><xsl:value-of select="@value"/></font>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>


If you have any questions or comments concerning the code, please feel free to comment on this post using the comments link at the bottom of this page. Also, if you would like to see any specific samples/news/information, please leave that information also.

Happy Programming!