用PageMethods进行Server和Client通信
来源:互联网 发布:蚂蜂窝 知乎 编辑:程序博客网 时间:2024/05/12 23:23
WebService and PageMethods的应用
想要使用ASP.NET AJAX在客户端JavaScript中异步调用服务器端Web Service,我们需要:
1 为Web Service类或需要暴露给客户端的Web Service方法添加[ScriptService]
属性;
2 为Web Service中需要暴露给客户端的方法添加[WebMethod]属性;
3 在页面中的ScriptManager控件中添加对该Web Service的引用;
4 在客户端使用如下JavaScript语法调用该Web Service:
[NameSpace].[ClassName].[MethodName](param1, param2,..., callbackFunction)
5 为客户端异步调用指定回调函数,在回调函数中接收返回值并进一步处理。
-----------------------
想要使用ASP.NET AJAX在客户端JavaScript中异步调用定义在ASP.NET页面中的方法,我们需要:
1 将该方法声明为公有(public);
2 将该方法声明为类方法(C#中的static,VB.NET中的Shared),而不是实例方法;
3 为该方法添加[WebMethod]属性;
4 将页面中ScriptManager控件的EnablePageMethods属性设置为true;
5 在客户端使用如下JavaScript语法调用该页面方法:
PageMethods.[MethodName](param1, param2,..., callbackFunction);
6 为客户端异步调用指定回调函数,在回调函数中接收返回值并进一步处理。
PageMethods Simple:
Server
[WebMethod]
public static void AddRootCauseGroup(string groupId,string description)
{
try
{
string alertMsg="操作不合法:"+groupId+"已存在!";
bool RecrodExist = CheckRecordExist.checkRecordExist("groupid", "rootcause_group", "groupid",groupId);
if (!RecrodExist)
{
RootCauseGroup.insertRootCauseGroup(groupId, siteId, description, userIndex, userIndex);
}
else
{
MessageBox.Show(alertMsg);
}
}
catch (Exception ee)
{
throw ee;
}
}
Client
function ButtonOk_onclick()
{
var groupId=window.document .getElementById("TextBoxRootGroupId").value;
var description=window.document .getElementById("TextBoxDescription").value;
PageMethods.AddRootCauseGroup(groupId,description);
returnValue1();
}
- 用PageMethods进行Server和Client通信
- 用XMLRPC开服务进行server/client通信
- 最简单client和server通信程序
- spice client 和 spice server 通信机制
- spice client 和 spice server 通信机制
- http client和server 通信示例
- spice client 和 spice server 通信机制
- UDP通信client端和server端
- messenger,client和server通信Demo
- 网络通信(Server和Client)
- 实现Server和client端的通信
- 网络代理服务Agent,服务端.client 连接server 进行通信
- server 和client通信(asp.net和Javascript)
- 用消息队列实现Client和Server间的通信方案
- marsing linux下socket通信,server和client简单例子
- linux下socket通信,server和client简单例子
- linux下socket通信,server和client简单例子
- linux下socket通信,server和client例子
- C#授权组件设计 - LicenseControlProject
- 遭遇svchoct.exe,vonine.exe,HBKernel32.sys,ssdtti.sys,System.exe,ublhbztl.sys等1
- js_dom
- 捕获winform 中 datagridview 中的单击选中事件
- Netstat
- 用PageMethods进行Server和Client通信
- SaaS遇上云计算:危险的三角关系
- 一些检索英文文献的网址(收藏)
- ORACLE 中ROWNUM用法总结
- Windows 2008之IIS 7下PHP部署攻略
- Oracle 表相关DDL
- 首条OLED生产线昆山投产 打破日韩垄断
- SilverLight 2 初体验
- 软件买方市场特点凸显 企业发展受困同质化