ArcGIS Engine 10.2 如何发布服务

 

1         ArcGIS Engine 10.2 如何发布服务

ArcGIS Engine的代码不能直接将MXD地图文档作为数据源进行发布,如果要发布的话,需要用ArcMap将MXD转成MSD,然后使用转换成功的MSD文档进行发布,代码如下:

 

public void Publish(string host,string username,string passwordstring service, string msdDocument, string outputDir)

        {

            //IAGSServerConnectionFactory3 pConnectionFactory = new AGSServerConnectionFactoryClass();

 

            admin connection file works fine, tested in ArcCatalog on the same server

            //IAGSServerConnection4 server = pConnectionFactory.OpenFromFile(@"e:\admin-connection.ags", 0) as IAGSServerConnection4;

            //     IAGSServerConnectionAdmin pAGSServerConnectionAdmin = server as IAGSServerConnectionAdmin;

 

 

            IPropertySet propertySet = new PropertySetClass();

            propertySet.SetProperty("url", host);

            propertySet.SetProperty("ConnectionMode", esriAGSConnectionMode.esriAGSConnectionModeAdmin);

            propertySet.SetProperty("ServerType", esriAGSServerType.esriAGSServerTypeDiscovery);

            propertySet.SetProperty("user", username);

            propertySet.SetProperty("password", password);

            propertySet.SetProperty("ALLOWINSECURETOKENURL", true); //设置为false会弹出一个警告对话框

            IAGSServerConnectionName3 pConnectName = new AGSServerConnectionNameClass() as IAGSServerConnectionName3;//10.1新增接口

            pConnectName.ConnectionProperties = propertySet;

            IAGSServerConnectionAdmin pAGSAdmin = ((IName)pConnectName).Open() as IAGSServerConnectionAdmin;

            IAGSServerConnectionAdmin pAGSServerConnectionAdmin = pAGSAdmin as IAGSServerConnectionAdmin;

            IServerObjectAdmin pServerObjectAdmin = pAGSServerConnectionAdmin.ServerObjectAdmin;

            IServerObjectConfiguration5 pConfiguration = (IServerObjectConfiguration5)pServerObjectAdmin.CreateConfiguration();

 

            //Set the general configuration settings

            pConfiguration.Name = service;

            pConfiguration.TypeName = "MapServer";

            pConfiguration.TargetCluster = "default";

            pConfiguration.StartupType = esriStartupType.esriSTAutomatic;

            pConfiguration.IsolationLevel = esriServerIsolationLevel.esriServerIsolationHigh;

            pConfiguration.IsPooled = true;

            pConfiguration.Description = "Modsim Map Output";

           // pConfiguration.LoadBalancing = esriLoadBalancing.esriLoadBalancingNone;//没有集群的话可以不用设置

 

            pConfiguration.MinInstances = 1;

            pConfiguration.MaxInstances = 15;

            pConfiguration.WaitTimeout = 60;

            pConfiguration.UsageTimeout = 600;

            pConfiguration.IdleTimeout = 1800;

 

 

            //Set the configuration properties of the MapServer

            IPropertySet pProps = pConfiguration.Properties;

            pProps.SetProperty("FilePath", msdDocument);

            pProps.SetProperty("OutputDir", outputDir);

            pProps.SetProperty("MaxImageHeight", "2048");

            pProps.SetProperty("MaxRecordCount", "1000");

            pProps.SetProperty("MaxBufferCount", "100");

            pProps.SetProperty("MaxImageWidth", "2048");

            pConfiguration.Properties = pProps;

 

            //MIME+URL (virtual directory)

            IEnumServerDirectory dirs = pServerObjectAdmin.GetServerDirectories();

            dirs.Reset();

            IServerDirectory serverDir = dirs.Next();

            while (serverDir != null)

            {

                if (((IServerDirectory2)serverDir).Type == esriServerDirectoryType.esriSDTypeOutput)

                {

                    pProps.SetProperty("OutputDir", serverDir.Path);

                    pProps.SetProperty("VirtualOutputDir", serverDir.URL);

                    break;

 

                   // gp.AddMessage("[DEBUG] Outputpath: " + serverDir.Path + " || Virtual: " + serverDir.URL);

                }

                serverDir = dirs.Next();

            }

 

            //Set the info segment properties

            IPropertySet info = pConfiguration.Info;

            info.SetProperty("WebEnabled", "true");

            info.SetProperty("WebCapabilities", "Map,Query,Data");

            pConfiguration.Info = info;

 

            //Set the recycle properties of the MapServer object

            IPropertySet recycle = pConfiguration.RecycleProperties;

            recycle.SetProperty("StartTime", "1:00 AM");

            recycle.SetProperty("Interval", "86400");

            pConfiguration.RecycleProperties = recycle;

 

            //Add the configuration to the server

            pServerObjectAdmin.AddConfiguration(pConfiguration);

            pServerObjectAdmin.StartConfiguration(service, "MapServer");

        }

2         使用ArcGIS Engie中的GP发布地图文档

ArcGIS 10.1 在发布服务的时候其实是按照下面的步骤来的,如果认真观察过也不难得出:

将MXD文档转成sddraft文件;

sddraft文件转成sd文件

l  sd文件上传到ArcGIS for Server

既然这个过程已经知道了,那么就可以通过Python按照这个流程来自动化的完成服务的发布:

 

 

import arcpy

 

# define local variables

wrkspc = 'C:/Project/'

mapDoc = arcpy.mapping.MapDocument(wrkspc + 'counties.mxd')

con = r'GIS Servers\arcgis on MyServer_6080 (admin).ags'

service = 'Counties'

sddraft = wrkspc + service + '.sddraft'

sd = wrkspc + service + '.sd'

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值