I am migrating some ArcObjects C# code to 10.1 and am having some trouble programatically publishing an MSD. We are using a multi-site configuration (not sure if that matters). Here is the code I am using to publish. I have added some comments to help clarify.
IAGSServerConnectionFactory3 pConnectionFactory = new AGSServerConnectionFactoryClass();
//admin connection file works fine, tested in ArcCatalog on the same server
IAGSServerConnection4 server = pConnectionFactory.OpenFromFile(@"e:\admin-connection.ags", 0) as IAGSServerConnection4;
IAGSServerConnectionAdmin pAGSServerConnectionAdmin = server as IAGSServerConnectionAdmin;
IServerObjectAdmin pServerObjectAdmin = pAGSServerConnectionAdmin.ServerObjectAdmin;
IServerObjectConfiguration4 pConfiguration = (IServerObjectConfiguration4)pServerObjectAdmin.CreateConfiguration();
//Set the general configuration settings
pConfiguration.Name = "output_56";
pConfiguration.TypeName = "MapServer";
pConfiguration.Description = "Map Output"; // required field in 10.1? Read that somewhere and added
pConfiguration.IsPooled = true;
pConfiguration.MinInstances = 1;
pConfiguration.MaxInstances = 15;
pConfiguration.WaitTimeout = 60;
pConfiguration.UsageTimeout = 600;
pConfiguration.IdleTimeout = 1800;
pConfiguration.StartupType = esriStartupType.esriSTAutomatic;
pConfiguration.IsolationLevel = esriServerIsolationLevel.esriServerIsolationAny;
//Set the configuration properties of the MapServer
IPropertySet pProps = pConfiguration.Properties;
//I have confirmed that the MSD exists and the FilePath is correct
pProps.SetProperty("FilePath", mapDocument);
//output directory is at network path on primary server on site \\10.7.1.XX\arcgisserver\directories\arcgisoutput\UserSims
// it should be noted that an empty directory is created here before the program crashes
pProps.SetProperty("OutputDir", outputDir);
//serverHost = "localhost", which is a secondary ArcServer on the site
// I commented this out because it looks like the arcgisoutput directory does not exist anymore.
// I'm not sure if this is required to publish, since we set OutputDir
//pProps.SetProperty("VirtualOutputDir", "http://" + serverHost + "/arcgisoutput");
pProps.SetProperty("MaxImageHeight", "2048");
pProps.SetProperty("MaxRecordCount", "1000");
pProps.SetProperty("MaxBufferCount", "100");
pProps.SetProperty("MaxImageWidth", "2048");
pConfiguration.Properties = pProps;
//Set the info segment properties
IPropertySet info = pConfiguration.Info;
info.SetProperty("WebEnabled", "true");
info.SetProperty("WebCapabilities", "Map,Query,Data");
pConfiguration.Info = info;
//Set the recycle properties of the MapServer object
IPropertySet recycle = pConfiguration.RecycleProperties;
recycle.SetProperty("StartTime", "1:00 AM");
recycle.SetProperty("Interval", "86400");
pConfiguration.RecycleProperties = recycle;
//Add the configuration to the server
pServerObjectAdmin.AddConfiguration(pConfiguration); //crashes here
pServerObjectAdmin.StartConfiguration(service, "MapServer");
Here is the error I am getting.
Unhandled Exception: System.Runtime.InteropServices.COMException (0x80040208): E
RROR: service failed to start, Cannot connect to this server.
at ESRI.ArcGIS.Server.IServerObjectAdmin.AddConfiguration(IServerObjectConfig
uration config)
at Matric.Modsim.SimulationCruncher.Publish.AddMapService(Geoprocessor gp, IA
GSServerConnection4 server, String serverHost, String outputDir, String service,
String mapDocument) in C:\Users\matt.moyles\Documents\Visual Studio 2010\Projec
ts\simulation2\simulation\Publish.cs:line 111
The error does not make sense to me, because I have confirmed the connection file is valid.
If anyone could provide any insight or suggestions I would be very grateful!
EDIT:
I also found this relevant entry in the arcgisserver logs:
Failed to construct instance of service 'UserSims/output_56.MapServer'.
Answer
You most likely have to recreate the service definition using ArcMap 10.1.
I believe many things were changed at 10.1--one of those being the service definition file format, which now has the extension ".sd" instead of ".msd" (I don't think renaming the file is sufficient however). Have you attempted to publish the MSD directly through ArcMap before trying to publish it programmatically? If it fails in ArcMap, it will also fail via .NET.
If you still have the source MXD file, I would load it in ArcMap and attempt to Share As > Service
and Save a service definition file
.
See this ArcGIS Help article: Migration to ArcGIS 10.1 for Server
Although it deals specifically with Image Services at 10.1, you might also find this code sample helpful
No comments:
Post a Comment