0
votes

I have a WCF service code like this:

[ServiceContract]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, 
    ConcurrencyMode = ConcurrencyMode.Multiple)]
public class SomeService
{
    public string Password { [OperationContract] get; [OperationContract] set; }

    public void CheckPassword()
    {
        if (Password == null || Password != "password")
            throw new FaultException("Invalid Password");
    }

    [OperationContract] 
    public string SomeMethod()
    {
        this.CheckPassword();

        return "Some Data";
    }
}

And the client windows application consumes it like this:

public class ClientClass
{
    public ClientClass()
    {
        STASomeService.Value.SomeMethod();
    }
}
public class ClientClass
{
    public ClientClass()
    {
        STASomeService.Value.set_Password("password");
    }
}

How can I reset the value of SomeService.Password whenever the SomeService class is instantiated? I do not want an attacker to access my service methods, but when the actual client set the password, the passwords stays in the SomeService.Password property in every service call. But I want to retain the Password value per instance because the client needs that.

My code is in C#, framework 4, build in VS2010 Pro.

Please help. Thanks in advance.

1

1 Answers

1
votes

You shouldn't have to reset the value of SomeService.Password because it isn't static. Are you seeing something to the contrary?


Since you're using InstanceContextMode.Single (which I originally overlooked), your best recourse my be to mock the behavior of having individual instances in your network bound singleton. The only way I can think of to facilitate this is to have a proxy service class that matches your service's contracts and delegates its calls to custom instances based on specific criteria (which would define the session). It would be cumbersome to maintain this way and adds a unnecessary level of abstraction, but (in my head at least) it should work