现在的位置: 首页 > 综合 > 正文

代码中操作ArcGis server服务

2012年01月16日 ⁄ 综合 ⁄ 共 3749字 ⁄ 字号 评论关闭

 

ESRI.ArcGIS.Server.IGISServerConnection gisServerConnection = null;
            ESRI.ArcGIS.Server.IServerObjectAdmin4 pServerSOA = null;
            ESRI.ArcGIS.Server.IServerObjectConfiguration3 pConfig = null;

            try
            {
                gisServerConnection = new ESRI.ArcGIS.Server.GISServerConnection();
                gisServerConnection.Connect(strMapServer);//, identity);TESTSERV//kjtxmapservice//kjtxmapresource

                pServerSOA = (ESRI.ArcGIS.Server.IServerObjectAdmin4)gisServerConnection.ServerObjectAdmin;
                pConfig = (ESRI.ArcGIS.Server.IServerObjectConfiguration3)pServerSOA.GetConfiguration(strMapServerName, "MapServer");
                pServerSOA.StopConfiguration(strMapServerName, "MapServer");
                pServerSOA.StartConfiguration(strMapServerName, "MapServer");
                //pServerSOA.UpdateConfiguration(pConfig);
                return "成功";
            }
            catch (Exception exp)
            {
                return exp.Message;
            }
            finally
            {
                gisServerConnection = null;
                pServerSOA = null;
                pConfig = null;
            }

 

 

下面是遍历所有的服务

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.ADF.ArcGISServer;
using ESRI.ArcGIS.ADF.Connection;
using ESRI.ArcGIS.Server;
using ESRI.ArcGIS.esriSystem;

namespace BounceMapSvcs
{
    class Program
    {
        static void Main()
        {
            GISServerConnection connection = null;
            IServerObjectAdmin3 soa = null;
            string me = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
            Console.WriteLine("Connected as: " + me);
            try
            {
                connection = new GISServerConnection();
                connection.Connect("server-name");
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not connect to server. Make sure this user is a member of the AGSADMIN group.");
                Console.WriteLine(e.StackTrace);
                Console.WriteLine(e.ToString());
            }
            try
            {
                soa = (IServerObjectAdmin3)connection.ServerObjectAdmin;

                IServerObjectAdmin4 serverObjectAdmin = (IServerObjectAdmin4)connection.ServerObjectAdmin;
                IEnumServerObjectConfiguration enumConfig = serverObjectAdmin.GetConfigurations();
                IServerObjectConfigurationStatus configStatus = null;
                IServerObjectConfiguration config = enumConfig.Next();
                // Loop thru services
                while ( config != null)
                {
                    configStatus = serverObjectAdmin.GetConfigurationStatus(config.Name, config.TypeName);
                    // Bounce/start all services but those in the sandbox
                    if (config.Name.StartsWith("Sandbox") == false)
                    {
                        Console.WriteLine("Working on: " + config.Name + " -- Status: " + configStatus.Status);
                        if (configStatus.Status == esriConfigurationStatus.esriCSStarted)
                        {
                            // If running, then bounce
                            Console.WriteLine("Stopping: " + config.Name);
                            soa.StopConfiguration(config.Name, config.TypeName);
                            soa.StartConfiguration(config.Name, config.TypeName);
                        }
                        else if (configStatus.Status == esriConfigurationStatus.esriCSStopped)
                        {
                            // If not running, then start
                            Console.WriteLine("Starting: " + config.Name);
                            soa.StartConfiguration(config.Name, config.TypeName);
                        }
                    }
                    config = enumConfig.Next();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error connecting to service. The service or service type does not exist. Check your case and spelling.");
                Console.WriteLine(e.StackTrace);
            }
        }
    }
}

抱歉!评论已关闭.