我有一个服务,我想使用我客户的属性:
[ServiceContract]
public interface IMyAPI
{
string UserName { [OperationContract] get; [OperationContract] set; }
string Password { [OperationContract] get; [OperationContract] set; }
[OperationContract]
bool StockQuery(string partNo);
}
public class MyAPI : IMyAPI
{
public string UserName { get; set; }
public string Password { get; set; }
private void CheckSecurity()
{
if(this.UserName != "test" && this.Password != "123")
{
throw new UnauthorizedAccessException("Unauthorised");
}
}
public bool StockQuery(string partNo)
{
this.CheckSecurity();
if(partNo == "123456")
{
return true;
}
return false;
}
}
然后在我的客户上我这样做:
Testing.MyAPIClient client = new Testing.MyAPIClient();
client.set_UserName("test");
client.set_Password("123");
Console.WriteLine(client.StockQuery("123456"));
Console.ReadLine();
问题是,当我调试UserName
并且Password
没有被设置时,它们都是空的