zoukankan      html  css  js  c++  java
  • C#中winform下利用ArcEngine调用ArcGIS Server发布的服务 AE 10

    开发环境:vs2010 + AE 10 测试

    public Form1()
            {
                ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);
                ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.Engine);
    
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                //获得服务对象名称[注意地址和名称;test:发布服务的自定义名称]
                IAGSServerObjectName pServerObjectName = GetMapServer("http://172.18.70.254:8081/ArcGIS/services", "test", false);
                IName pName = (IName)pServerObjectName;
                //访问地图服务
                IAGSServerObject pServerObject = (IAGSServerObject)pName.Open();
                IMapServer pMapServer = (IMapServer)pServerObject;
    
                IMapServerLayer pMapServerLayer = new MapServerLayer() as IMapServerLayer;
                //连接地图服务
    
                pMapServerLayer.ServerConnect(pServerObjectName, pMapServer.DefaultMapName);
                //添加数据图层
    
                axMapControl1.AddLayer(pMapServerLayer as ILayer);
    
                axMapControl1.Refresh();
            }
    
            public IAGSServerObjectName GetMapServer(string pHostOrUrl, string pServiceName, bool pIsLAN)
            {
                //设置连接属性
                IPropertySet pPropertySet = new PropertySet();
                if (pIsLAN)
                    pPropertySet.SetProperty("machine", pHostOrUrl);
                else
                    pPropertySet.SetProperty("url", pHostOrUrl);
    
                //打开连接
    
                IAGSServerConnectionFactory pFactory = new AGSServerConnectionFactory();
                //Type factoryType = Type.GetTypeFromProgID(
                //    "esriGISClient.AGSServerConnectionFactory");
                //IAGSServerConnectionFactory agsFactory = (IAGSServerConnectionFactory)
                //    Activator.CreateInstance(factoryType);
                IAGSServerConnection pConnection = pFactory.Open(pPropertySet, 0);
    
                //Get the image server.
                IAGSEnumServerObjectName pServerObjectNames = pConnection.ServerObjectNames;
                pServerObjectNames.Reset();
                IAGSServerObjectName ServerObjectName = pServerObjectNames.Next();
                while (ServerObjectName != null)
                {
                    if ((ServerObjectName.Name.ToLower() == pServiceName.ToLower()) &&
                        (ServerObjectName.Type == "MapServer"))
                    {
    
                        break;
                    }
                    ServerObjectName = pServerObjectNames.Next();
                }
    
                //返回对象
                return ServerObjectName;
            }
  • 相关阅读:
    数据库范式
    服务器防火墙
    Java垃圾回收(GC)机制详解
    Java内存模型
    类加载器
    Java类加载机制
    java虚拟机:Java内存区域及对象
    初识HashMap
    初识LinkedList
    java ArrayList
  • 原文地址:https://www.cnblogs.com/tianciliangen/p/5435665.html
Copyright © 2011-2022 走看看