Engine如何使用远程ArcGIS Server发布地图服务?

同样代码和数据使用本机的ArcGIS Server可以发布成功,但是使用远程的ArcGIS Server发布则在AddConfiguration报错。
已邀请:

朱新颖

赞同来自:

【解决办法】:
数据所在的文件夹需要注册到ArcGIS Server,也就是服务器上的ArcGIS Server能够访问到该数据。
注册文件夹方法:在ArcCatalog中的该远程Server的连接上右击选中Server Properties,弹出界面选择Data Store页面,可以将该数据和msd所在的文件夹进行注册,如下图: 
[attach]https://c.ap4.content.force.co ... 9TwCL[/attach]
如果Server注册了该文件夹,需要将本机D:\Esi\data中的内容考到服务器的D盘下(根据图中注册时的路径),然后代码中该msd的路径直接写成:D:\publishmsd.msd(即服务器上该msd的路径)
可以参考下面代码:

Publish(https://192.168.100.139:6443/arcgis/admin, arcgis, arcgis, PublishMsd, @D:\publishmsd.msd, @C:\arcgisserver\directories\arcgisoutput);
public void Publish(string host, string username, string password, string service, string msdDocument, string outputDir)
        {            
            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);
        }

岳官印

赞同来自:

文中多出SetProperty第二个参数,缺少双引号,所以请大家使用时,注意修改

要回复问题请先登录注册