摘要: WebServices的概念 Webservice是一个平台独立的,低耦合的,自包含的、基于可编程的web的应用程序,可使用开放的XML(标准通用标记语言下的一个子集)标准来描述、发布、发现、协调和配置这些应用程序,用于开发分布式的互操作的应用程序。 WebS...
WebServices的概念
Webservice是一个平台独立的,低耦合的,自包含的、基于可编程的web的应用程序,可使用开放的XML(标准通用标记语言下的一个子集)标准来描述、发布、发现、协调和配置这些应用程序,用于开发分布式的互操作的应用程序。
WebService技术,能使得运行在不同机器上的不同应用无须借助附加的、专门的第三方软件或硬件,就可相互交换数据或集成。依据Web Service规范实施的应用之间,无论它们所使用的语言、平台或内部协议是什么,都可以相互交换数据。Web Service是自描述、自包含的可用网络模块,可以执行具体的业务功能。Web Service也很容易部署,因为它们基于一些常规的产业标准以及已有的一些技术,诸如标准通用标记语言下的子集XML、HTTP。Web Service减少了应用接口的花费。Web Service为整个企业甚至多个组织之间的业务流程的集成提供了一个通用机制。
WebServices调用AO的方法:
1.服务器端代码:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.DataSourcesGDB; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.DataSourcesFile; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。// [System.Web.Script.Services.ScriptService] public class Service : System.Web.Services.WebService { public Service () { //如果使用设计的组件,请取消注释以下行 //InitializeComponent(); } [WebMethod] public string HelloWorld() { return "Hello World"; } [WebMethod] public bool AddPointToFileGDB(double x, double y) { IAoInitialize aoInit = new AoInitializeClass(); aoInit.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcServer); IWorkspaceFactory pWSF = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass() as IWorkspaceFactory; ESRI.ArcGIS.esriSystem.IPropertySet pPropertySet = new ESRI.ArcGIS.esriSystem.PropertySetClass(); pPropertySet.SetProperty("DATABASE", @"D:\数据\New File Geodatabase.gdb"); IFeatureWorkspace pFW = pWSF.Open(pPropertySet, 0) as IFeatureWorkspace; IPoint pPoint = new PointClass(); pPoint.X = x; pPoint.Y = y; IFeatureClass pFC = pFW.OpenFeatureClass("point"); IFeature pF = pFC.CreateFeature(); pF.Shape = pPoint; pF.Store(); return true; } }
2.客户端代码:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { addpointserver.Service se = new addpointserver.Service(); se.AddPointToFileGDBCompleted += new addpointserver.AddPointToFileGDBCompletedEventHandler(se_AddPointToFileGDBCompleted); se.AddPointToFileGDBAsync(double.Parse(TextBox1.Text),double.Parse( TextBox2.Text)); } void se_AddPointToFileGDBCompleted(object sender, addpointserver.AddPointToFileGDBCompletedEventArgs e) { Response.Write("done!"); } }
3.注意事项:file gdb所在所在目录必须有 ASPNET角色和NETWorkService角色的读写权限,不然不能读写
4.在WinXP下,使文件夹属性页有“安全”标签页的方法:
(1)打开资源管理器
(2)进入 工具——文件夹选项 菜单,切换到“查看”标签页
(3)去掉“使用简单文件共享(推荐)”选项