文档介绍:WCF 简单示例程序(源码下载)
本示例程序演示如何编写一个简单的WCF 示例程序。
如何使用WCF 示例代码:
Server 端:Console 程序,WCF Service 承载在Console 程序中。
WCF 简单示例程序(源码下载)
本示例程序演示如何编写一个简单的WCF 示例程序。
如何使用WCF 示例代码:
Server 端:Console 程序,WCF Service 承载在Console 程序中。
[ServiceContract(Namespace = "")]
public interface IBankService
{
[OperationContract]
int AddAccount(string clientName, int clientAge);
[OperationContract]
bool RemoveAccount(int accountNumber);
[OperationContract]
List<String> GetAccounts();
}
class BankService: IBankService
{
private List<Account> _accounts = new List<Account>();
private int _idGenerator = 0;
public int AddAccount(string clientName, int clientAge)
{
();
_idGenerator++;
Account acc = new Account(_idGenerator, clientName, clientAge);
(acc);
("ADD - " + ());
return _idGenerator;
}
......
Client 端: 也是一个Console 程序,负责调用/测试 WCF Services。
using (ChannelFactory<IBankService> bankFactory =
new ChannelFactory<IBankService>("MyClient"))
{
IBankService bankProxy = ();