简体   繁体   中英

Using public property between web service methods

I want to define a property in asmx web service that shared between all web methods. this is my question:

Code:

myWS test1 = new myWS();
test1.SetToken(UserID1);
test1.AnotherMethod();


//stuff...

myWS test2 = new myWS();
test2.SetToken(UserID2);
test2.AnotherMethod();

Webservice:

[WebService(Namespace = "http://test.ir/")]
public class myWS : System.Web.Services.WebService
{
    public string Token { get; set; }

    Public void SetToken(int UserID){
      this.Token= BLL.GetToken(UserID);
    }

    Public void AnotherMethod(){
      BLL.CheckToken(Token);//i want token value be per every myWS web service defined
    }
 }

notes: * static property is not good,because is share between all users,i want token value be unique in every myWS test = new myWS()

thanks.

Edits:

My app runs on a pc in every user start up and all instance call my web service

I found that any instance of web service is unique. we resolved this by sending param to our methods,associate that to a public property and use in other methods of that instance of web service.

Webservice: [WebService(Namespace = " http://test.ir/ ")]

public class myWS : System.Web.Services.WebService
{
    public string Token { get; set; }

    Public void SetToken(string myToken){
      this.Token= myToken;
    }

    Public void Method1(){
      BLL.CheckToken1(Token);
    }

    Public void Method2(){
      BLL.CheckToken2(Token);
    }
 }

call:

myWS test1 = new myWS();
test1.SetToken("abc");
test1.Method1();
test1.Method2();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM