2014-03-07 37 views
0

我在asp.net web服務的會話概念中遇到問題,如何在應用程序中實現?什麼是Web服務中的會話概念?以及如何實現

而且我已經在asp.net的eval一個問題,實際上有什麼用EVAL

<asp:ImageButton ID="imgbtnDelete" ImageUrl="~/cpanel/images/icons/table/actions-delete.png" 
     runat="server" CommandArgument='<%#Eval("JobID")%>' OnClick="imgbtnDelete_Click"> 
+2

請將您的問題分爲兩個單獨的問題。一個爲你的會議提出一個針對eval問題的問題。 – shenku

回答

1

Web服務通常運行在一個web應用,就像一個網站,讓你有機會獲得的所有相同的會話功能。

Session State Overue

可以使用存儲在會話數據:

Session["FirstName"] = "Peter"; 
Session["LastName"] = "Parker"; 

使用Retreive它:

ArrayList stockPicks = (ArrayList)Session["StockPicks"]; 
1
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

相關問題