隨著軟件運(yùn)行環(huán)境越來(lái)越復(fù)雜,webse州ce為分布式應(yīng)用、跨平臺(tái)交互、軟件間的整合提供了一種解決方案。思路就是用ajax定時(shí)查看有無(wú)新內(nèi)容,如果有的用一個(gè)定時(shí)器讓文字閃動(dòng)(通過(guò)變化文件的color實(shí)現(xiàn)),如果沒(méi)有就關(guān)閉定時(shí)器,恢復(fù)文字的顏色。里郵件的獲取用到了exchange的web service 結(jié)合jquery和一般處理程序ashx的ajax。
現(xiàn)在開(kāi)始演示一個(gè)實(shí)例,開(kāi)發(fā)工具如下為:Visual studio S 2008+jQuery1.4.1
1.新建一項(xiàng)目:MyService
2.Web service后臺(tái)代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace MyService
{
///
/// Summary description for Service1
///
[WebService]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]//此處需要設(shè)定為ScriptService類(lèi)型,js才能夠從web service取得值
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string GetMessage(string name)
{
return "Hello,"+name;
}
[WebMethod]
public List GetMembers() {
List personList = new List();
personList.Add("AGAN");
personList.Add("MS");
personList.Add("ZURI");
personList.Add("JILI");
personList.Add("Who are you!");
return personList;
}
[WebMethod]
public string GetYourAge(string name) {
int age = 0;
switch(name.ToUpper()){
case "AGAN":
age = 18;
break;
case "MS":
age = 28;
break;
case "ZURI":
age = 25;
break;
case "JILI":
age = 23;
break;
default:
age = 30;
break;
}
return age.ToString();
}
}
}