private void button2_Click(object sender, EventArgs e)
{
if(this.textBox1.Text=="")
{
MessageBox.Show("請輸入主機名!");
return;
}
if(this.textBox2.Text=="")
{
MessageBox.Show("請輸入發佈服務名稱!");
return;
}
if (this.textBox3.Text == "")
{
MessageBox.Show("請選擇發佈MXD文件路徑!");
return;
}
//獲取發佈的主機名稱,服務名稱,發佈文件的地址
hostname = this.textBox1.Text;
servername = this.textBox2.Text;
filepath = this.textBox3.Text;
IGISServerConnection pGISServerConnection;
pGISServerConnection = new GISServerConnectionClass();
//請注意:connect輸入的主機名,表示要連接的服務器
pGISServerConnection.Connect(hostname);
IServerObjectAdmin pServerObjectAdmin;
pServerObjectAdmin = pGISServerConnection.ServerObjectAdmin;
IServerObjectConfiguration2 configuration = (IServerObjectConfiguration2)pServerObjectAdmin.CreateConfiguration();
//獲得server服務器列表,判斷髮布的服務是否存在
IEnumServerObjectConfiguration ss = pServerObjectAdmin.GetConfigurations();
IServerObjectConfiguration2 pp;
for (int i = 0; i < ss.Count;i++ )
{
pp = (IServerObjectConfiguration2)ss.Next();
String name = pp.Name;
if(name==servername)
{
MessageBox.Show("發佈的服務名稱已經存在!");
return;
}
}
configuration.Name = servername;//發佈Service的名稱,必填
configuration.TypeName = "MapServer";//發佈服務的類型,如:MapServer,GeocodeServer
IPropertySet props = configuration.Properties;
//props.SetProperty("FilePath", @"E:\Program Files\ArcGIS\DeveloperKit\SamplesNET\data\World\world.mxd");//設置MXD的路徑
props.SetProperty("FilePath", filepath);//設置MXD的路徑
//一下的property並非必須,只要一個filepath就可以發佈
props.SetProperty("OutputDir", "c:\\arcgisserver\\arcgisoutput");//圖片的輸出目錄
string VirtualOutPutDir = "http://" + hostname + "/arcgisoutput";
props.SetProperty("VirtualOutPutDir", VirtualOutPutDir);//圖片輸出的虛擬路徑
props.SetProperty("SupportedImageReturnTypes", "URL");//支持的圖片類型
props.SetProperty("MaxImageHeight", "2048");//圖片的最大高度
props.SetProperty("MaxRecordCount", "500");//返回記錄的最大條數
props.SetProperty("MaxBufferCount", "100");//緩衝區分析的最大數目
props.SetProperty("MaxImageWidth", "2048");//圖片的最大寬度
props.SetProperty("IsCached", "false");//是否切片
props.SetProperty("CacheOnDemand", "false");//是否主動切片
props.SetProperty("IgnoreCache", "false");//是否忽略切片
props.SetProperty("ClientCachingAllowed", "true");//是否允許客戶端緩衝
string CacheDir = "c:\\arcgisserver\\arcgiscache\\" + servername;
props.SetProperty("CacheDir", CacheDir);//切片的輸出路徑
props.SetProperty("SOMCacheDir", "c:\\arcgisserver\\arcgiscache");//som的切片輸出路徑
if(this.checkBox3.Checked)
{
//設置KML
configuration.set_ExtensionEnabled("KmlServer", true);
IPropertySet kmlprops = configuration.get_ExtensionProperties("KmlServer");
kmlprops.SetProperty("ImageSize", "1024");
kmlprops.SetProperty("Composite", "true");
kmlprops.SetProperty("FeatureLimit", "1000000");
kmlprops.SetProperty("Dpi", "96");
kmlprops.SetProperty("UseNetworkLinkControlTag", "false");
kmlprops.SetProperty("MinRefreshPeriod", "30");
kmlprops.SetProperty("LinkDescription", "");
kmlprops.SetProperty("LinkName", "");
kmlprops.SetProperty("Message", "");
string EndPointURL = "http://" + hostname + "/arcgis/services/" + servername + "/MapServer";
kmlprops.SetProperty("EndPointURL", EndPointURL);
kmlprops.SetProperty("UseDefaultSnippets", "false");
configuration.set_ExtensionProperties("KmlServer", kmlprops);
IPropertySet kmlinfo = configuration.get_ExtensionInfo("KmlServer");
kmlinfo.SetProperty("WebEnabled", "true");
kmlinfo.SetProperty("WebCapabilities", "SingleImage,SeparateImages,Vectors");
configuration.set_ExtensionInfo("KmlServer", kmlinfo);
}
////設置WCS
//configuration.set_ExtensionEnabled("WCSServer", true);
//IPropertySet wcsprops = configuration.get_ExtensionInfo("WCSServer");
//wcsprops.SetProperty("CustomGetCapabilities","false");
//configuration.set_ExtensionProperties("WCSServer", wcsprops);
if(this.checkBox2.Checked)
{
//設置WFS
configuration.set_ExtensionEnabled("WFSServer", true);
IPropertySet wfsprops = configuration.get_ExtensionProperties("WFSServer");
wfsprops.SetProperty("CustomGetCapabilities", "false");
wfsprops.SetProperty("EnableTransactions", "false");
wfsprops.SetProperty("Name", servername);
string + hostname + "/arcgis/services/" + servername + "/MapServer/WFSServer";
wfsprops.SetProperty("OnlineResource", OnlineResource);
string AppSchemaURI = "http://" + hostname + "/arcgis/services/" + servername + "/MapServer/WFSServer";
wfsprops.SetProperty("AppSchemaURI", AppSchemaURI);
wfsprops.SetProperty("AppSchemaPrefix", servername);
configuration.set_ExtensionProperties("WFSServer", wfsprops);
IPropertySet wfsinfo = configuration.get_ExtensionInfo("WFSServer");
wfsinfo.SetProperty("WebEnabled", "true");
configuration.set_ExtensionInfo("WFSServer", wfsinfo);
}
if(this.checkBox1.Checked)
{
//設置WMS
configuration.set_ExtensionEnabled("WMSServer", true);
IPropertySet wmsprops = configuration.get_ExtensionProperties("WMSServer");
wmsprops.SetProperty("CustomGetCapabilities", "false");
wmsprops.SetProperty("PathToCustomGetCapabilitiesFiles", "");
wmsprops.SetProperty("Name", "WMS");
wmsprops.SetProperty("Title", servername);
wmsprops.SetProperty("Abstract", "");
wmsprops.SetProperty("Keyword", "");
string + hostname + "/arcgis/services/" + servername + "/MapServer/WMSServer";
wmsprops.SetProperty("OnlineResource", OnlineResource);
wmsprops.SetProperty("ContactPerson", "");
wmsprops.SetProperty("ContactPosition", "");
wmsprops.SetProperty("ContactOrganization", "");
wmsprops.SetProperty("AddressType", "");
wmsprops.SetProperty("City", "");
wmsprops.SetProperty("StateOrProvince", "");
wmsprops.SetProperty("PostCode", "");
wmsprops.SetProperty("Country", "");
wmsprops.SetProperty("ContactVoiceTelephone", "");
wmsprops.SetProperty("ContactFacsimileTelephone", "");
wmsprops.SetProperty("ContactElectronicMailAddress", "");
wmsprops.SetProperty("Fees", "");
wmsprops.SetProperty("AccessConstraints", "");
configuration.set_ExtensionProperties("WMSServer", wmsprops);
IPropertySet wmsinfo = configuration.get_ExtensionInfo("WMSServer");
wmsinfo.SetProperty("WebEnabled", "true");
wmsinfo.SetProperty("WebCapabilities", "");
configuration.set_ExtensionInfo("WMSServer", wmsinfo);
}
configuration.Description = servername;//Service的描述
configuration.IsolationLevel = esriServerIsolationLevel.esriServerIsolationHigh;//或者esriServerIsolationLow,esriServerIsolationAny
configuration.IsPooled = true;//是否池化
configuration.MaxInstances = 1;//最多的實例數
configuration.MinInstances = 1;//最少的實例數
//設置刷新
IPropertySet recycleProp = configuration.RecycleProperties;
recycleProp.SetProperty("StartTime", "00:00");//刷新開始時間
recycleProp.SetProperty("Interval", "3600");//刷新間隔
//設置是否開啓REST服務
IPropertySet infoProp = configuration.Info;
infoProp.SetProperty("WebEnabled", "true");//是否提供REST服務
infoProp.SetProperty("WebCapabilities", "Map,Query,Data");//提供何種服務
configuration.StartupType = esriStartupType.esriSTAutomatic;//或者esriSTManual
configuration.UsageTimeout = 120;//客戶端佔用一個服務的最長時間
configuration.WaitTimeout = 120;//客戶端申請一個服務的最長等待時間
if (this.checkBox3.Checked)
{
configuration.set_ExtensionEnabled("KmlServer", true);
}
if (this.checkBox2.Checked)
{
configuration.set_ExtensionEnabled("WFSServer", true);
}
if (this.checkBox1.Checked)
{
configuration.set_ExtensionEnabled("WMSServer", true);
}
//添加服務到Server
pServerObjectAdmin.AddConfiguration(configuration);
//刪除服務
//pServerObjectAdmin.DeleteConfiguration("NewService", "MapServer");
//啓動服務
pServerObjectAdmin.StartConfiguration(servername, "MapServer");
MessageBox.Show("發佈成功!");
}