Select to view content in your preferred language

C# Create a Service in an Existing Folder

1003
3
Jump to solution
02-07-2013 06:53 AM
AkhilParujanwala
Regular Contributor
I am trying to create a service in a folder called Mobile_Services.
When I publish a map using ArcMap or ArcCatalog I am able to select an Existing folder called "Mobile_Services".
But when I use the code below, the location of the service appears into the root directory of the server, which is the default as mentioned in the help files.

I would like to have the service created in an existing folder called "Mobile_Services".
Please have a look at my code and hope fully someone can shed some light on this.

        public static void PublishMobileMapServiceForRaDCAMS(string serverMachineName, string serviceName, string pathToMXD)         {             //define paths for the onlineresource property in the extension properties             string resourceWMS = "http://" + serverMachineName + "/ArcGIS/services/" + serviceName + "/MapServer/WMSServer";             string resourceMobile = "http://" + serverMachineName + "/ArcGIS/services/" + serviceName + "/MapServer/MobileServer";              //  Connect to the ArcGIS server called  serverMachineName (string) .                IGISServerConnection pGISServerConnection = new GISServerConnectionClass();             pGISServerConnection.Connect(serverMachineName);              // create the new configuration             IServerObjectAdmin4 pServerObjectAdmin = (IServerObjectAdmin4)pGISServerConnection.ServerObjectAdmin;             IServerObjectConfiguration pConfiguration = pServerObjectAdmin.CreateConfiguration();             IServerObjectConfiguration2 pConfiguration2 = (IServerObjectConfiguration2)pConfiguration;             IServerObjectConfiguration3 pConfiguration3 = (IServerObjectConfiguration3)pConfiguration;              // set the   General Configuration Settings             pConfiguration.Name = serviceName;           //  the name of this configuration             pConfiguration.TypeName = "MapServer";   // the type of server object to be created             pConfiguration.IsPooled = true;             pConfiguration.MinInstances = 1;             pConfiguration.MaxInstances = 2;             pConfiguration.WaitTimeout = 60;             pConfiguration.UsageTimeout = 600;             pConfiguration.StartupType = esriStartupType.esriSTAutomatic;             pConfiguration.IsolationLevel = esriServerIsolationLevel.esriServerIsolationHigh;               //IEnumServerDirectory pEnumServerDirectories = pServerObjectAdmin.GetServerDirectories();             //pEnumServerDirectories.Reset();             //IServerDirectory pServerDirectory = pEnumServerDirectories.Next();             //while (pServerDirectory != null)             //{             //    if (((IServerDirectory2)pServerDirectory).Type == esriServerDirectoryType.esriSDTypeOutput)             //    {             //        string dir = pServerDirectory.Path;             //        string vdir = pServerDirectory.URL;             //        break;             //    }             //}               //  Set the configuration Properties of the MapServer Object             IPropertySet pProps = pConfiguration.Properties;             pProps.SetProperty("FilePath", pathToMXD);    // required property             pProps.SetProperty("OutputDir", "c:\\arcgisserver\\arcgisoutput");             string virtualOutDir = " http://" + serverMachineName + "/arcgisoutput";             pProps.SetProperty("VirtualOutputDir", virtualOutDir);                         pProps.SetProperty("MaxImageHeight", "2048");             pProps.SetProperty("MaxRecordCount", "500");             pProps.SetProperty("MaxBufferCount", "100");             pProps.SetProperty("MaxImageWidth", "2048");             pConfiguration.Properties = pProps;                          //  Set the info segment of the MapServer Object  properties             IPropertySet info = pConfiguration2.Info;             info.SetProperty("WebEnabled", "true");             info.SetProperty("WebCapabilities", "Map,Query,Data");             pConfiguration2.Info = info;              //  Set the recycle properties of the MapSrver object             IPropertySet pProp = pConfiguration.RecycleProperties;             pProp.SetProperty("StartTime", "1:00 AM");    //   start recycling at midnight             pProp.SetProperty("Interval", "86400");      //  every 24 hours             pConfiguration.RecycleProperties = pProp;               // create a mobile server and web enabled             pConfiguration2.set_ExtensionEnabled("Mobileserver", true);             IServerObjectManager pServerObjectManager = pGISServerConnection.ServerObjectManager;             IServerContext serverContext = pServerObjectManager.CreateServerContext(string.Empty, string.Empty);             IPropertySet2 extensionSet = serverContext.CreateObject("esriSystem.PropertySet") as IPropertySet2;             extensionSet.SetProperty("WebEnabled", "true");             extensionSet.SetProperty("WebCapabilities", "");             pConfiguration2.set_ExtensionInfo("Mobileserver", extensionSet);              //' add the configuration to  the server             pServerObjectAdmin.AddConfiguration(pConfiguration2);                         pServerObjectAdmin.StartConfiguration(serviceName, "MapServer");                                       //IEnumBSTR pEnumBSTR = pServerObjectAdmin.GetFolders("arcgisoutput");             //pEnumBSTR.Reset();             //string fName = pEnumBSTR.Next();             //while (pEnumBSTR.Next() != null)             //{             //    fName = pEnumBSTR.Next();                             //}         }


Thanks in advance!
1 Solution

Accepted Solutions
AkhilParujanwala
Regular Contributor
Ok I have solved my own problem.
There were two lines of code that I changed.

It turns out you need to have the folder name with a forward slash integrated with the service name to indicate that the service should be created in a virtual folder.

pConfiguration.Name = folderName + "/" + serviceName; pServerObjectAdmin.StartConfiguration(folderName + "/" + serviceName, "MapServer");


Unfortunately the SDK doesn't say anything about adding the virtual folder to the name of the service.
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Name_Property/003z000000...

Regardless, I have figured it out and now I can finally create a map document and a service from start to finish in one click!

Hope this helps others.

View solution in original post

0 Kudos
3 Replies
AkhilParujanwala
Regular Contributor
Can anyone please assist me, I really need this to complete one of my applications.
I cannot have my services created on the root of the server, they must be placed into an existing folder.
In my example the folder is called "Mobile_Services".
0 Kudos
AkhilParujanwala
Regular Contributor
I have tried the following, and I have looked at other MapService.cfg files that I create using ArcMap and I still cannot make a service inside a folder.

            //  Set the configuration Properties of the MapServer Object
            IPropertySet pProps = pConfiguration.Properties;
            pProps.SetProperty("FilePath", pathToMXD);    // required property
            pProps.SetProperty("OutputDir", "c:\\arcgisserver\\arcgisoutput");
            string virtualOutDir = " http://" + serverMachineName + "/arcgisoutput";
            pProps.SetProperty("VirtualOutputDir", virtualOutDir);
            pProps.SetProperty("SupportedImageReturnTypes", "URL");
            pProps.SetProperty("MaxImageHeight", "2048");
            pProps.SetProperty("MaxRecordCount", "500");
            pProps.SetProperty("MaxBufferCount", "100");
            pProps.SetProperty("MaxImageWidth", "2048");
            pProps.SetProperty("IsCached", "false");
            pProps.SetProperty("CacheOnDemand", "false");
            pProps.SetProperty("IgnoreCache", "false");
            pProps.SetProperty("ClientCachingAllowed", "true");
            pProps.SetProperty("CacheDir", "c:\\arcgisserver\\arcgiscache\\" + "Mobile_Services_" + serviceName);
            pProps.SetProperty("SOMCacheDir", "c:\\arcgisserver\\arcgiscache");
            pConfiguration.Properties = pProps;


As you can see in the CacheDir, I told it to be inside the Mobile_Services folder, but when I look at the server, the service is still created at the root directory.

Please help.
0 Kudos
AkhilParujanwala
Regular Contributor
Ok I have solved my own problem.
There were two lines of code that I changed.

It turns out you need to have the folder name with a forward slash integrated with the service name to indicate that the service should be created in a virtual folder.

pConfiguration.Name = folderName + "/" + serviceName; pServerObjectAdmin.StartConfiguration(folderName + "/" + serviceName, "MapServer");


Unfortunately the SDK doesn't say anything about adding the virtual folder to the name of the service.
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Name_Property/003z000000...

Regardless, I have figured it out and now I can finally create a map document and a service from start to finish in one click!

Hope this helps others.
0 Kudos