在 Web 服务方法之间使用 public 属性

Using public property between web service methods

我想在所有 Web 方法之间共享的 asmx Web 服务中定义一个 属性。 这是我的问题:

代码:

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


//stuff...

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

网络服务:

[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
    }
 }

备注: * static 属性 不好,因为它在所有用户之间共享,我希望令牌值在每个 myWS 测试中都是唯一的 = new myWS()

谢谢。

编辑:

我的应用程序在每个用户启动时都在一台电脑上运行,并且所有实例都调用我的网络服务

我发现网络服务的任何实例都是唯一的。 我们通过向我们的方法发送参数来解决这个问题,将其关联到 public 属性 并在该 Web 服务实例的其他方法中使用。

网络服务: [WebService(命名空间 = "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);
    }
 }

通话:

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