Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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:

<Msg time="2012-06-20T15: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>
share|improve this question

3 Answers 3

up vote 5 down vote accepted
+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

share|improve this answer
    
I can publish it in ArcMap. Interesting code sample, that might just work. –  dubvfan87 Jun 25 '12 at 15:29
    
I was able to use that sample to add the extra parts I was missing into my configuration. I was missing: pConfiguration.LoadBalancing = esriLoadBalancing.esriLoadBalancingRoundRobin; and had my Output and VirutalDirectories wrong. The code from the sample reads the directories from the connection. Enjoy the bounty there. Arrrrrrrrrrrrr. –  dubvfan87 Jun 25 '12 at 16:08

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

share|improve this answer

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");
share|improve this answer
    
Very nice, thank you for sharing. Its just very sad that it takes this much effort to replace what ESRI had in ArcXML/ArcCMD out of the box. And after 6 years of AGS still has not given us good tools to use to automate managing our servers and services. –  D.E.Wright Jun 25 '12 at 17:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.