ADF连接SOM
VS2008新建一个应用如下:
添加引用如下:
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" %>
效果图:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET10 - 预览版1新功能体验(一)