ASP.NET ATLAS 的一个简单例子

本文介绍如何使用ATLAS简化Ajax和WebService的开发过程。通过一个示例项目详细展示了创建WebService和利用ATLAS进行异步调用的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ATLAS是MS一个新的项目,封装了Ajex 和Web Service的使用,透过简单的方法就可以实现用普通技术实现起来较为复杂的效果。

通过http://atlas.asp.net上的连接下载安装后,打开VS2005,建立一个Web Project。在这个Project中建立一个Web Service(HelloWorldSerice.asmx)如下:

<%

 

@ 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

{

 

}

}

}

}

再建立AtlasScript.aspx,不用CodeBehind。内容如下:

<!

 

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>

 

 

</head>

 

<body>

 

<form id="Form1" runat="server">

 

<div>

Search for

 

<input id="SearchKey" type="text" />

 

<input id="SearchButton" type="button" value="Search"

 

onclick="DoSearch()" />

 

</div>

 

<script type="text/javascript">

 

 

{

 

Samples.AspNet.HelloWorldService.HelloWorld(SrchElem.value,

OnRequestComplete);

}

 

 

{

 

RsltElem.innerHTML = result;

}

 

 

function DoSearch()var SrchElem = document.getElementById("SearchKey");function OnRequestComplete(result)var RsltElem = document.getElementById("Results");</script>

 

</form>

 

<hr style="width: 300px" />

 

<div>

 

<span id="Results"></span>

 

</

使用F5编译运行通过。

</div> </body>html>
return "The query string was null or empty" ;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值