An enhanced approach to get image server name object without opening it up (without providing username/password when creating layer):
private static IName GetImageServerName(string hostOrUrl, string serviceName)
{
IPropertySet propSet = new PropertySetClass();
propSet.SetProperty("url", hostOrUrl);
propSet.SetProperty("ANONYMOUS", false);
//don't hardcode user/password
//propertySet.SetProperty("user", userName);
//propertySet.SetProperty("password", password);
IAGSServerConnectionName agsServerConnectName = new AGSServerConnectionNameClass();
agsServerConnectName.ConnectionProperties = propSet;
IAGSServerObjectName agsSOName = new AGSServerObjectNameClass();
agsSOName.AGSServerConnectionName = agsServerConnectName;
agsSOName.Name = serviceName;
agsSOName.Type = "ImageServer";
return (IName)agsSOName;
}