arcengine 加载服务

Engine无法通过REST+token的方式加载加密服务,需要通过SOAP+用户名密码的方式,如: 

三种方式:

public ILayer AddServiceLayer(string url, string serviceName) 

//create a new ArcGIS Server connection factory 
ESRI.ArcGIS.GISClient.IAGSServerConnectionFactory2 connectionFactory; 
connectionFactory = (ESRI.ArcGIS.GISClient.IAGSServerConnectionFactory2)new ESRI.ArcGIS.GISClient.AGSServerConnectionFactory(); 
//create a property set to hold connection properties 
IPropertySet connectionProps; 
connectionProps = new PropertySet(); 
//specify the URL for the server 
connectionProps.SetProperty(URL, url); 
//define username and password for the connection 
connectionProps.SetProperty(USER, <USER>); 
connectionProps.SetProperty(PASSWORD, <PASS>); 
//open the server connection, pass in the property set, get a connection object back 
ESRI.ArcGIS.GISClient.IAGSServerConnection gisServer; 
gisServer = connectionFactory.Open(connectionProps, 0); 

//get an enum of all server object names from the server (GIS services, i.e.) 
ESRI.ArcGIS.GISClient.IAGSEnumServerObjectName soNames = gisServer.ServerObjectNames; 
ESRI.ArcGIS.GISClient.IAGSServerObjectName3 soName; 
//loop thru all services, find a map service called I3_Imagery_Prime_World_2D (high res imagery for the world) 
soName = (ESRI.ArcGIS.GISClient.IAGSServerObjectName3)soNames.Next(); 
do 

if ((soName.Type == MapServer) && (soName.Name == serviceName)) 

break; //found it 

//keep searching the services ... 
soName = (ESRI.ArcGIS.GISClient.IAGSServerObjectName3)soNames.Next(); 
} while (soName != null); 
//if the desired service was found ... 
ILayer serviceLayer = null; 
if (soName != null) 

//create a layer factory to make a new MapServerLayer from the server object name 
ILayerFactory msLayerFactory; 
msLayerFactory = new MapServerLayerFactory(); 
//create an enum of layers using the name object (will contain only a single layer) 
IEnumLayer enumLyrs = msLayerFactory.Create(soName); 
//get the layer from the enum, store it in a MapServerLayer variable 
IMapServerLayer mapServerLayer; 
mapServerLayer = (IMapServerLayer)enumLyrs.Next(); 
//make sure the layer is not empty (Nothing), then add it to the map 
if (mapServerLayer != null) 

serviceLayer = ((ILayer)mapServerLayer); 


return serviceLayer; 

 

public IMapServer GetMapServer(string agsUrl, string serviceName) 

IMapServer mapserver = null; 

//Set connection propertyset. sample URL: http://host:port/arcgis/services. 
IPropertySet propertySet = new PropertySetClass(); 
propertySet.SetProperty(url, agsUrl); 

//Open an AGS connection. 
Type factoryType = Type.GetTypeFromProgID(esriGISClient.AGSServerConnectionFactory); 
IAGSServerConnectionFactory agsFactory = (IAGSServerConnectionFactory)Activator.CreateInstance(factoryType); 
IAGSServerConnection agsConnection = agsFactory.Open(propertySet, 0); 

//Get the image server. 
IAGSEnumServerObjectName agsServerObjectNames = agsConnection.ServerObjectNames; 
agsServerObjectNames.Reset(); 
IAGSServerObjectName agsServerObjectName = agsServerObjectNames.Next(); 
while (agsServerObjectName != null) 

if ((agsServerObjectName.Name.ToLower() == serviceName.ToLower()) && (agsServerObjectName.Type == MapServer)) 

IName pName = (IName)agsServerObjectName; 
IAGSServerObject agsServerObject = (IAGSServerObject)pName.Open(); 
mapserver = (IMapServer)agsServerObject; 
break; 

agsServerObjectName = agsServerObjectNames.Next(); 

//Return the image server object. 
return mapserver; 

public IServerObjectAdmin ConnectAGS(string host, string username, string password) 

IServerObjectAdmin m_ServerObjectAdmin = null; 
try 

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); 
IAGSServerConnectionName3 connectName = new AGSServerConnectionNameClass() as IAGSServerConnectionName3; 
connectName.ConnectionProperties = propertySet; 
IAGSServerConnectionAdmin agsAdmin = ((IName)connectName).Open() as IAGSServerConnectionAdmin; 

m_ServerObjectAdmin = agsAdmin.ServerObjectAdmin; 

catch (Exception exc) 

Console.WriteLine(连接失败:{0}.Message:{1}, host, exc.Message); 
return null; 

return m_ServerObjectAdmin; 
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值