学习asp.net ajax(四)(从客户端访问WebService)

服务器端释放WebService方法

名词解释

Ajax技术:异步刷新(javascript)

Ajax.Net:基于asp.net框架是一个ajax框架(不是微软体统的框架)

Asp.net Ajax: 微软提供的框架

 

编写一个普通的Asp.net webservice

为WebSrvice类添加自定义属性标记

 -ScriptServiceAttribute

释放WebService方法

- 访问级别为public

-使用WeMethidAttribute

为页面中ScriptManager(Proxy)引入asmx文件

 

客户端访问WebService

[Namespaces.]ClassName.MethodName

 依次传入参数

 传入一个方法作为成功后的回调函数

 即使没有返回值也会调用回调函数

  InlineScript=false 将会调用代理

 页面的代码

Code

对应的的Webservice

Code

客户端访问PageMethod

服务器端

只能在aspx页面中定义

只能那个是公开静态方法

使用WebMethodAttribute标记

ScriptManager的EnablePageMethods属性设置为true

客户端

通过PageMethods.MethodName 访问

 

//得到国际标准时间

DateTime.UtcNow

对应代码2

Code

Code

错误处理

调用时可以提供一个额外的错误回调函数

包括超时和服务器抛出的异常

超时智能设置在WebService对象上

   设置在PageMethods对象上

   无法在每个MethodCall时指定

Sys.Net.WebServiceError

 

复杂数据类型基础

公有属性或公有Field会被释放和接受

 

容器对象

   实现IList接口的对象

   实现IDictionary接口的对象

     Key必须是String

Code

客户端代理使用细节

函数调用完整性

Invoke(ar1,…,argN,onSucceded,onFailed,userContext)

回调函数完整性

 onSucceeded(result,userContext,methodName)

 onFailed(result,userContext,methodName)

WebService级别默认属性

-timeout

-defaultUserContext

-defaultSucceededCallback

-defaultFailedCallback

posted @ 2009-10-24 11:54  胡佳180815  阅读(943)  评论(0编辑  收藏  举报