All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
sql之组合条件和布尔运算符_[SQL,Server教程]
开发某项目用到的全部50个Sql语句_[SQL Server教程]
想学ASP.NET,来看看一些建议_.net资料_编程技术
最简单快速的Apache二级域名实现方法介绍_php资料_编程技术
DB2,9和ASP.NET2.0构建下一代应用程序之二_[Asp.Net教程]
SQL,Server,7.0,入门(五)_mssql学习_编程技术
将DBF,XLS,XML,MDB文件导入C#DataGrid的方法_[Asp.Net教程]
ASPX文件转HTML_[Asp.Net教程]
Login控件也可添加图文验证码_[Asp.Net教程]
用php读取xml数据_php资料_编程技术
Reading number is top 10 pictures
鸡蛋的新玩法
The wise woman of chest2
9.3阅兵全景图3-外国方阵梯队和坦克方阵梯队
姑娘手慢了,已经走光了
The Soviet union swimsuit exposure in the 70 year3
Summer is most suitable for young people to travel in China6
China's programmers are live what kind, had a look at will know that
中国女孩大胆自拍,显露完美身材4
The money of more than 100 countries and regions22
Ashlynn Brooke show proud chest measurement1
Download software ranking
Macromedia Dreamweaver 8
matrix3
Unix video tutorial8
Sora aoi 120 minutes
变速齿轮3.26
linux初级教程
网络管理员第三版
Such love down(擒爱记)
天龙八部最新服务端
The hero
归海一刀 published in(发表于) 2014/1/30 0:52:03 Edit(编辑)
Asp.Net,Ajax,学习笔记6,客户端访问WebService(上)_[Asp.Net教程]

Asp.Net,Ajax,学习笔记6,客户端访问WebService(上)_[Asp.Net教程]

Asp.Net Ajax 学习笔记6 客户端访问WebService(上)_[Asp.Net教程]

1、要客户端能访问WebService,那么WebService类必须加上[ScriptService]标记,此标记在System.Web.Script.Services命名空间下,并且被访问的方法必须是public和加上[WebMethod]标记。客户端在ScriptManager标签之间加上如下代码


InlineScript属性表示是否将代理缓存到页面中(HTML源码中)。在js代码调用WebService时,如果WebService有命名空间,必须加上命名空间调用,并且WebService里面方法是作为静态方法调用,也就是说,不用实例化WebService。在客户端调用WebService的方法的时候,ScriptManager代理的方法后默认追加几个参数个参数,


注意,即使没有返回值也会调用回调函数。


2、客户端访问页面的方法。页面的方法必须写在aspx页面文件对应的aspx.cs文件上。方法必须是public和static并且用[WebMethod]标记。客户端必须使用PageMethods.方法名()访问,并且与访问WebService一样有成功后的回调函数。注:ScriptManager的EnablePageMethods属性必须设置为true,才能访问页面的方法。一般很少使用客户端访问页面的方法。


3、调用PageMethod和WebService的错误处理。如第一点所描述的失败回调函数的参数为一个error对象,那么错误对象有一下几种方法,来返回错误的一些信息WebService方法:


[WebMethod]
public Employee DoubleSalary(Employee employee)
{
employee.Salary *= 2;
return employee;
}
Employee类:


public class Employee
{
public string FirstName;


public string LastName;


public int Salary;


public string FullName
{
get
{
return this.FirstName + " " + this.LastName;
}
}
}
那么客户端的employee对象,因为与Employee的公开字段相同名字的Field,并且WebMethod的方法是Employee类,那么,调用WebMethod的方法的时候employee对象由客户端的Object类型转换为了Employee类型。那么返回值也与此类似,只不过转换方向反过来了。


容器对象:在WebService一方要返回一个集合或参数是一个集合,那么这个方法的返回值或参数必须实现了IList接口或IDictionary接口的对象。并且IDictionary对象的key必须是string类型,那么客户端的对象一定是Array类型。这样就能实现由客户端的Array类型到服务段的IList或IDictionary类型的互转


注:Array类型可以象IList接口是一个一维数组,也可以是类似与IDictionary是一个带有key的二位数组



error.get_timedOut()
error.get_message()
error.get_exceptionType()
error.get_stackTrace()
生成的WebService代理存在一个set_timeout()方法,用来设置调用WebService的超时时间。PageMethod不存在这个方法。


4、负责类型的使用


公有属性或公有Field会被释放和接受。这句话的意思就是如果通过客户端传递过来的对象,这个对象的属性与WebService里方法参数所对应的类的公有属性或公有Field字段名相同,将自动转换为相应的对象。如以下代码


客户端:


function doubleSalary()
{
var employee = new Object();
employee.FirstName = "Jeffrey";
employee.LastName = "Zhao";
employee.Salary = 1000;
ComplexType.DoubleSalary(employee, doubleSalarySucceeded);
}


WebMethod(arg1, …, argN, onSucceeded, onFailed,userContext)
onSucceeded:执行成功调用的回调函数地址


onSucceeded(result, userContext, methodName)
onSucceeded的三个参数:result函数的返回值,userContext是有调用WebMethod的userContext,可以将一些附加信息传递到onSucceeded函数,methodName调用成功回调函数的的WebMethod的函数名。


onFailed:执行失败/超时的回调函数地址


onFailed(result, userContext, methodName)
onFailed的三个参数:result是error对象,后面两个参数与onSucceeded的两个参数相同。


userContext:由用户指定要传给回调函数的附加信息


WebService方法生成的代理方法最后三个参数可以通过以下几个方法


WebService.set_defaultUserContext(information)
WebService.set_defaultSucceededCallback(functionName)
WebService.set_defaultFailedCallback(functionName)







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.