Atlas笔记1:介绍和调用WebService的方法

Atlas是运行在Asp.net2.0环境下的一个项目,微软的AJAX项目。
Atlas主页 http://www.asp.net/default.aspx?tabindex=7&tabid=47

AJAX (Asynchronous JavaScript and XML),结合上.net2.0的功能效果自然非同凡响。网页的也不调用可以避免无谓的网页周期,使浏览速度大大加快,也可以减轻服务器的负荷;用户体验上,可以创建rich UI,制作富有表现力的网页不再那么麻烦。

安装atlas比较简单,只要有asp。net2.0,然后下在一个项目模版文件安装就可以了。

按照Atlas Quickstart Tutorials 的步骤,先开始第一个测试:异步调用WebService。

在atlas项目里面:

1:先创建一个简单的WebService
None.gif public   class  WebServiceT1 : System.Web.Services.WebService
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
InBlock.gif    
public WebServiceT1()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    [WebMethod]
InBlock.gif    
public string TestMethod(string msg)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        System.Threading.Thread.Sleep(
1000 * 60 * 21);
InBlock.gif        
return "the webService got it:"+msg;
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedBlockEnd.gif}

None.gif

 

2:创建一个aspx页面


      首先在页面上添加一个atlas引用:
      注意里面要引用上WebService的地址。幸好2.0里面的代码自动完成功能作的比较多,不噢能够自己写太多代码,输入几个字母就有提示了。
None.gif < atlas:ScriptManager ID = " ScriptManager1 "  runat = " server "  EnableScriptComponents = ' false ' >
None.gif                
< Services >
None.gif                    
< atlas:ServiceReference Path = ' WebServiceT1.asmx '   />
None.gif                
</ Services >
None.gif            
</ atlas:ScriptManager >

然后再页面上加上两个html控件:一个按钮一个文本框。双击文本框,他会自动给创建一个client端的事件,自动创建一个js函数
None.gif
None.gif                
< input id = " Button1 "  type = " button "  value = " click me and will invoke the webservice "  onclick = " return Button1_onclick() "   />
None.gif                
< asp:TextBox ID = " TextBox1 "  runat = " server "  OnTextChanged = " TextBox1_TextChanged " ></ asp:TextBox >

js函数
None.gif
None.giffunction Button1_onclick()
ExpandedBlockStart.gifContractedBlock.gif 
dot.gif {
InBlock.gif   WebServiceT1.TestMethod(document.getElementById(
'TextBox1').value,OnComplet,OnTimeOut);//异步调用,传递两个事件的回调函数:完成之后;超时
InBlock.gif
   
InBlock.gif   
return true;
ExpandedBlockEnd.gif}

None.giffunction OnComplet(result)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
//得到返回值.这个result是个objext类型的,可以传递一个类的实例过去,比如DataTable。
InBlock.gif
  window.alert(result);
ExpandedBlockEnd.gif}

None.giffunction OnTimeOut(result)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
//居然也有返回值,不知道是什么
InBlock.gif
  window.alert('time out. got nothing from the server');
InBlock.gif  window.alert(result);
ExpandedBlockEnd.gif}

运行测试之就可以了。

几个问题:
1:传递的类型可以是复杂类型,除了string之类也可以一个类的实例。返回值也是。
      可以这样使用:result.Name=xx。详细的介绍会在以后的“atlas数据邦定”中有。
2:好像WebService的方法必须得有一个参数。
3:也可以没有OnTimeOut处理。

转载于:https://www.cnblogs.com/raymond19840709/archive/2006/10/12/526818.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值