2014-12-24 4 views
0

아래 코드에서 언급 한 것처럼 wshttpbinding에서 InstanceContextMode.PerSession을 사용하고 있지만 카운트가 증가하지 않아 작동하지 않는 것 같습니다.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(); 
       } 

답변

0

(SessionMode = SessionMode.Allowed)로 인터페이스를 표시하는 것 외에 정의하는 데 필요한 인터페이스 initiate과 같이 세션에 어떤 방법 : 예 삽입만으로 세션이 시작되면 [OperationContract (IsInitiating = true)] int Insert (int userId); example here

가 확장 된 논평으로 당

(아니, IsInitiating = true은 어떤 경우에 기본값입니다) 거기는 시행 착오 접근 방식은 결국 TransactionFlow가 제대로 작동 SessionMode를 방지 함을 얻었다. 현재이 날짜에 대한 정확한 참조를 찾을 수 없습니다. 가장 가까운 날짜는 is this입니다. 논리적으로, 세션은 트랜잭션보다 훨씬 오래 지속될 수 있습니다 (그리고 트랜잭션은 데이터베이스와 큐 자원에 대한 잠금을 유지할 수 있습니다) 일부 논리가 있습니다.

상기 용액은 TransactionFlow을 제거하는 것이었다. InstanceContextMode = InstanceContextMode.PerSessionTransactionFlow 둘을 결합하고자하는 사람들을 위해

편집

, see here

+0

I 라인 아래에 추가 및 내 서비스 참조를 업데이트하지만 행운은 [OperationContract를 (IsInitiating = TRUE)]을 – Dev

+0

IsInitiating은에 간다 인터페이스 - 초기 게시물에 실수를 했습니까? 'SessionMode = SessionMode.Allowed'를'SessionMode.Required'로 변경하여 강제로 시도해 볼 수도 있습니다. – StuartLC

+0

내 코드에서 동일한 내용을 업데이트하고 클라이언트 서비스 참조를 업데이트했지만 여전히 동일한 문제가 있습니다 .i하지 않습니다. 이 코드에서 내가 뭘하고 있는지 알 수 있습니다. – Dev