本地连接可以使用Dcom代理,而本质上DCOM代理是利用AO对象和ArcGIS Server 服务器对象打交道。所以本地连接,客户端就要有AO对象,当然也可以直接利用AO API(可以认为是远端服务器对象的AO代理),而不使用Dcom代理,(但是使用Dcom代理,因为代理和值对象是在客户端,所以要比AO快(AO proxies的所有操作都是在远程调用的基础上完成的,但是利用AO我们可以访问到远端的细粒度的AO对象)),而代理属于Soap的范畴,而获取Dcom代理,目前我发现两种方法,如下:
ESRI.ArcGIS.ADF.Identity id = new ESRI.ArcGIS.ADF.Identity(username, password, domain);
ESRI.ArcGIS.ADF.ArcGISServer.MapServerDcomProxy mapserver_dcom =
(MapServerDcomProxy) MapServerDcomProxy.Create(SOMname, servicename, id);
// do something with the DCOM proxy
mapserver_dcom.Dispose();
ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection connection = null; ESRI.ArcGIS.Server.IServerContext serverContext = null; try { connection = new ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection(); connection.Host = "localhost"; connection.Connect(); ESRI.ArcGIS.Server.IServerObjectManager serverObjectManager = connection.ServerObjectManager; serverContext = serverObjectManager.CreateServerContext("MyMapService", "MapServer"); ESRI.ArcGIS.ADF.ArcGISServer.MapServerDcomProxy mapservice = new ESRI.ArcGIS.ADF.ArcGISServer.MapServerDcomProxy(serverContext, true); ESRI.ArcGIS.ADF.ArcGISServer.MapServerInfo mapinfo = mapservice.GetServerInfo(mapservice.GetDefaultMapName()); ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapdesc = mapinfo.DefaultMapDescription; ESRI.ArcGIS.ADF.ArcGISServer.ImageType imgtype = new ESRI.ArcGIS.ADF.ArcGISServer.ImageType(); imgtype.ImageFormat = ESRI.ArcGIS.ADF.ArcGISServer.esriImageFormat.esriImagePNG; imgtype.ImageReturnType = ESRI.ArcGIS.ADF.ArcGISServer.esriImageReturnType.esriImageReturnURL; ESRI.ArcGIS.ADF.ArcGISServer.ImageDisplay imgdisp = new ESRI.ArcGIS.ADF.ArcGISServer.ImageDisplay(); imgdisp.ImageHeight = 500; imgdisp.ImageWidth = 500; imgdisp.ImageDPI = 96; ESRI.ArcGIS.ADF.ArcGISServer.ImageDescription imgdesc = new ESRI.ArcGIS.ADF.ArcGISServer.ImageDescription(); imgdesc.ImageDisplay = imgdisp; imgdesc.ImageType = imgtype; ESRI.ArcGIS.ADF.ArcGISServer.MapImage mapimg = mapservice.ExportMapImage(mapdesc, imgdesc); System.Net.HttpWebRequest webreq = System.Net.WebRequest.Create(mapimg.ImageURL) as HttpWebRequest; System.Net.HttpWebResponse webresp = webreq.GetResponse() as HttpWebResponse; System.Drawing.Image img = System.Drawing.Image.FromStream(webresp.GetResponseStream()); } catch (Exception ex){} finally { serverContext.ReleaseContext(); connection.Dispose(); }
|