mojoPortal 项目中使用Joyrock和MagicAjaxNET,他没有使用Asp.net ajax ,是因为mojoPortal是一个运行在Windows的 .net framework或Linux,Mac OS的Mono平台上的cms系统,asp.net ajax 的协议决定了它不能应用于mono上。Joyrock的具体应用可以去看
mojoPortal 的最新版本的代码。
Joyrock是一个LGPL的开源的软件,实现了JSON和JSON-RPC,支持微软ASP.NET框架。
Joyrock是一个LGPL的开源的软件,实现了JSON和JSON-RPC,支持微软ASP.NET框架。
看看服务器端的写法:
<%@ WebHandler Class="JayrockWeb.HelloWorld" %>
<%@ WebHandler Class="JayrockWeb.HelloWorld" %>
namespace JayrockWeb
{
using System;
using System.Web;
using Jayrock.Json;
using Jayrock.JsonRpc;
using Jayrock.JsonRpc.Web;
{
using System;
using System.Web;
using Jayrock.Json;
using Jayrock.JsonRpc;
using Jayrock.JsonRpc.Web;
public class HelloWorld : JsonRpcHandler
{
[ JsonRpcMethod("greetings") ]
public string Greetings()
{
return "Welcome to Jayrock!";
}
}
}
[ JsonRpcMethod("greetings") ]恰好对应于ASP.NET 的[WebMethod],深入理解一下就知道,这两个自定义属性就是起到标记作用,用来声明方法是可以远程调用的。
{
[ JsonRpcMethod("greetings") ]
public string Greetings()
{
return "Welcome to Jayrock!";
}
}
}
[ JsonRpcMethod("greetings") ]恰好对应于ASP.NET 的[WebMethod],深入理解一下就知道,这两个自定义属性就是起到标记作用,用来声明方法是可以远程调用的。
客户端调用:
" [url]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/url]">
[url]http://www.w3.org/1999/xhtml[/url]" lang="en" xml:lang="en">
Hello Jayrock
" [url]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/url]">
[url]http://www.w3.org/1999/xhtml[/url]" lang="en" xml:lang="en">
This page tests the HelloWorld service with Jayrock.
可以看到helloworld.ashx?proxy指向了一个JS文件,他的内容就是:
// This JavaScript was automatically generated by
// Jayrock.Json.Rpc.Web.JsonRpcProxyGenerator, Jayrock, Version=0.9.7507.0, Culture=neutral, PublicKeyToken=null
// on 2006年12月5日 at 8:46:27 (中国标准时间)
// This JavaScript was automatically generated by
// Jayrock.Json.Rpc.Web.JsonRpcProxyGenerator, Jayrock, Version=0.9.7507.0, Culture=neutral, PublicKeyToken=null
// on 2006年12月5日 at 8:46:27 (中国标准时间)
// Proxy version 1.0
function HelloWorld(url)
{
/* Returns a summary about the JSON-RPC server implementation for display purposes. */
this["system.about"] = function(callback)
{
return call("system.about", [ ], callback);
}
/* Returns the version JSON-RPC server implementation using the major, minor, build and revision format. */
this["system.version"] = function(callback)
{
return call("system.version", [ ], callback);
}
/* Returns an array of method names implemented by this service. */
this["system.listMethods"] = function(callback)
{
return call("system.listMethods", [ ], callback);
}
this["greetings"] = function(callback)
{
return call("greetings", [ ], callback);
}
var url = typeof(url) === 'string' ? url : 'http://localhost:3409/Web/HelloWorld.ashx';
var self = this;
var nextId = 0;
{
/* Returns a summary about the JSON-RPC server implementation for display purposes. */
this["system.about"] = function(callback)
{
return call("system.about", [ ], callback);
}
/* Returns the version JSON-RPC server implementation using the major, minor, build and revision format. */
this["system.version"] = function(callback)
{
return call("system.version", [ ], callback);
}
/* Returns an array of method names implemented by this service. */
this["system.listMethods"] = function(callback)
{
return call("system.listMethods", [ ], callback);
}
this["greetings"] = function(callback)
{
return call("greetings", [ ], callback);
}
var url = typeof(url) === 'string' ? url : 'http://localhost:3409/Web/HelloWorld.ashx';
var self = this;
var nextId = 0;
function call(method, params, callback)
{
var request = { id : nextId++, method : method, params : params };
return callback == null ?
callSync(method, request) : callAsync(method, request, callback);
}
{
var request = { id : nextId++, method : method, params : params };
return callback == null ?
callSync(method, request) : callAsync(method, request, callback);
}
function callSync(method, request)
{
var http = newHTTP();
http.open('POST', url, false, self.httpUserName, self.httpPassword);
setupHeaders(http, method);
http.send(JSON.stringify(request));
if (http.status != 200)
throw { message : http.status + ' ' + http.statusText, toString : function() { return message; } };
var response = JSON.eval(http.responseText);
if (response.error != null) throw response.error;
return response.result;
}
{
var http = newHTTP();
http.open('POST', url, false, self.httpUserName, self.httpPassword);
setupHeaders(http, method);
http.send(JSON.stringify(request));
if (http.status != 200)
throw { message : http.status + ' ' + http.statusText, toString : function() { return message; } };
var response = JSON.eval(http.responseText);
if (response.error != null) throw response.error;
return response.result;
}
function callAsync(method, request, callback)
{
var http = newHTTP();
http.open('POST', url, true, self.httpUserName, self.httpPassword);
setupHeaders(http, method);
http.onreadystatechange = function() { http_onreadystatechange(http, callback); }
http.send(JSON.stringify(request));
return request.id;
}
{
var http = newHTTP();
http.open('POST', url, true, self.httpUserName, self.httpPassword);
setupHeaders(http, method);
http.onreadystatechange = function() { http_onreadystatechange(http, callback); }
http.send(JSON.stringify(request));
return request.id;
}
function setupHeaders(http, method)
{
http.setRequestHeader('Content-Type', 'text/plain; charset=utf-8');
http.setRequestHeader('X-JSON-RPC', method);
}
{
http.setRequestHeader('Content-Type', 'text/plain; charset=utf-8');
http.setRequestHeader('X-JSON-RPC', method);
}
function http_onreadystatechange(sender, callback)
{
if (sender.readyState == /* complete */ 4)
{
var response = sender.status == 200 ?
JSON.eval(sender.responseText) : {};
response.xmlHTTP = sender;
callback(response);
}
}
{
if (sender.readyState == /* complete */ 4)
{
var response = sender.status == 200 ?
JSON.eval(sender.responseText) : {};
response.xmlHTTP = sender;
callback(response);
}
}
function newHTTP()
{
return typeof(ActiveXObject) === 'function' ?
new ActiveXObject('Microsoft.XMLHTTP') : /* IE 5 */
new XMLHttpRequest(); /* Safari 1.2, Mozilla 1.0/Firefox, and Netscape 7 */
}
}
{
return typeof(ActiveXObject) === 'function' ?
new ActiveXObject('Microsoft.XMLHTTP') : /* IE 5 */
new XMLHttpRequest(); /* Safari 1.2, Mozilla 1.0/Firefox, and Netscape 7 */
}
}
HelloWorld.rpcMethods = ["system.about","system.version","system.listMethods","greetings"];
上面JS文档是自动生成的,ASP.NET AJAX也有自动生成客户端访问对象的功能
Jayrock 远程方法要求写在一个ashx中,页面请求这个ashx的时候,在Proce***equest 中根据Request对象中的参数信息,确定请求的服务器端方法名称和参数,然后进行调用,并返回结果。
上面JS文档是自动生成的,ASP.NET AJAX也有自动生成客户端访问对象的功能
Jayrock 远程方法要求写在一个ashx中,页面请求这个ashx的时候,在Proce***equest 中根据Request对象中的参数信息,确定请求的服务器端方法名称和参数,然后进行调用,并返回结果。
自由、创新、研究、探索……
©著作权归作者所有:来自51CTO博客作者张善友的原创作品,如需转载,请注明出处,否则将追究法律责任
.NET 职场 休闲
开源项目
0
收藏
上一篇:RESTFul Web Serv... 下一篇:IBatisNetProvide...
推荐专栏更多

