我開始學習web服務,我順利地到this topic。如果你能在這裏看到的是代碼click事件創建proxy
和存儲Cookie會出現:需要一些關於web服務的幫助
protected void Button1_Click(object sender, EventArgs e)
{
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 />";
}
我很困惑在行MyService = Session["MyService"] as localhost.MyDemo;
。
雖然我知道as
用於鑄造,我想在這裏它做相同的,但
問題1:爲Session
和localhost.MyDemo
是兩個不同的對象鑄因此如何是可能的?
問題2:是as
是不是在做鑄造,那麼這條線意味着什麼?
問題3:爲什麼需要施放?
問題4:什麼值Session["MyService"]
將有?
請幫我理解這一點。
本文將幫助您理解:http://msdn.microsoft.com/en-us/library/ms173105.aspx – ohlmar
您已經在ASMX Web服務上找到了一箇舊教程。 ASMX是一項傳統技術,不應該用於新開發。 WCF或ASP.NET Web API應該用於Web服務客戶端和服務器的所有新開發。一個暗示:微軟已經在MSDN上退役了[ASMX Forum](http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/threads)。 –
是啊@JohnSaunders。我只是想在學習'Web服務'之後'WCF'會更容易。感謝您的好建議。 – SMI