public class MyDemo : System.Web.Services.WebService
{
[WebMethod (EnableSession = true)]
public string HelloWorld()
{
// get the Count out of Session State
int? Count = (int?)Session["Count"];
if (Count == null)
Count = 0;
// increment and store the count
Count++;
Session["Count"] = Count;
return "Hello World - Call Number: " + Count.ToString();
}
}
[的WebMethod(EnableSession =真)] - 這屬性啓用Web服務中的會話
從客戶端針對應用上的按鈕單擊事件,我們不得不寫這篇訪問Web服務
localhost.MyDemo MyService;
// try to get the proxy from Session state
MyService = Session["MyService"] as localhost.MyDemo;
if (MyService == null)
{
// create the proxy
MyService = new localhost.MyDemo();
// create a container for the SessionID cookie
MyService.CookieContainer = new CookieContainer();
// store it in Session for next usage
Session["MyService"] = MyService;
}
// call the Web Service function
Label1.Text += MyService.HelloWorld() + "<br />";
}
輸出將是: - 的Hello World - 呼叫號碼:1 的Hello World - 電話號碼:2 Hello World - 致電編號:3
請將您的問題分爲兩個單獨的問題。一個爲你的會議提出一個針對eval問題的問題。 – shenku