0
我是WCF的初學者。我有兩個簡單的服務:添加客戶的名字和姓氏,並返回客戶端的數量。每當客戶添加時,當我測試服務給客戶端時,數量不增加總是一個。下面的代碼:WCF和客戶端代碼
class ClientService : IClientService
{
List<Client> list = new List<Client>();
public bool SubmitClient(Client client)
{
list.Add(client);
}
public int IClientService.GetClient()
{
return list.Count;
}
}
客戶端代碼:
protected void Button1_Click(object sender, EventArgs e)
{
ClientServiceClient channel = new ClientServiceClient();
Client cl = new Client();
cl.FirstName = txtFName.Text;
cl.LastName = txtLName.Text;
channel.SubmitClient(cl);
labbel1.Text=string.Format("Number of clients: {0}"),channel.GetClient());
}
默認實例上下文模式是PerCall意味着每次你做一個服務調用一個新的實例是在服務器中創建的,舊的狀態完全被遺忘了 – VJAI