ArcServer之管理服务器上下文

       操作服务器的上下文是学习ArcServer的起点,也是重点,下文将通过一个简单的例子来模拟这个过程。为了方便,我们使用ArcGis Server本地数据源,这样就可以通过服务器上下文直接与服务器对象交互了。

        首先看看如何获取服务器上下文对象

 

ContractedBlock.gif ExpandedBlockStart.gif Code
 1//获取服务器上下文对象
 2    private IServerContext getServerContext()
 3ExpandedBlockStart.gifContractedBlock.gif    {
 4        string servername = "localhost";
 5        string mapserverobject = "cz";
 6        IServerObjectManager serverManager;
 7        Session.Clear(); 
 8        if (Session["SOM"== null)
 9ExpandedSubBlockStart.gifContractedSubBlock.gif        {
10            Identity identify = new Identity("Administrator""123456"null);
11            AGSServerConnection gisconnection = new AGSServerConnection(servername, identify);
12            gisconnection.Connect();
13
14            serverManager = gisconnection.ServerObjectManager;
15            Session.Add("SOM", serverManager);
16
17        }

18        else
19ExpandedSubBlockStart.gifContractedSubBlock.gif        {
20            serverManager = Session["SOM"as IServerObjectManager;
21        }

22
23        IServerContext mapContext = serverManager.CreateServerContext(mapserverobject, "MapServer");
24        return mapContext;
25    }

       大致过程为:建立与服务器的连接,需要计算机名称或IP地址以及用于身份验证的Identify对象。构造好连接对象后,调用起Connect方法进行连接,若连接成功,就通过连接对象的ServerObjectManager属性找到GIS服务器上的SOM,利用它创建一个服务器上下文。

       下面利用得到服务器上下文输出一张图片来看看效果。其中imgOutput为手动在aspx添加的一个Image控件。

 

ContractedBlock.gif ExpandedBlockStart.gif Code
 1  protected void Page_PreRender(object sender, EventArgs e)
 2ExpandedBlockStart.gifContractedBlock.gif    {
 3        if (Page.IsPostBack)
 4            return;
 5        //得到服务器上下文对象
 6        IServerContext mapContext = getServerContext();
 7        IMapServer mapServer = mapContext.ServerObject as IMapServer;
 8
 9        IMapServerInfo mapInfo = mapServer.GetServerInfo(mapServer.DefaultMapName);
10        IMapDescription mapDesc = mapInfo.DefaultMapDescription;
11
12        CreateMapImage(mapContext, mapDesc);
13 
14        //池化服务器不需要我们来释放上下文对象,但是非池化就需要利用代码释放。
15        mapContext.ReleaseContext(); 
16    }

17
18    private void CreateMapImage(IServerContext mapContext, IMapDescription md)
19ExpandedBlockStart.gifContractedBlock.gif    {
20        IImageType imageType;
21        IImageDescription imageDesc;
22        IImageDisplay imageDisp;
23
24        imageType = mapContext.CreateObject("esriCarto.ImageType"as IImageType;
25        imageDesc = mapContext.CreateObject("esriCarto.ImageDescription"as ImageDescription;
26        imageDisp = mapContext.CreateObject("esriCarto.ImageDisplay"as ImageDisplay;
27
28        imageType.Format = esriImageFormat.esriImagePNG;
29        imageType.ReturnType = esriImageReturnType.esriImageReturnURL;
30
31        imageDisp.Width = (int)imgOutput.Width.Value;
32        imageDisp.Height = (int)imgOutput.Height.Value;
33        imageDisp.DeviceResolution = 96;
34
35        imageDesc.Display = imageDisp;
36        imageDesc.Type = imageType;
37
38        IMapServer mapServer = mapContext.ServerObject as IMapServer;
39
40        IImageResult mapImage = mapServer.ExportMapImage(md, imageDesc);
41        imgOutput.ImageUrl = mapImage.URL;
42        imgOutput.Visible = true;
43    }

 

 

 

 

 

转载于:https://www.cnblogs.com/gis_sky/archive/2009/11/24/Context.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值