• 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" %>

     效果图:

  • 相关阅读:
    个人便签
    秒杀系统架构分析与实战
    NPOI大数据分批写入同个Excel
    js获取鼠标坐标位置兼容多个浏览器
    月薪3万的程序员都避开了哪些坑
    怎样理解阻塞非阻塞与同步异步的区别?
    JS中的prototype
    互联网——降级论
    fedora自带OpenJDK,所以如果安装官方的JDK的话要先删除OpenJDK
    cygwin 安装完后不能进入think问题,网上99%都是错误的
  • 原文地址:https://www.cnblogs.com/arcserver/p/2780898.html
Copyright © 2020-2023  润新知