Atlas 学习之006:Make Client-Side Network Callbacks with “Atlas”

  下面的文章将介绍:

  how Microsoft “Atlas” helps web developers make network callbacks directly from client-side script code.

  本文将学习以下内容:

  • how to create a simple web service that is “Atlas” enabled;
  • how to call this web service from client-side JavaScript code; 
  • how to use the data returned from the web service.

 

  详细步骤:

1、先见一个简单的web service,只将HelloWorld方法小改如下:

 [WebMethod]
    public string HelloWorld(String ss)
    {
        return "Hello " + ss;
    }

 

2、 在“源”页面里,把代码“<atlas:ScriptManager ID="ScriptManager1" runat="server" / >”修改成如下代码:

<atlas:ScriptManager ID="ScriptManager1" runat="server" >
            <Services>
                <atlas:ServiceReference Path="WebService.asmx" />
            </Services>
        </atlas:ScriptManager>

 

3、在“设计”页面里从“ HTML  ” 选项卡里拖拽一个“text”和“button”控件,双击“button”控件,切换到“源”页面,把代码“function Button1_onclick() {    }”修改成如下代码:

function Button1_onclick()
{
    abc = WebService.HelloWorld(document.getElementById('Text1').value,OnComplete,OnTimeOut);
    return false;
}

function OnComplete(result)
{
    alert(result);
}

function OnTimeOut(result)
{
    alert("超时!");
}

 

4、保存所有文件, F5运行一把,在“text”里输入任意字符,点击按钮,检验一下效果。

完整代码:

 

<% @ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"  %>

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >
< html  xmlns ="http://www.w3.org/1999/xhtml" >
< head  runat ="server" >
    
< title > Untitled Page </ title >
< script  language ="javascript"  type ="text/javascript" >
// <!CDATA[

function Button1_onclick() 
{
    abc 
= WebService.HelloWorld(document.getElementById('Text1').value,OnComplete,OnTimeOut);
    
return false;
}


function OnComplete(result)
{
    alert(result);
}


function OnTimeOut(result)
{
    alert(
"超时!");
}


// ]]>
</ script >
</ head >
< body >
    
< form  id ="form1"  runat ="server" >
        
< atlas:ScriptManager  ID ="ScriptManager1"  runat ="server"   >
        
< Services >
        
< atlas:ServiceReference   Path ="WebService.asmx"   />
        
        
</ Services >
        
</ atlas:ScriptManager >
        
< br  />
        请输入你的姓名:
        
< input  id ="Text1"  type ="text"   />
        
< input  id ="Button1"  type ="button"  value ="button"  onclick ="return Button1_onclick()"   /></ form >     
</ body >
</ html >
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值