クライアントのプロパティを使用したいサービスがあります。
[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
いない場合、両方ともnullになることです。