我个人看了这两处的代码并对比后,有些被ArcInfo这些产品提供的东西弄糊涂了,为什么ArcIMS生成ArcXML有两种解决方法呢,都有什么作用呢,那一种更好用更适合呢?
下面将这两处的代码对比如下(其中Flyingis所说的方法在我这里并没有运行成功,不知道还需要注意什么地方的设置或编码):
1、在.Net工程中引用StudioAT.MapNet.DLL文件,下面的代码为页面上的MapNet控件的点击事件(MapNet控件为可视化控件,也是通过添加StudioAT.MapNet.DLL文件获得的,至于如何添加.Net以外的控件,我这里就不多说了。)
1using System;
2using System.Collections;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Web;
7using System.Web.SessionState;
8using System.Web.UI;
9using System.Web.UI.WebControls;
10using System.Web.UI.HtmlControls;
11using System.Xml;
12using StudioAT.IMS;
13using StudioAT;
14
15……
16
17/// <summary>
18/// 单击地图时显示相关的属性信息和坐标信息
19/// </summary>
20/// <param name="rct">点的大小范围信息</param>
21private void MapNet1_Click(StudioAT.IRect rct)
22 {
23 IMapNet myMapNet = this.MapNet1;
24 XmlElement myXmlEle = null;
25 XmlDocument myXmlDoc = (XmlDocument)ArcXML.BuildRequest(ArcXML.enuRequest.GET_FEATURES, ref myXmlEle);
26 myXmlEle.SetAttribute(ArcXML.AttributeOutputmode,"newxml");
27 myXmlEle.SetAttribute(ArcXML.AttributeGeometry, "true");
28 myXmlEle.SetAttribute(ArcXML.AttributeEnvelope, "true");
29 myXmlEle.SetAttribute(ArcXML.AttributeCompact, "true");
30 XmlElement xmlELayer = myXmlDoc.CreateElement(ArcXML.NodeLayer);
31 xmlELayer.SetAttribute(ArcXML.AttributeId, this.DDL_Layer.SelectedValue);
32 myXmlEle.AppendChild(xmlELayer);
33 XmlElement xmlESQ = myXmlDoc.CreateElement(ArcXML.NodeSpatialquery);
34 xmlELayer.SetAttribute(ArcXML.AttributeId, this.DDL_Layer.SelectedValue);
35 myXmlEle.AppendChild(xmlESQ);
36 XmlElement xmlESF = myXmlDoc.CreateElement(ArcXML.NodeSpatialfilter);
37 xmlESF.SetAttribute(ArcXML.AttributeRelation, "area_intersection");
38 xmlESQ.AppendChild(xmlESF);
39 XmlElement xmlEEnv = (XmlElement)ArcXML.CreateExtent(ref myXmlDoc,rct);
40 xmlESF.AppendChild(xmlEEnv);
41 string strResponse = myMapNet.RequestArcXML(myXmlDoc.InnerXml, ArcXML.enuCustomService.Query);
42 myXmlDoc = new XmlDocument();
43 myXmlDoc.LoadXml(strResponse);
44 if(myXmlDoc.GetElementsByTagName("FIELD").Count > 2)
45 {
46 this.TB_BZ.Text = myXmlDoc.InnerXml;
47 }
48 }
49
50……
上面的代码是当在地图中点击一点,显示地图中该点的属性。2using System.Collections;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Web;
7using System.Web.SessionState;
8using System.Web.UI;
9using System.Web.UI.WebControls;
10using System.Web.UI.HtmlControls;
11using System.Xml;
12using StudioAT.IMS;
13using StudioAT;
14
15……
16
17/// <summary>
18/// 单击地图时显示相关的属性信息和坐标信息
19/// </summary>
20/// <param name="rct">点的大小范围信息</param>
21private void MapNet1_Click(StudioAT.IRect rct)
22 {
23 IMapNet myMapNet = this.MapNet1;
24 XmlElement myXmlEle = null;
25 XmlDocument myXmlDoc = (XmlDocument)ArcXML.BuildRequest(ArcXML.enuRequest.GET_FEATURES, ref myXmlEle);
26 myXmlEle.SetAttribute(ArcXML.AttributeOutputmode,"newxml");
27 myXmlEle.SetAttribute(ArcXML.AttributeGeometry, "true");
28 myXmlEle.SetAttribute(ArcXML.AttributeEnvelope, "true");
29 myXmlEle.SetAttribute(ArcXML.AttributeCompact, "true");
30 XmlElement xmlELayer = myXmlDoc.CreateElement(ArcXML.NodeLayer);
31 xmlELayer.SetAttribute(ArcXML.AttributeId, this.DDL_Layer.SelectedValue);
32 myXmlEle.AppendChild(xmlELayer);
33 XmlElement xmlESQ = myXmlDoc.CreateElement(ArcXML.NodeSpatialquery);
34 xmlELayer.SetAttribute(ArcXML.AttributeId, this.DDL_Layer.SelectedValue);
35 myXmlEle.AppendChild(xmlESQ);
36 XmlElement xmlESF = myXmlDoc.CreateElement(ArcXML.NodeSpatialfilter);
37 xmlESF.SetAttribute(ArcXML.AttributeRelation, "area_intersection");
38 xmlESQ.AppendChild(xmlESF);
39 XmlElement xmlEEnv = (XmlElement)ArcXML.CreateExtent(ref myXmlDoc,rct);
40 xmlESF.AppendChild(xmlEEnv);
41 string strResponse = myMapNet.RequestArcXML(myXmlDoc.InnerXml, ArcXML.enuCustomService.Query);
42 myXmlDoc = new XmlDocument();
43 myXmlDoc.LoadXml(strResponse);
44 if(myXmlDoc.GetElementsByTagName("FIELD").Count > 2)
45 {
46 this.TB_BZ.Text = myXmlDoc.InnerXml;
47 }
48 }
49
50……
2、在.Net工程中引用ESRI.ArcIMS.Server.DLL文件,在一个页面Button控件的单击事件被触发后,将获得的ArcXML给一个TextBox控件的Text属性。采用了Flyingis所说的方法,但未成功。将Flyingis所写的代码同时粘贴出来做个对比。
首先,需要将.NET Link的程序集引用到开发环境中,我使用的是Visual Studio 2005,需要说明的是ArcIMS 9/9.1 的.NET Link在VS2003和VS2005中都能工作的很好,兼容性不错。这样ESRI.ArcIMS.Server.dll就加入了项目中。
第二步,建立到ArcIMS应用服务器的连接。
using ESRI.ArcIMS.Server
……
ServerConnection connection = new ServerConnection();
connection.Host = "localhost";
connection.AppServerPort = 5300;
connection.Scheme = Scheme.TCP;
……
ServerConnection connection = new ServerConnection();
connection.Host = "localhost";
connection.AppServerPort = 5300;
connection.Scheme = Scheme.TCP;
如果需要建立一个HTTP连接,端口为80,可以将以上语句改为
connection.Scheme = Scheme.HTTP;
connection.Host = "http://www.yourdomain.com";
connection.URIPort = 80;
connection.Host = "http://www.yourdomain.com";
connection.URIPort = 80;
第三步,发送一个ArcXML请求。在.NET Link中发送ArcXML请求,其实质就是对ArcXML文件的一种拼装。
// 获取默认的地图服务
connection.ServiceName = "ServerSample";
// 建立一个 XML String,即 axl
string sAXLText;
// 在 sAXLText 中写入定制的 axl 文件
sAXLText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ARCXML version=\"1.1\">";
sAXLText = sAXLText + "<REQUEST><GET_IMAGE><PROPERTIES>";
sAXLText = sAXLText + "<IMAGESIZE width=\"300\" height=\"250\"/>";
sAXLText = sAXLText + "<ENVELOPE minx=\"-132.0\" miny=\"25.0\" maxx=\"-57.0\" maxy=\"50.0\" />";
sAXLText = sAXLText + "<LEGEND display=\"false\" />";
sAXLText = sAXLText + "</PROPERTIES></GET_IMAGE></REQUEST></ARCXML>";
string response = conArcIMS.Send(sAXLText);
connection.ServiceName = "ServerSample";
// 建立一个 XML String,即 axl
string sAXLText;
// 在 sAXLText 中写入定制的 axl 文件
sAXLText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ARCXML version=\"1.1\">";
sAXLText = sAXLText + "<REQUEST><GET_IMAGE><PROPERTIES>";
sAXLText = sAXLText + "<IMAGESIZE width=\"300\" height=\"250\"/>";
sAXLText = sAXLText + "<ENVELOPE minx=\"-132.0\" miny=\"25.0\" maxx=\"-57.0\" maxy=\"50.0\" />";
sAXLText = sAXLText + "<LEGEND display=\"false\" />";
sAXLText = sAXLText + "</PROPERTIES></GET_IMAGE></REQUEST></ARCXML>";
string response = conArcIMS.Send(sAXLText);
最后,需要处理ArcXML响应。
System.Xml.XmlDocument axlResponse = new System.Xml.XmlDocument();
axlResponse.LoadXml(response);
if (axlResponse.GetElementsByTagName("OUTPUT").Count == 1)
{
// 从 ArcIMS 应用服务器响应中获取 "OUTPUT" XmlNode 节点的集合,并且节点只有一个
System.Xml.XmlNodeList nodeOutput = axlResponse.GetElementsByTagName("OUTPUT");
// 获取这个节点的 url 属性值
imageURL = nodeOutput[0].Attributes["url"].Value;
}
axlResponse.LoadXml(response);
if (axlResponse.GetElementsByTagName("OUTPUT").Count == 1)
{
// 从 ArcIMS 应用服务器响应中获取 "OUTPUT" XmlNode 节点的集合,并且节点只有一个
System.Xml.XmlNodeList nodeOutput = axlResponse.GetElementsByTagName("OUTPUT");
// 获取这个节点的 url 属性值
imageURL = nodeOutput[0].Attributes["url"].Value;
}
最后获得的imageURL就是之前客户端用户发送请求需要服务器返回的图片地址,用户每次对地图操作后看到的结果,其本质就是一张张图片。
上面是Flyingis在《ArcIMS 连接器--.NET Link 使用方法》所提到的代码。下面是我的代码:
1using System;
2using System.Collections;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Web;
7using System.Web.SessionState;
8using System.Web.UI;
9using System.Web.UI.WebControls;
10using System.Web.UI.HtmlControls;
11using System.Xml;
12using ESRI.ArcIMS.Server;
13
14……
15
16private void Btn_SS_Click(object sender, System.EventArgs e)
17 {
18 ServerConnection mySerCon = new ServerConnection();
19 mySerCon.Scheme = Scheme.HTTP;
20 mySerCon.Host = "http://localhost";
21 mySerCon.URIPort = 80;
22 mySerCon.ServiceName = "DemoMap";
23 string SendArcXMLText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ARCXML version=\"1.1\"><REQUEST><GET_FEATURES outputmode=\"newxml\" geometry=\"true\" envelope=\"true\" compact=\"true\"><LAYER id=\"18\" /><SPATIALQUERY><SPATIALFILTER relation=\"area_intersection\"><ENVELOPE minx=\"87.6087292191028\" miny=\"43.7877048007505\" maxx=\"87.6092644218237\" maxy=\"43.7882400034714\" /></SPATIALFILTER></SPATIALQUERY></GET_FEATURES></REQUEST></ARCXML>";
24 string InceptArcXMLText = mySerCon.Send(SendArcXMLText);
25 this.TB_BZ.Text = InceptArcXMLText;
26 XmlDocument InceptXmlDoc= new XmlDocument();
27 InceptXmlDoc.LoadXml(InceptArcXMLText);
28 if (InceptXmlDoc.GetElementsByTagName("OUTPUT").Count == 1)
29 {
30 XmlNodeList NodeOutPut = InceptXmlDoc.GetElementsByTagName("OUTPUT");
31 this.MapNet1.ImageUrl = NodeOutPut[0].Attributes["url"].Value;
32 }
33 }
34
35……
上面是我使用情况的代码但是在运行触发事件后,第24行报错,错误提示为:“无效的 URI: 无法分析主机名。”。错误图片如下:2using System.Collections;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Web;
7using System.Web.SessionState;
8using System.Web.UI;
9using System.Web.UI.WebControls;
10using System.Web.UI.HtmlControls;
11using System.Xml;
12using ESRI.ArcIMS.Server;
13
14……
15
16private void Btn_SS_Click(object sender, System.EventArgs e)
17 {
18 ServerConnection mySerCon = new ServerConnection();
19 mySerCon.Scheme = Scheme.HTTP;
20 mySerCon.Host = "http://localhost";
21 mySerCon.URIPort = 80;
22 mySerCon.ServiceName = "DemoMap";
23 string SendArcXMLText = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ARCXML version=\"1.1\"><REQUEST><GET_FEATURES outputmode=\"newxml\" geometry=\"true\" envelope=\"true\" compact=\"true\"><LAYER id=\"18\" /><SPATIALQUERY><SPATIALFILTER relation=\"area_intersection\"><ENVELOPE minx=\"87.6087292191028\" miny=\"43.7877048007505\" maxx=\"87.6092644218237\" maxy=\"43.7882400034714\" /></SPATIALFILTER></SPATIALQUERY></GET_FEATURES></REQUEST></ARCXML>";
24 string InceptArcXMLText = mySerCon.Send(SendArcXMLText);
25 this.TB_BZ.Text = InceptArcXMLText;
26 XmlDocument InceptXmlDoc= new XmlDocument();
27 InceptXmlDoc.LoadXml(InceptArcXMLText);
28 if (InceptXmlDoc.GetElementsByTagName("OUTPUT").Count == 1)
29 {
30 XmlNodeList NodeOutPut = InceptXmlDoc.GetElementsByTagName("OUTPUT");
31 this.MapNet1.ImageUrl = NodeOutPut[0].Attributes["url"].Value;
32 }
33 }
34
35……
应该是在“mySerCon.Host = "http://localhost";”里有什么错误了,但不太清楚如何改为正确的URL。不知道是否有人清楚呢?盼望回答