两次调用服务调用时,Silverlight链接多个异步Web请求会崩溃

时间:2011-05-11 19:33:44

标签: silverlight asynchronous chaining

帮助!!

我正在链接多个Web服务,当我调用它一旦它工作。我第二次尝试拨打同一个电话,其中一个服务崩溃了!我已经尝试了所有的东西,并完成了大量的研究,但没有找到解决方案,我们有一个严重的截止日期。这是我的代码..

      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;
            }

它在检索结果时崩溃任何帮助将不胜感激。感谢

1 个答案:

答案 0 :(得分:0)

找到答案。

由于Service Agent是静态的,因此回调事件处理程序不断累积。我在每次调用时都重新实例化了服务代理,并修复了问题。