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.
Thanks in advance!
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.
Code:
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();
//}
}