VS2008 Web开发笔记 - Ajax 客户端编程 (一)
2010-03-18 16:25
417 查看
序:
VS2008的新功能让我振奋。对VS2008的学习兴趣越来越大,今天开始我会循序渐进地学习VS2008的Web开发。因为本人的专长是开发B/S结
构应用开发。所以在这一系列中没有关于winFrom的内容,并且本人暂时也不对WPF做过多的研究(感觉它离实际应用还比较远,而且个人精力有限)。
在这一系列中将会设计的内容有 Asp.Net Ajax 编程(客户端,服务器端),LINQ,WCF和WF。在开始前请务必安装VS2008,目前只有英文版下载。否则后果本人不负责。
第一课:使用Asp.Net Ajax框架调用WebService
还是从经典的HelloWorld开始。新建工程后,在工程内添加一个WebService。
取消[System.Web.Script.Services.ScriptService] 行前的注释,这样该WS就能暴露给客户端Ajax Library访问。
再新建一个Aspx页面,在From中放入一个ScriptManager控件。
为ScriptManager 控件增加Service关联。从而可以直接访问WS并调用其中方法。
并且依靠VS2008中的自感应系统,在编辑JavaScript脚本时能非常迅速的帮您定位到WSHelloWorld类,并且找到你需要的方法。
<script. type="text/javascript">
function TransferWSHelloWord()
{
var CallBack=function(result)
{
$get("Text1").value=result.toString();
}
//这里实现调用WebService,通过VS2008强大的编辑器,你可以轻松看到HelloWorld方法需要的参数。
WSHellowWorld.HelloWorld(CallBack,OnFailed,OnTimeOut);
}
function OnFailed(result)
{
var msg=result.get_exceptionType() + "\r\n";
msg += result.get_message() + "\r\n";
msg += result.get_stackTrace();
alert(msg);
}
//超时处理
function OnTimeOut(result)
{
alert("Timeout :" + result);
}
</script>
VS2008的新功能让我振奋。对VS2008的学习兴趣越来越大,今天开始我会循序渐进地学习VS2008的Web开发。因为本人的专长是开发B/S结
构应用开发。所以在这一系列中没有关于winFrom的内容,并且本人暂时也不对WPF做过多的研究(感觉它离实际应用还比较远,而且个人精力有限)。
在这一系列中将会设计的内容有 Asp.Net Ajax 编程(客户端,服务器端),LINQ,WCF和WF。在开始前请务必安装VS2008,目前只有英文版下载。否则后果本人不负责。
第一课:使用Asp.Net Ajax框架调用WebService
还是从经典的HelloWorld开始。新建工程后,在工程内添加一个WebService。
using System; using System.Collections; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; using System.Xml.Linq; /// <summary> /// Summary description for WSHellowWorld /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService] public class WSHellowWorld : System.Web.Services.WebService { public WSHellowWorld() { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public string HelloWorld() { return "Hello World"; } } |
再新建一个Aspx页面,在From中放入一个ScriptManager控件。
<asp:ScriptManager ID="ScriptManager1" runat="server" > <Services> <asp:ServiceReference Path="~/WebService/WSHellowWorld.asmx"/> </Services> </asp:ScriptManager> |
并且依靠VS2008中的自感应系统,在编辑JavaScript脚本时能非常迅速的帮您定位到WSHelloWorld类,并且找到你需要的方法。
<script. type="text/javascript">
function TransferWSHelloWord()
{
var CallBack=function(result)
{
$get("Text1").value=result.toString();
}
//这里实现调用WebService,通过VS2008强大的编辑器,你可以轻松看到HelloWorld方法需要的参数。
WSHellowWorld.HelloWorld(CallBack,OnFailed,OnTimeOut);
}
function OnFailed(result)
{
var msg=result.get_exceptionType() + "\r\n";
msg += result.get_message() + "\r\n";
msg += result.get_stackTrace();
alert(msg);
}
//超时处理
function OnTimeOut(result)
{
alert("Timeout :" + result);
}
</script>
相关文章推荐
- web开发-javascript编程prototype、this、ajax、json、结构体和数组-学习笔记十四
- Asp.Net Ajax 学习笔记24 利用Microsoft AJAX Library开发客户端组件(中)
- 基于AJAX技术开发Web电子邮件客户端之 UI篇
- ASP.NET AJAX客户端编程之旅(四)——以组件的思想开发Ajax应用:客户端组件初探
- 开发笔记 - 客户端-Web端同步登录
- MS Ajax 客户端编程 学习笔记 (1)
- [python]网络编程基础学习笔记(二)Web客户端访问
- ArcGIS客户端开发学习笔记(一)——AJAX机制
- ASP.NET AJAX客户端编程之旅(四)——以组件的思想开发Ajax应用:客户端组件初探
- ASP.NET AJAX客户端编程之旅(五)——以组件的思想开发Ajax应用:行为、绑定及xml-script
- 笔记之 02_传智播客AJAX视频教程_使用IntelliJ开发Web项目
- 在vs2008中使用AJAX开发.net 2.0下的Web程序的方法
- android开发笔记之网络编程—简易新闻客户端
- ASP.NET AJAX客户端编程之旅(五)——以组件的思想开发Ajax应用:行为、绑定及xml-script
- ASP.NET AJAX客户端编程之旅(四)——以组件的思想开发Ajax应用:客户端组件初探
- ASP.NET AJAX客户端编程之旅(五)——以组件的思想开发Ajax应用:行为、绑定及xml-script
- ArcGIS客户端开发学习笔记(一)——AJAX机制
- Asp.Net Ajax 学习笔记25 利用Microsoft AJAX Library开发客户端组件(下)
- ASP.NET AJAX客户端编程之旅(四)——以组件的思想开发Ajax应用:客户端组件初探 收藏 在这里添加日志标题
- ASP.NET AJAX客户端编程之旅(四)——以组件的思想开发Ajax应用:客户端组件初探