/// <summary>
/// 连接地图服务
/// </summary>
/// <param name="pHostOrUrl"></param>
/// <param name="pServiceName"></param>
/// <param name="userName"></param>
/// <param name="pwd"></param>
/// <param name="pIsLAN">是否有访问权限默认为没有true</param>
/// <returns></returns>
public IMapServer GetMapServer(string pHostOrUrl, string pServiceName, string userName = "", string pwd = "", bool pIsLAN = true)
{
IPropertySet pPropertySet = new PropertySetClass();
IMapServer pMapServer = null;
try
{
if (string.IsNullOrEmpty(userName)) pIsLAN = true;
if (pIsLAN)
pPropertySet.SetProperty("machine", pHostOrUrl);
else
{
pPropertySet.SetProperty("url", pHostOrUrl);
pPropertySet.SetProperty("user", userName);
pPropertySet.SetProperty("password", pwd);
}
Type factoryType = Type.GetTypeFromProgID("esriGISClient.AGSServerConnectionFactory");
IAGSServerConnectionFactory pFactory = (IAGSServerConnectionFactory)Activator.CreateInstance(factoryType);
IAGSServerConnection pConnection = pFactory.Open(pPropertySet, 0);
IAGSEnumServerObjectName pServerObjectNames = pConnection.ServerObjectNames;
IAGSServerObjectName ServerObjectName = pServerObjectNames.Next();
while (ServerObjectName != null)
{
if ((ServerObjectName.Name.ToLower() == pServiceName.ToLower()) &&
(ServerObjectName.Type == "MapServer"))
{
break;
}
ServerObjectName = pServerObjectNames.Next();
}
if (ServerObjectName == null)
{
return null;
}
IName pName = ServerObjectName as IName;
//访问地图服务
IAGSServerObject pServerObject = pName.Open() as IAGSServerObject;
pMapServer = pServerObject as IMapServer;
}
catch (Exception ex)
{
throw new Exception("打开MapServer异常:" + ex.Message + "!\r\n请确认MapServer服务是否有访问权限,如有请配置相应权限后重试。");
}
return pMapServer;
}
网友评论