微服务技术架构和大数据治理实战
大数据时代的微服务之路
共18章 | 纯洁微笑
¥51.00 702人订阅
订 阅

基于Python的DevOps实战
自动化运维开发新概念
共20章 | 抚琴煮酒
¥51.00 551人订阅
订 阅
猜你喜欢
我的友情链接 mono-3.4.0 源码安装时出现的问题 [do-install] Error 2 [install-pcl-targets] Er JQuery ajax返回JSON时的处理方式 从零开始手写 dubbo rpc 框架 从零手动实现 java json 序列化框架 VS.Net 2005 中文正式版下载 “RPC服务不可用”的解决过程 Log4Net使用详解(续) 杂七杂八(1)——如何查看本机的.NET Framework版本 大型软件公司.net面试题!一定得看(附答案) NET USE 命令用法 docker深入2-linux下的配置文件daemon.json使用示例 C#/VB.NET 将SVG图片添加到PDF、转换为PDF 接口默认方法是什么鬼 ASPNetCore MVC ModelValidation-ajax C#如何设置Excel文档保护——工作簿、工作表、单元格 C# /VB.NET 操作Word (一)——插入、修改、删除Word批注 微信支付---APP调起微信支付c#后台接口 C# Word转PDF/HTML/XML/XPS/SVG/EMF/EPUB/TIFF Powershell如何在Start-Job的Scriptblock里传参?


扫一扫,领取大礼包

0
分享
张善友

Ctrl+Enter 发布
发布
取消