代码
//
创建WFS
protected void btnCreatWFS_Click( object sender, EventArgs e)
{
string serviceName = " WFSService " ;
// string serviceType = "MAPSERVER";
string strDocPath = string .Empty;
string filepath = @ " F:\地图\LSGXPT.mxd " ;
string hostname = " localhost " ;
#region // 连接到主机服务器
// 连接到主机服务器
IGISServerConnection pGISServerConnection = new ESRI.ArcGIS.Server.GISServerConnectionClass();
pGISServerConnection.Connect(hostname);
// 创建空的服务器上下文
IServerObjectManager som = pGISServerConnection.ServerObjectManager;
IServerContext serverContext = som.CreateServerContext( "" , "" );
// 得到服务对象管理员
IServerObjectAdmin pServerObjectAdmin = pGISServerConnection.ServerObjectAdmin;
IServerObjectConfiguration2 configuration = (IServerObjectConfiguration2)pServerObjectAdmin.CreateConfiguration();
// 获得server服务器列表,判断发布的服务是否存在
IEnumServerObjectConfiguration pEnumServerObjectConfiguration = pServerObjectAdmin.GetConfigurations();
IServerObjectConfiguration2 pp;
for ( int i = 0 ; i < pEnumServerObjectConfiguration.Count; i ++ )
{
pp = (IServerObjectConfiguration2)pEnumServerObjectConfiguration.Next();
String name = pp.Name;
if (name == serviceName)
{
return ;
}
}
#endregion
configuration.Name = serviceName; // 发布Service的名称,必填
configuration.TypeName = " MapServer " ; // 发布服务的类型
#region // 设置服务一般属性
IPropertySet props = configuration.Properties;
props.SetProperty( " FilePath " , filepath); // 设置MXD的路径
// 一下的property并非必须,只要一个filepath就可以发布
props.SetProperty( " OutputDir " , " D:\\ArcGIS9.3\\ArcGIS Server\\arcgisoutput " );
props.SetProperty( " VirtualOutputDir " , " http://localhost/arcgisoutput " );
props.SetProperty( " SupportedImageReturnTypes " , " URL " ); // 支持的图片类型
props.SetProperty( " MaxImageHeight " , " 2048 " ); // 图片的最大高度
props.SetProperty( " MaxRecordCount " , " 500 " ); // 返回记录的最大条数
props.SetProperty( " MaxBufferCount " , " 100 " ); // 缓冲区分析的最大数目
props.SetProperty( " MaxImageWidth " , " 2048 " ); // 图片的最大宽度
props.SetProperty( " IsCached " , " false " ); // 是否切片
props.SetProperty( " CacheOnDemand " , " false " ); // 是否主动切片
props.SetProperty( " IgnoreCache " , " false " ); // 是否忽略切片
props.SetProperty( " ClientCachingAllowed " , " true " ); // 是否允许客户端缓冲
props.SetProperty( " CacheDir " , " D:\\ArcGIS9.3\\ArcGIS Server\\arcgiscache " ); // 切片的输出路径
props.SetProperty( " SOMCacheDir " , " D:\\ArcGIS9.3\\ArcGIS Server\\arcgiscache " ); // som的切片输出路径
#endregion
#region // 设置WFS属性
configuration.set_ExtensionEnabled( " WFSServer " , true );
IPropertySet wfsprops = configuration.get_ExtensionProperties( " WFSServer " );
wfsprops.SetProperty( " CustomGetCapabilities " , " false " );
wfsprops.SetProperty( " EnableTransactions " , " false " );
wfsprops.SetProperty( " Name " , serviceName);
wfsprops.SetProperty( " OnlineResource " , " http://localhost/arcgis/services/MyService/MapServer/WMSServer " );
string AppSchemaURI = " http:// " + hostname + " /arcgis/services/ " + serviceName + " /MapServer/WFSServer " ;
wfsprops.SetProperty( " AppSchemaURI " , " http://localhost/arcgis/services/MyService/MapServer/WMSServer " );
wfsprops.SetProperty( " AppSchemaPrefix " , serviceName);
configuration.set_ExtensionProperties( " WFSServer " , wfsprops);
IPropertySet wfsinfo = configuration.get_ExtensionInfo( " WFSServer " );
wfsinfo.SetProperty( " WebEnabled " , " true " );
configuration.set_ExtensionInfo( " WFSServer " , wfsinfo);
#endregion
#region
configuration.Description = serviceName; // Service的描述
configuration.IsolationLevel = esriServerIsolationLevel.esriServerIsolationHigh; // 或者esriServerIsolationLow,esriServerIsolationAny
configuration.IsPooled = true ; // 是否池化
configuration.MaxInstances = 1 ; // 最多的实例数
configuration.MinInstances = 1 ; // 最少的实例数
// 设置刷新
IPropertySet recycleProp = configuration.RecycleProperties;
recycleProp.SetProperty( " StartTime " , " 00:00 " ); // 刷新开始时间
recycleProp.SetProperty( " Interval " , " 3600 " ); // 刷新间隔
// 设置是否开启REST服务
IPropertySet infoProp = configuration.Info;
infoProp.SetProperty( " WebEnabled " , " true " ); // 是否提供REST服务
infoProp.SetProperty( " WebCapabilities " , " Map,Query,Data " ); // 提供何种服务
configuration.StartupType = esriStartupType.esriSTAutomatic; // 或者esriSTManual
configuration.UsageTimeout = 120 ; // 客户端占用一个服务的最长时间
configuration.WaitTimeout = 120 ; // 客户端申请一个服务的最长等待时间
configuration.set_ExtensionEnabled( " WFSServer " , true );
#endregion
// 添加服务到Server
pServerObjectAdmin.AddConfiguration(configuration);
// 删除服务
// pServerObjectAdmin.DeleteConfiguration("NewService", "MapServer");
// 启动服务
pServerObjectAdmin.StartConfiguration(serviceName, " MapServer " );
// 释放服务器上下文
serverContext.ReleaseContext();
}
protected void btnCreatWFS_Click( object sender, EventArgs e)
{
string serviceName = " WFSService " ;
// string serviceType = "MAPSERVER";
string strDocPath = string .Empty;
string filepath = @ " F:\地图\LSGXPT.mxd " ;
string hostname = " localhost " ;
#region // 连接到主机服务器
// 连接到主机服务器
IGISServerConnection pGISServerConnection = new ESRI.ArcGIS.Server.GISServerConnectionClass();
pGISServerConnection.Connect(hostname);
// 创建空的服务器上下文
IServerObjectManager som = pGISServerConnection.ServerObjectManager;
IServerContext serverContext = som.CreateServerContext( "" , "" );
// 得到服务对象管理员
IServerObjectAdmin pServerObjectAdmin = pGISServerConnection.ServerObjectAdmin;
IServerObjectConfiguration2 configuration = (IServerObjectConfiguration2)pServerObjectAdmin.CreateConfiguration();
// 获得server服务器列表,判断发布的服务是否存在
IEnumServerObjectConfiguration pEnumServerObjectConfiguration = pServerObjectAdmin.GetConfigurations();
IServerObjectConfiguration2 pp;
for ( int i = 0 ; i < pEnumServerObjectConfiguration.Count; i ++ )
{
pp = (IServerObjectConfiguration2)pEnumServerObjectConfiguration.Next();
String name = pp.Name;
if (name == serviceName)
{
return ;
}
}
#endregion
configuration.Name = serviceName; // 发布Service的名称,必填
configuration.TypeName = " MapServer " ; // 发布服务的类型
#region // 设置服务一般属性
IPropertySet props = configuration.Properties;
props.SetProperty( " FilePath " , filepath); // 设置MXD的路径
// 一下的property并非必须,只要一个filepath就可以发布
props.SetProperty( " OutputDir " , " D:\\ArcGIS9.3\\ArcGIS Server\\arcgisoutput " );
props.SetProperty( " VirtualOutputDir " , " http://localhost/arcgisoutput " );
props.SetProperty( " SupportedImageReturnTypes " , " URL " ); // 支持的图片类型
props.SetProperty( " MaxImageHeight " , " 2048 " ); // 图片的最大高度
props.SetProperty( " MaxRecordCount " , " 500 " ); // 返回记录的最大条数
props.SetProperty( " MaxBufferCount " , " 100 " ); // 缓冲区分析的最大数目
props.SetProperty( " MaxImageWidth " , " 2048 " ); // 图片的最大宽度
props.SetProperty( " IsCached " , " false " ); // 是否切片
props.SetProperty( " CacheOnDemand " , " false " ); // 是否主动切片
props.SetProperty( " IgnoreCache " , " false " ); // 是否忽略切片
props.SetProperty( " ClientCachingAllowed " , " true " ); // 是否允许客户端缓冲
props.SetProperty( " CacheDir " , " D:\\ArcGIS9.3\\ArcGIS Server\\arcgiscache " ); // 切片的输出路径
props.SetProperty( " SOMCacheDir " , " D:\\ArcGIS9.3\\ArcGIS Server\\arcgiscache " ); // som的切片输出路径
#endregion
#region // 设置WFS属性
configuration.set_ExtensionEnabled( " WFSServer " , true );
IPropertySet wfsprops = configuration.get_ExtensionProperties( " WFSServer " );
wfsprops.SetProperty( " CustomGetCapabilities " , " false " );
wfsprops.SetProperty( " EnableTransactions " , " false " );
wfsprops.SetProperty( " Name " , serviceName);
wfsprops.SetProperty( " OnlineResource " , " http://localhost/arcgis/services/MyService/MapServer/WMSServer " );
string AppSchemaURI = " http:// " + hostname + " /arcgis/services/ " + serviceName + " /MapServer/WFSServer " ;
wfsprops.SetProperty( " AppSchemaURI " , " http://localhost/arcgis/services/MyService/MapServer/WMSServer " );
wfsprops.SetProperty( " AppSchemaPrefix " , serviceName);
configuration.set_ExtensionProperties( " WFSServer " , wfsprops);
IPropertySet wfsinfo = configuration.get_ExtensionInfo( " WFSServer " );
wfsinfo.SetProperty( " WebEnabled " , " true " );
configuration.set_ExtensionInfo( " WFSServer " , wfsinfo);
#endregion
#region
configuration.Description = serviceName; // Service的描述
configuration.IsolationLevel = esriServerIsolationLevel.esriServerIsolationHigh; // 或者esriServerIsolationLow,esriServerIsolationAny
configuration.IsPooled = true ; // 是否池化
configuration.MaxInstances = 1 ; // 最多的实例数
configuration.MinInstances = 1 ; // 最少的实例数
// 设置刷新
IPropertySet recycleProp = configuration.RecycleProperties;
recycleProp.SetProperty( " StartTime " , " 00:00 " ); // 刷新开始时间
recycleProp.SetProperty( " Interval " , " 3600 " ); // 刷新间隔
// 设置是否开启REST服务
IPropertySet infoProp = configuration.Info;
infoProp.SetProperty( " WebEnabled " , " true " ); // 是否提供REST服务
infoProp.SetProperty( " WebCapabilities " , " Map,Query,Data " ); // 提供何种服务
configuration.StartupType = esriStartupType.esriSTAutomatic; // 或者esriSTManual
configuration.UsageTimeout = 120 ; // 客户端占用一个服务的最长时间
configuration.WaitTimeout = 120 ; // 客户端申请一个服务的最长等待时间
configuration.set_ExtensionEnabled( " WFSServer " , true );
#endregion
// 添加服务到Server
pServerObjectAdmin.AddConfiguration(configuration);
// 删除服务
// pServerObjectAdmin.DeleteConfiguration("NewService", "MapServer");
// 启动服务
pServerObjectAdmin.StartConfiguration(serviceName, " MapServer " );
// 释放服务器上下文
serverContext.ReleaseContext();
}