2011-05-11 2 views
0

Help !!서비스 호출을 두 번 호출 할 때 Silverlight에서 여러 개의 비동기 웹 요청이 충돌 함

여러 웹 서비스를 체인화하고 있으며 일단 호출하면 작동합니다. 두 번째로 나는 같은 전화를하려고 애썼다. 서비스 중 하나에 대한 eninvoke가 충돌한다 !! 나는 모든 것을 시도하고 수 많은 연구를 해본 결과 해결책을 찾지 못했고 심각한 마감 기한이 도래했습니다. 여기에 내 코드가있다.

 public void RejectViolation(ViolationPage currentPage, Violation currentViolation, RejectionReason rejectionReason) 
     { 
      //Copy the properties over 
      CurrentViolation = currentViolation; 
      MyViolationPage = currentPage; 
      _rejectionReason = rejectionReason; 

      //First call 
      ServiceAgent.Validate(CurrentViolation, 
       (s, e) => 
       { 
         //Reject the violation 
         Reject(); 
            }); 
     } 

     /// <summary> 
     /// Rejects the violation 
     /// </summary> 
     /// <returns>Nothing</returns> 
     private void Reject() 
     { 
      //Second call 
      ServiceAgent.RejectViolation(CurrentViolation, 
       (s, e) => 
       { 
                    MyViolationPage.RemoveCurrentViolation(); 
       }); 
     } 

     I am using the MVVM pattern so this is my view model. My Service Agent looks like this. 

/// <summary> 
     /// Validates the reject 
     /// </summary> 
     /// <param name="violation">The violation to reject</param> 
     /// <param name="callback">The callback function</param> 
     public void Validate(Violation violation, EventHandler<ValidateRejectCompletedEventArgs> callback) 
     { 
      try 
      { 
       // Submit violation for Accept to server 
       _client.ValidateRejectCompleted -= callback; 
       _client.ValidateRejectCompleted += callback; 
       _client.ValidateRejectAsync(violation); 
      } 
      catch (FaultException) 
      { 
       throw; 
      } 
      catch (EndpointNotFoundException endpointNotFoundException) 
      { 
       throw new Exception(DataSourceMessages.EndpointNotFoundExceptionMessage, endpointNotFoundException); 
      } 
      catch (ProtocolException protocolException) 
      { 
       throw new Exception(DataSourceMessages.ProtocolExceptionMessage, protocolException); 
      } 
      catch (CommunicationException communicationException) 
      { 
       throw new Exception(DataSourceMessages.CommunicationExceptionMessage, communicationException); 
      } 
     } 

     /// <summary> 
     /// Process the reject of a violation by a user 
     /// </summary> 
     /// <param name="violation"> 
     /// Violation to be rejected 
     /// </param> 
     /// <param name="callback"> 
     /// Function callback to notify requester about result of the execution. 
     /// </param> 
     public void RejectViolation(Violation violation, EventHandler<RejectViolationCompletedEventArgs> callback) 
     { 
      try 
      { 
       // Submit violation for Accept to server 
       this._client.RejectViolationCompleted -= callback; 
       this._client.RejectViolationCompleted += callback; 
       this._client.RejectViolationAsync(violation); 
      } 
      catch (FaultException) 
      { 
       throw; 
      } 
      catch (EndpointNotFoundException endpointNotFoundException) 
      { 
       throw new Exception(DataSourceMessages.EndpointNotFoundExceptionMessage, endpointNotFoundException); 
      } 
      catch (ProtocolException protocolException) 
      { 
       throw new Exception(DataSourceMessages.ProtocolExceptionMessage, protocolException); 
      } 
      catch (CommunicationException communicationException) 
      { 
       throw new Exception(DataSourceMessages.CommunicationExceptionMessage, communicationException); 
      } 
     } 

이 모든 작업을 수행 한 후에 정리해야 할 것이 있습니까? 처음으로 다시 호출하고 결과 세트를 반환 할 때 EndInvoke 메서드 에서 종료됩니다.

이것은 두 번째 시간을 충돌 어디 주위

어떤 도움을 크게 감상 할 수 결과를 검색하는 동안 충돌
public CoE.VCS.SL.ViolationService.Violation EndRejectViolation(System.IAsyncResult result) { 
       object[] _args = new object[0]; 
       CoE.VCS.SL.ViolationService.Violation _result = ((CoE.VCS.SL.ViolationService.Violation)(base.EndInvoke("RejectViolation", _args, result))); 
       return _result; 
      } 

. 감사합니다

답변

0

답을 찾았습니다.

서비스 에이전트가 정적이어서 콜백 이벤트 처리기가 계속 누적되었습니다. 모든 호출에서 서비스 에이전트를 다시 인스턴스화하고 문제를 해결했습니다.

관련 문제