【问题标题】:Silverlight chaining multiple async web requests crashes when calling service call twice两次调用服务调用时,Silverlight 链接多个异步 Web 请求崩溃
【发布时间】:2011-05-11 19:33:44
【问题描述】:

求救!!

我正在链接多个 Web 服务,一旦它工作,我就会调用它。我第二次尝试调用同一个调用,其中一个服务崩溃的 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;
            }

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

【问题讨论】:

    标签: silverlight asynchronous chaining


    【解决方案1】:

    找到答案了。

    由于服务代理是静态的,回调事件处理程序不断累积。我在每次通话时都重新实例化了服务代理,它解决了问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 2011-09-03
      相关资源
      最近更新 更多