我以一个最简单的helloworld为例,演示AJax.net源码中调用后台服务的机制,只是列出一些大体的框架,具体细节我还在研究中:)
不当之处,欢迎指正。

我先把例子中的核心代码列出,方便大家阅读。
HelloWorldService服务中:
微软AJax.net源码初步分析(2)--服务执行流程    [WebMethod(EnableSession = true)]
微软AJax.net源码初步分析(2)--服务执行流程    
public string HelloWorld(string name)
    }

HelloWorld.aspx文件:
微软AJax.net源码初步分析(2)--服务执行流程<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="HelloWorld.aspx.cs" Inherits="_Default" %>
微软AJax.net源码初步分析(2)--服务执行流程
微软AJax.net源码初步分析(2)--服务执行流程
<%@ Register Assembly="Microsoft.Web.Extensions" Namespace="Microsoft.Web.UI" TagPrefix="asp" %>
微软AJax.net源码初步分析(2)--服务执行流程
微软AJax.net源码初步分析(2)--服务执行流程
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
微软AJax.net源码初步分析(2)--服务执行流程
微软AJax.net源码初步分析(2)--服务执行流程
<html>
微软AJax.net源码初步分析(2)--服务执行流程
<head id="Head1" runat="server">
微软AJax.net源码初步分析(2)--服务执行流程    
<title>Hello</title>
微软AJax.net源码初步分析(2)--服务执行流程
微软AJax.net源码初步分析(2)--服务执行流程
<script type="text/javascript">
微软AJax.net源码初步分析(2)--服务执行流程    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.net源码初步分析(2)--服务执行流程        //取得AJax的客户端脚本名称
微软AJax.net源码初步分析(2)--服务执行流程
        private static string GetFullName(string name, System.Reflection.Assembly assembly)
        }
微软AJax.net源码初步分析(2)--服务执行流程        //取得dll中js文件的位置
微软AJax.net源码初步分析(2)--服务执行流程
        string IClientScriptManager.GetWebResourceUrl(Type type, string resourceName)
        }
微软AJax.net源码初步分析(2)--服务执行流程        //注册服务
微软AJax.net源码初步分析(2)--服务执行流程        
//取得页面上有哪些服务,如上面的HelloWorldService.asmx服务,然后调用如下语句
微软AJax.net源码初步分析(2)--服务执行流程
        this._clientScriptManager.RegisterClientScriptInclude(type, "HelloWorldService.asmx/jsdebug""HelloWorldService.asmx/jsdebug");
微软AJax.net源码初步分析(2)--服务执行流程
以上主要是使用.net 2.0新增的 微软AJax.net源码初步分析(2)--服务执行流程            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
相关资源
相似解决方案