ASP.NET 2.0 AJAX中能够在客户端js中很方便地调用服务器Webservice,以下为一些调用的示例。笔者安装的ASP.NET 2.0 AJAX
版本为AJAX November CTP。
三个示例分别为: 1 带参数的WS方法 2 不带参数的WS方法 3 参数类型为DataTable的WS方法
一、WebMethod 注意要点: 1 WebMethod类需要添加命名空间 Microsoft.Web.Script.Services,此空间需要引用Microsoft.Web.Preview.dll 2 类声明加入标签 [ScriptService] 3 在Asp.net 2.0里可以直接用DataTable作为返回类型了,但是需要在Web.config文件添加序列化转换器的属性。DataSet、DataTable、DataRow均有转换器
<system.web.extensions> <scripting> <webServices> <jsonSerialization> <converters> <add name="DataSetConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataSetConverter, Microsoft.Web.Preview"/> <add name="DataRowConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataRowConverter, Microsoft.Web.Preview"/> <add name="DataTableConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataTableConverter, Microsoft.Web.Preview"/> </converters> </jsonSerialization> </webServices> </scripting> </system.web.extensions> WEB服务1:WS1
using System; using System.Web; using System.Collections; using System.Web.Services; using System.Web.Services.Protocols; using Microsoft.Web.Script.Services; using System.Data; /**//// <summary> /// WS1 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/ ")]
上一篇:Webservice中使用Session、Application
下一篇:asp中可以保存参数值的分页代码
复制本页网址和标题,发送给你QQ/Msn的好友一起分享