【发布时间】:2015-02-22 19:12:05
【问题描述】:
我在 wshttpbinding 中使用 InstanceContextMode.PerSession,如下面的代码所述,但它似乎不起作用,因为我的计数没有增加。
请指教。
[ServiceContract(SessionMode = SessionMode.Required)]
public interface ITransService
{
[OperationContract(IsInitiating=true)]
int Insert(int userId);
[TransactionFlow(TransactionFlowOption.Allowed)]
[OperationContract]
int Update();
// TODO: Add your service operations here
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class TransService : ITransService
{
public int count = 0;
[OperationBehavior(TransactionScopeRequired = true)]
public int Insert(int userId)
{
count = count+1;
return count;
}
[OperationBehavior(TransactionScopeRequired = true)]
public int Update()
{
count = count++;
return count;
}
}
客户电话---
using (TransactionScope tranScope = new TransactionScope())
{
TransServiceClient obj = new TransServiceClient();
var a= obj.Insert(123);
var b = obj.Insert(123);
var c = obj.Update();
tranScope.Complete();
}
【问题讨论】:
标签: asp.net wcf c#-4.0 wcf-binding