6

I am using ArcGIS Server 10.1.

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.

I also found this relevant entry in the arcgisserver logs:

<Msg time="2012年06月20日T15:13:27,824" type="SEVERE" code="8274" source="Server" process="632" thread="1" methodName="" machine="ROGER-WATERS.TECH.LOCAL" user="" elapsed="">Failed to construct instance of service 'UserSims/output_56.MapServer'. </Msg>
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jun 20, 2012 at 19:25

3 Answers 3

6
+50

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

answered Jun 25, 2012 at 13:32
0
3

For the benefit of others. Here is what worked for me on our clustered server configuration.

 IAGSServerConnectionAdmin pAGSServerConnectionAdmin = server as IAGSServerConnectionAdmin;
 IServerObjectAdmin pServerObjectAdmin = pAGSServerConnectionAdmin.ServerObjectAdmin;
 IServerObjectConfiguration5 pConfiguration = (IServerObjectConfiguration5)pServerObjectAdmin.CreateConfiguration();
 //Set the general configuration settings
 pConfiguration.Name = service;
 pConfiguration.TypeName = "MapServer";
 pConfiguration.TargetCluster = "default";
 pConfiguration.StartupType = esriStartupType.esriSTAutomatic;
 pConfiguration.IsolationLevel = esriServerIsolationLevel.esriServerIsolationHigh;
 pConfiguration.IsPooled = true;
 pConfiguration.Description = "Modsim Map Output";
 pConfiguration.LoadBalancing = esriLoadBalancing.esriLoadBalancingRoundRobin;
 pConfiguration.MinInstances = 1;
 pConfiguration.MaxInstances = 15;
 pConfiguration.WaitTimeout = 60;
 pConfiguration.UsageTimeout = 600;
 pConfiguration.IdleTimeout = 1800;
 //Set the configuration properties of the MapServer
 IPropertySet pProps = pConfiguration.Properties;
 pProps.SetProperty("FilePath", mapDocument);
 pProps.SetProperty("OutputDir", outputDir);
 pProps.SetProperty("MaxImageHeight", "2048");
 pProps.SetProperty("MaxRecordCount", "1000");
 pProps.SetProperty("MaxBufferCount", "100");
 pProps.SetProperty("MaxImageWidth", "2048");
 pConfiguration.Properties = pProps;
 //MIME+URL (virtual directory)
 IEnumServerDirectory dirs = pServerObjectAdmin.GetServerDirectories();
 dirs.Reset();
 IServerDirectory serverDir = dirs.Next();
 while (serverDir != null)
 {
 if (((IServerDirectory2)serverDir).Type == esriServerDirectoryType.esriSDTypeOutput)
 {
 pProps.SetProperty("OutputDir", serverDir.Path);
 pProps.SetProperty("VirtualOutputDir", serverDir.URL);
 break;
 gp.AddMessage("[DEBUG] Outputpath: " + serverDir.Path + " || Virtual: " + serverDir.URL);
 }
 serverDir = dirs.Next();
 }
 //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);
 pServerObjectAdmin.StartConfiguration(service, "MapServer");
answered Jun 25, 2012 at 16:27
0
0

you can use new api administrator rest for these operations http://resources.arcgis.com/en/help/main/10.1/0154/0154000005p3000000.htm using also c# also because at 10.1, you can no longer use ArcObjects remotely (via DCOM); this way of interacting with ArcGIS for Server is no longer supported. If you are using GISServerConnection in the Server library or AGSServerConnection in the GISClient library in your code, these need to be removed if you are working with ArcGIS 10.1 for Server.

you can use rest api admin. I have written code c# in my blog (see CreateService) http://nicogis.blogspot.it/2012/10/ags-101-restful-administrative-api.html

answered Sep 29, 2012 at 11:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.