Hướng dẫn xây dựng WCF Services

Tạo dự án mới, chọn WCF Server Application

cc

Tạo ServiceContract (Interface trong C#)

IbankService.cs

namespace WcfBankService

{

[ServiceContract]

public interface IBankService

{

[OperationContract]

bool Register(string accId, string name, float balance, string pin);

[OperationContract]

bool ValidateAccount(string accId, string pin);

[OperationContract]

bool WithDraw(string accId,float balance);

[OperationContract]

bool Deposit(string accId,float balance);

[OperationContract]

float ViewBalance(string accId);

}

}

Tạo BankService.cs implement IBankService

namespace WcfBankService

{

public class BankService : IBankService

{

public bool Register(string accId, string name, float balance, string pin)

{

//Viet code them mot hang account

return true;

}

public bool ValidateAccount(string accId, string pin)

{

//Login – Check ID & PIN

return true;

}

public bool WithDraw(string accId, float amount)

{

//Rut tien

//Update Accounts set Balance = Balance-amount

return true;

}

public bool Deposit(string accId, float amt)

{

//Bo tien vao

//Update Accounts set Balance = Balanece + amt

return true;

}

public float ViewBalance(string accId)

{

float balance = 0;

//Kiem tra so du cua tai khoan accit

return balance;

}

}

Giao diện các class sau khi hoàn thiện

21

 

 

Advertisements