public class WebServiceT1 : System.Web.Services.WebService

{
public WebServiceT1()
{
}
[WebMethod]
public string TestMethod(string msg)
{
System.Threading.Thread.Sleep(1000 * 60 * 21);
return "the webService got it:"+msg;
}
}
2:创建一个aspx页面
<atlas:ScriptManager ID="ScriptManager1" runat="server" EnableScriptComponents='false'>
<Services>
<atlas:ServiceReference Path='WebServiceT1.asmx' />
</Services>
</atlas:ScriptManager>
<input id="Button1" type="button" value="click me and will invoke the webservice" onclick="return Button1_onclick()" />
<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>
function Button1_onclick()
{
WebServiceT1.TestMethod(document.getElementById('TextBox1').value,OnComplet,OnTimeOut);//异步调用,传递两个事件的回调函数:完成之后;超时
return true;
}
function OnComplet(result)

{
//得到返回值.这个result是个objext类型的,可以传递一个类的实例过去,比如DataTable。
window.alert(result);
}
function OnTimeOut(result)

{
//居然也有返回值,不知道是什么
window.alert('time out. got nothing from the server');
window.alert(result);
}运行测试之就可以了。
几个问题:
1:传递的类型可以是复杂类型,除了string之类也可以一个类的实例。返回值也是。
可以这样使用:result.Name=xx。详细的介绍会在以后的“atlas数据邦定”中有。
2:好像WebService的方法必须得有一个参数。
3:也可以没有OnTimeOut处理。