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

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s