ADF连接SOM

   

VS2008新建一个应用如下:

 

 

添加引用如下:

ADF连接SOM_第1张图片

 

 

 

ADF连接SOM_第2张图片

 

service.cs的内容

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Collections;

using ESRI.ArcGIS.Server;
using ESRI.ArcGIS.ADF;
using ESRI.ArcGIS.ADF.Connection.Local;
using ESRI.ArcGIS.ADF.Connection.AGS;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;


// 注意: 如果更改此处的类名“Service”,也必须更新 Web.config 和关联的 .svc 文件中对“Service”的引用。
public class Service : IService
{
public ArrayList GetProvinceNames(string country)
{
string username = "ArcGISSOM";
string password = "111";
string domain = "ohn-THINK";
string hostname = "localhost";
ArrayList results = new ArrayList();
IServerContext serverContext = null;
try
{
using (ComReleaser comReleaser = new ComReleaser())
{
// Create the user identity.
ESRI.ArcGIS.ADF.Identity userIdentity = new ESRI.ArcGIS.ADF.Identity(username, password, domain);

AGSServerConnection agsConnnection = new AGSServerConnection(hostname, userIdentity);
agsConnnection.Connect();
IServerObjectManager som = agsConnnection.ServerObjectManager;
comReleaser.ManageLifetime(som);

serverContext = som.CreateServerContext("World", "MapServer");
IMapServer ms = (IMapServer)serverContext.ServerObject;
IMapServerObjects mapObjs = ms as IMapServerObjects;
IMap map = mapObjs.get_Map(ms.DefaultMapName);
ILayer layer = map.get_Layer(0); // cities 图层
IFeatureLayer flayer = layer as IFeatureLayer;
IFeatureClass featClass = flayer.FeatureClass;

IQueryFilter qf = new QueryFilterClass();
qf.WhereClause = "CNTRY_NAME='" + country + "'";
ICursor cursor = (ICursor)featClass.Search(qf, false);
IDataStatistics dataStatistics = new DataStatisticsClass();
dataStatistics.Field = "ADMIN_NAME";
dataStatistics.Cursor = cursor;
System.Collections.IEnumerator enumerator = dataStatistics.UniqueValues;
enumerator.Reset();

while (enumerator.MoveNext())
{
string countryname = enumerator.Current.ToString();
results.Add(countryname);
}
serverContext.ReleaseContext();
}
}
catch
{
serverContext.ReleaseContext();
}
return results;
}


public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}

public CompositeType GetDataUsingDataContract(CompositeType composite)
{
if (composite.BoolValue)
{
composite.StringValue += "Suffix";
}
return composite;
}
}

 

 

 

 IService.cs的内容

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
using System.Collections;
// 注意: 如果更改此处的接口名称“IService”,也必须更新 Web.config 中对“IService”的引用。
[ServiceContract]
public interface IService
{
[WebGet]
[OperationContract]
ArrayList GetProvinceNames(string country);


[OperationContract]
string GetData(int value);

[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);

// 任务: 在此处添加服务操作
}

// 使用下面示例中说明的数据约定将复合类型添加到服务操作。
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";

[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}

[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}

 

web.config

<%@ ServiceHost Language="C#" Debug="true" Service="Service" CodeBehind="~/App_Code/Service.cs" %>

 效果图:

ADF连接SOM_第3张图片

 

你可能感兴趣的:(ADF连接SOM)