我的Web服務被稱爲ASMX的WebMethod調用不保留變量值
public class Service : System.Web.Services.WebService
{
public Service() {
//Uncomment the following line if using designed components
//InitializeComponent();
}
private string password;
[WebMethod]
public void SetPassword(string pPassword)
{
password = pPassword;
}
private bool ValidPassword()
{
return (password == ConfigurationManager.AppSettings["Token"].ToString());
}
[WebMethod]
public DataSet GetAccountInfo(string account)
{
ValidPassword();
//logic here
}
的網頁做
Dim mySvc As New RNX.Service
mySvc.SetPassword("passwordhere")
Dim dsAcctInfo As DataSet = mySvc.GetAccountInfo(strAcct)
兩種方法都執行就好了電話... SetPassword完成,然後使用同一個Web服務對象,調用者然後運行GetAccountInfo,它檢查它是否是ValidPassword()。
但是,在這個時候,變量再次爲空......如在,不保留該值。
ASMX是一種過時的技術,並且不應該被用於新的開發。 WCF應該用於Web服務客戶端和服務器的所有新開發。一個暗示:微軟已經在MSDN上退役了[ASMX Forum](http://social.msdn.microsoft.com/Forums/en-US/asmxandxml/threads)。 –