// Create WMS
Protected void btncreatwms_click (Object sender, eventargs E)
{
String strsername = "FMS ";
String strservice = "California ";
String strsertype = "mapserver ";
String strdocpath = string. empty;
# Region
// Connect to the host server
Igisserverconnection pgisserverconnection = new ESRI. ArcGIS. server. gisserverconnectionclass ();
Pgisserverconnection. Connect (strsername );
// Create an empty server context
Iserverobjectmanager som = pgisserverconnection. serverobjectmanager;
Iservercontext servercontext = som. createservercontext ("","");
// Get the object Administrator
Iserverobjectadmin pserverobjectadmin = pgisserverconnection. serverobjectadmin;
Iserverobjectconfiguration2 psoc = pserverobjectadmin. getconfiguration (strservice, strsertype) as iserverobjectconfiguration2;
// Obtain the mxd file of the original service and use this file to generate a new service
// Ipropertyset py2 = psoc. properties;
// Object temp = pde3. getproperty ("filepath ");
// Strdocpath = temp. tostring ();
Iserverobjectconfiguration2 psoc1 = pserverobjectadmin. createconfiguration () as iserverobjectconfiguration2;
Psoc1.name = "myservice ";
Psoc1.typename = "mapserver ";
Psoc1.ispooled = true;
Psoc1.mininstances = 1;
Psoc1.maxinstances = 1;
Psoc1.waittimeout = 10;
Psoc1.usagetimeout = 120;
// Parameters of the new WMS service-file path, delete directory, and virtual directory
Ipropertyset pnewy2 = psoc1.properties;
// Pnewde3. setproperty ("filepath", strdocpath );
Pnewde3. setproperty ("filepath", @ "F: \ data \ newmxd. mxd ");
Pnewde3. setproperty ("outputdir", @ "D: \ arcgis9.3 \ ArcGIS Server \ arcgisoutput ");
Pnewde3. setproperty ("virtualoutputdir", "http: // FMS/arcgisoutput % 22 );
Pnewde3. setproperty ("somcachedir", @ "D: \ arcgis9.3 \ ArcGIS Server \ arcgiscache ");
// Set the WMS name and title
Ipropertyset2 pproset1 = servercontext. Createobject ("esrisystem. propertyset") as ipropertyset2;
Pproset1.setproperty ("name", "newwms ");
Pproset1.setproperty ("title", "titlebydefault ");
// Pproset1.setproperty ("outputdir", @ "D: \ arcgis9.3 \ ArcGIS Server \ arcgisoutput ");
// Pproset1.setproperty ("virtualoutputdir", "http: // FMS/arcgisoutput % 22 );
// Pproset1.setproperty ("onlineresource", "http: // localhost/ArcGIS/services/myservice/mapserver/wmsserver % 22 );
Ipropertyset2 pproset2 = servercontext. Createobject ("esrisystem. propertyset") as ipropertyset2;
Pproset2.setproperty ("webenabled", "true ");
Pproset2.setproperty ("webcapabilities", "map, query, data ");
Psoc1.set _ extensionproperties ("wmsserver", pproset1 );
Psoc1.set _ extensioninfo ("wmsserver", pproset2 );
Psoc1.set _ extensionenabled ("wmsserver", true );
Pserverobjectadmin. addconfiguration (psoc1 );
// Start the service
Pserverobjectadmin. startconfiguration ("myservice", "mapserver ");
// Release the server context
Servercontext. releasecontext ();
# Endregion
}