AJAX学习之Atlas框架之建立基本的程序

来源:互联网 发布:java在线客服源码 编辑:程序博客网 时间:2024/04/30 02:49
AJAX学习之Atlas框架之建立基本的程序
取消
作者天涯路远 发表于 2006-05-16 21:06
标题:AJAX学习之Atlas框架之建立基本的程序
做人要厚道,转载请说明出处
天涯路远 http://www.flysblog.com
例子代码下载:下载文件 点击下载此例子项目代码

这个例子将象我们展示ATLAS的最基本框架和应用.Say Hello to ATLAS.
当然要建立一个ATLAS程序,你要先装一些预备的东西
1.Microsoft Visual Studio 2005 and the .NET Framework version 2.0.
2."Atlas"程序安装包.具体的程序包去http://atlas.asp.net下载.
一 . 建立ASP.NET 'Atlas' 网站程序
1.打开 文件 - 新建 - 网站 菜单
2.在新建网站的对话框中选择ASP.NET 'Atlas' 网站模板.
3.在 位置 选择文件系统并选择你要用的一种编程语言
4.单击确定后系统将帮你自动生成一个ASP.NET 'Atlas' 网站
二.新建一个Web Service 方法
1.在解决方案资源管理器中右击上个步骤建立的网站名在弹出的菜单中选择添加一个新项..
2.在打开的添加新项对话框中,选杂一个Web Service
3.填写你要建立的Web Service 的名字最后点添加按钮
4.在新建的代码文件中输入
程序代码 程序代码
<%@ WebService Language="C#" Class="Samples.AspNet.HelloWorldService" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

namespace Samples.AspNet {

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class HelloWorldService : System.Web.Services.WebService {

[WebMethod]
public string HelloWorld(String query)
{
string inputString = Server.HtmlEncode(query);
if(!String.IsNullOrEmpty(inputString))
{
return String.Format("Hello, you queried for {0}. The "
+ "current time is {1}", inputString, DateTime.Now);
}
else
{
return "The query string was null or empty";
}
}
}
}


三.新建一个调用这个WebMethod的网页
在新建的页面上输入下面这段代码
程序代码 程序代码

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

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="Head1" runat="server">
<atlas:ScriptManager runat="server" ID="scriptManager">
<services>
<atlas:servicereference path="~/HelloWorldService.asmx" />
</services>
</atlas:ScriptManager>
<style type="text/css">
body { font: 11pt Trebuchet MS;
font-color: #000000;
padding-top: 72px;
text-align: center }

.text { font: 8pt Trebuchet MS }
</style>
<script type="text/javascript">

function DoSearch()
{
var SrchElem = document.getElementById("SearchKey");
Samples.AspNet.HelloWorldService.HelloWorld(SrchElem.value, OnRequestComplete);
}

function OnRequestComplete(result)
{
var RsltElem = document.getElementById("Results");
RsltElem.innerHTML = result;
}

</script>
</head>
<body>
<form runat="server">
<div>
Search for
<input id="SearchKey" type="text" />
<input id="SearchButton" type="button" value="Search"
onclick="DoSearch()" />
</div>
</form>
<hr style="width: 300px" />
<div>
<span id="Results"></span>
</div> </body>
</html>




到此一个简单的Say Hello,World程序已经建好。你可以运行整个程序.

四.总结
通过这个程序的建立,我们可以知道整个ATLAS程序的大概流程.当新建这个ATLAS的程序其实VS编程环境已经在背后为我们写了好多的代码.好好的研究这些代码可以使我们对ATLAS的理解更深一步.
这篇文章是ATLAS的学习文章,原文地址是:http://atlas.asp.net/docs/Walkthroughs/GetStarted/Basic.aspx 我只是简单的翻译了一下.当中带了好多我自己的理解.HOHO...