ArcGIS Server代码动态创建发布服务(MapServer,ImageServer)

来源:互联网 发布:男士网红淘宝店铺 编辑:程序博客网 时间:2024/05/17 23:29
  1. #region 创建地图服务  
  2.   private bool CreateServices(string MapPath, string ServerName)//ServerName为地图服务设置的服务名  
  3.   {  
  4.       ESRI.ArcGIS.ADF.Identity identity = new ESRI.ArcGIS.ADF.Identity(MapServerUserName, MapserverPass, "");//MapServerUserName和MapserverPass为连接ArcGIS Server的用户名和密码  
  5.       ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection agsConnection = new ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection(HostName, identity);//HostName为ArcGIS Server所在服务器的主机名  
  6.       agsConnection.Connect();  
  7.       IServerObjectAdmin pServerObjectAdmin;  
  8.       pServerObjectAdmin = agsConnection.ServerObjectAdmin;  
  9.       IServerObjectConfiguration2 configuration = (IServerObjectConfiguration2)pServerObjectAdmin.CreateConfiguration();  
  10.       configuration.Name = ServerName;//发布Service的名称,必填  
  11.       configuration.TypeName = "MapServer";//发布服务的类型,如:MapServer,GeocodeServer  
  12.       IPropertySet props = configuration.Properties;  
  13.       props.SetProperty("FilePath", MapPath);//设置MXD的路径  
  14.       props.SetProperty("OutputDir""c:\\arcgisserver\\arcgisoutput");//图片的输出目录  
  15.       props.SetProperty("VirtualOutPutDir""http://" + HostName + "/arcgisoutput");//图片输出的虚拟路径  
  16.       props.SetProperty("SupportedImageReturnTypes""URL");//支持的图片类型  
  17.       props.SetProperty("MaxImageHeight""2048");//图片的最大高度  
  18.       props.SetProperty("MaxRecordCount""500");//返回记录的最大条数  
  19.       props.SetProperty("MaxBufferCount""100");//缓冲区分析的最大数目  
  20.       props.SetProperty("MaxImageWidth""2048");//图片的最大宽度  
  21.       props.SetProperty("IsCached""false");//是否切片  
  22.       props.SetProperty("CacheOnDemand""false");//是否主动切片  
  23.       props.SetProperty("IgnoreCache""false");//是否忽略切片  
  24.       props.SetProperty("ClientCachingAllowed""true");//是否允许客户端缓冲  
  25.       props.SetProperty("CacheDir""c:\\arcgisserver\\arcgiscache\\NewService");//切片的输出路径  
  26.       props.SetProperty("SOMCacheDir""c:\\arcgisserver\\arcgiscache");//som的切片输出路径  
  27.   
  28.       //configuration.Description = "NewService";//Service的描述  
  29.       configuration.IsolationLevel = esriServerIsolationLevel.esriServerIsolationHigh;//或者esriServerIsolationLow,esriServerIsolationAny  
  30.       configuration.IsPooled = true;//是否池化  
  31.       configuration.MaxInstances = 2;//最多的实例数  
  32.       configuration.MinInstances = 1;//最少的实例数  
  33.   
  34.       ////设置刷新  
  35.       IPropertySet recycleProp = configuration.RecycleProperties;  
  36.       recycleProp.SetProperty("StartTime""00:00");//刷新开始时间  
  37.       recycleProp.SetProperty("Interval""3600");//刷新间隔  
  38.   
  39.       ////设置是否开启REST服务  
  40.       IPropertySet infoProp = configuration.Info;  
  41.       infoProp.SetProperty("WebEnabled""true");//是否提供REST服务  
  42.       infoProp.SetProperty("WebCapabilities""Map,Query,Data");//提供何种服务  
  43.   
  44.       //configuration.StartupType = esriStartupType.esriSTAutomatic;//或者esriSTManual  
  45.       //configuration.UsageTimeout = 120;//客户端占用一个服务的最长时间  
  46.       //configuration.WaitTimeout = 120;//客户端申请一个服务的最长等待时间 
  47.       #endregion  
  48.   
  49.       //添加服务到Server  
  50.       pServerObjectAdmin.AddConfiguration(configuration);  
  51.   
  52.       //启动服务   
  53.       pServerObjectAdmin.StartConfiguration(ServerName, "MapServer");//设置服务类型为MapServer,并启动服务  
  54.       return true;  
  55.   
  56.   }  
  57.   #endregion
  1. private bool CreateServices(string ImagePath, string ServerName)  
  2.     {  
  3.          ESRI.ArcGIS.ADF.Identity identity = new ESRI.ArcGIS.ADF.Identity(MapServerUserName, MapserverPass, "");  
  4.         ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection agsConnection = new   
  5.   
  6.   
  7. ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection(HostName, identity);  
  8.         agsConnection.Connect();  
  9.         IServerObjectAdmin pServerObjectAdmin;  
  10.         pServerObjectAdmin = agsConnection.ServerObjectAdmin;  
  11.         IServerObjectConfiguration2 configuration = (IServerObjectConfiguration2)pServerObjectAdmin.CreateConfiguration();  
  12.         configuration.Name = ServerName;//发布Service的名称,必填  
  13.         configuration.TypeName = "ImageServer";//发布服务的类型,如:MapServer,GeocodeServer  
  14.         IPropertySet propertySet = configuration.Properties;  
  15. <span style="color:#ff0000;">        propertySet.SetProperty("Path", ImagePath);//设置Image的路径</span>  
  16.         propertySet.SetProperty("Start""00:00");  
  17.         propertySet.SetProperty("Interval""24");  
  18.         propertySet.SetProperty("SupportedImageReturnTypes""URL");  
  19. <span style="color:#ff9900;"> propertySet.SetProperty("OutputDir""c:\\arcgisserver\\arcgisoutput");//图片的输出目录  
  20.     propertySet.SetProperty("VirtualOutPutDir""http://" + HostName + "/arcgisoutput");//图片输出的虚拟路径</span>  
  21.         //propertySet.SetProperty("MaxImageHeight", 4100);//4100  
  22.        // propertySet.SetProperty("MaxImageWidth", 15000);//15000  
  23.         //propertySet.SetProperty("AllowedCompressions", "None,JPEG,LZ77");//"None,JPEG,LZ77"  
  24.         //propertySet.SetProperty("DefaultResamplingMethod", 0);//0  
  25.         //propertySet.SetProperty("DefaultCompressionQuality", 75);//75  
  26.         //propertySet.SetProperty("MaxRecordCount", 500);//500  
  27.         //propertySet.SetProperty("MaxMosaicImageCount", 1);//20  
  28.         //propertySet.SetProperty("MaxDownloadImageCount", 20);//20  
  29.         //propertySet.SetProperty("AllowedFields","Name,MinPS,MaxPS,LowPS,HighPS,CenterX,CenterY");//"Name,MinPS,MaxPS,LowPS,HighPS,CenterX,CenterY"  
  30.         //propertySet.SetProperty("AllowedMosaicMethods","Center,NorthWest,LockRaster,ByAttribute,Nadir,Viewpoint,Seamline");//"Center,NorthWest,LockRaster,ByAttribute,Nadir,Viewpoint,Seamline"  
  31.         //propertySet.SetProperty("AllowedItemMetadata", "Full");//"Full"  
  32.         //ImageServiceInfo pImageSerivce = new ImageServiceInfo();  
  33.         configuration.StartupType = esriStartupType.esriSTAutomatic;  
  34.         configuration.MinInstances = 1;  
  35.         configuration.MaxInstances = 2;  
  36.     configuration.IsPooled = true;  
  37.         configuration.Info.SetProperty("WebEnabled""true");  
  38.         configuration.Info.SetProperty("WebCapabilities""Image,Catalog,Metadata,Download,Pixels");  
  39.         pServerObjectAdmin.AddConfiguration(configuration);  
  40.         //启动服务  
  41.         pServerObjectAdmin.StartConfiguration(ServerName, "ImageServer");//设置服务类型并启动服务  
  42.         return true;  
  43.     }