我以一个最简单的helloworld为例,演示AJax.net源码中调用后台服务的机制,只是列出一些大体的框架,具体细节我还在研究中:)
不当之处,欢迎指正。
我先把例子中的核心代码列出,方便大家阅读。
HelloWorldService服务中:
[WebMethod(EnableSession = true)]
public string HelloWorld(string name)
}
HelloWorld.aspx文件:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HelloWorld.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="Microsoft.Web.Extensions" Namespace="Microsoft.Web.UI" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head id="Head1" runat="server">
<title>Hello</title>

<script type="text/javascript">
function SayHello()
后台调用机制分析:(都是Microsoft.Web.Extensions.dll反编译后看到的)
1、在AssemblyInfo.cs中声明了如下一些javascript脚本:
[assembly: System.Web.UI.WebResource("Microsoft.Web.Resources.Timer.bmp", "image/bmp")]
[assembly: System.Web.UI.WebResource("Microsoft.Web.Resources.Background.gif", "image/gif")]
[assembly: System.Web.UI.WebResource("Microsoft.Web.Resources.ScriptLibrary.MicrosoftAjaxWebForms.debug.js", "application/x-javascript")]
[assembly: System.Web.UI.WebResource("Microsoft.Web.Resources.ScriptLibrary.MicrosoftAjaxRuntime.debug.js", "application/x-javascript")]
[assembly: System.Web.UI.WebResource("Microsoft.Web.Resources.ScriptLibrary.MicrosoftAjax.debug.js", "application/x-javascript")]
[assembly: System.Web.UI.WebResource("Microsoft.Web.Resources.ScriptLibrary.MicrosoftAjaxWebForms.js", "application/x-javascript")]
[assembly: System.Web.UI.WebResource("Microsoft.Web.Resources.ScriptLibrary.MicrosoftAjaxRuntime.js", "application/x-javascript")]
[assembly: System.Web.UI.WebResource("Microsoft.Web.Resources.ScriptLibrary.MicrosoftAjax.js", "application/x-javascript")]
这些javascript脚本也都是作为资源包含在Microsoft.Web.Extensions.dll中的
2、在ScriptManager的OnPreRender中进行如下操作,进行js代码的注册(有的方法是调用其它类里面的):
//取得AJax的客户端脚本名称
private static string GetFullName(string name, System.Reflection.Assembly assembly)
}
//取得dll中js文件的位置
string IClientScriptManager.GetWebResourceUrl(Type type, string resourceName)
}
//注册服务
//取得页面上有哪些服务,如上面的HelloWorldService.asmx服务,然后调用如下语句
this._clientScriptManager.RegisterClientScriptInclude(type, "HelloWorldService.asmx/jsdebug", "HelloWorldService.asmx/jsdebug");
以上主要是使用.net 2.0新增的
public void ProcessRequest(HttpContext context)
context.Response.Write(text1);
相关文章:
-
2022-01-13
-
2022-12-23
-
2022-12-23
-
2021-12-15
-
2021-08-01
-
2021-11-05
-
2022-12-23
-
2022-12-23
猜你喜欢
-
2022-12-23
-
2022-01-07
-
2021-08-23
-
2022-01-03
-
2022-02-08
-
2022-12-23
-
2021-09-24
相关资源
-
下载
2023-02-04
-
下载
2023-01-30
-
下载
2022-12-03
-
下载
2021-06-06