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

发布于 2024-11-06 18:39:08 字数 4609 浏览 1 评论 0原文

帮助 !!

我正在链接多个网络服务,当我调用它时,它就会起作用。第二次我尝试调用同一个调用时,其中一项服务的调用崩溃了!我已经尝试了一切并进行了大量的研究,但还没有找到解决方案,而且我们的最后期限即将到来。这是我的代码..

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

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

Help !!

I am chaining multiple web services and when I call it once it works. the second time I tried to call the same call the eninvoke of one of the services crashes !! I have tried everything and done tons of research and have not found a solution and we have a serious deadline coming up. Here is my code ..

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

Is there something that I need to clean up after I do all this work ?
It works fine the first time around I call it again and it dies on the EndInvoke method
when returning a result set.

This is where it crashes the second time around

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

it crashes while retrieving the result any help would be greatly appreciated. Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸠魁 2024-11-13 18:39:08

找到了答案。

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

Found the answer.

Since the Service Agent was static the callback event handlers kept accumulating. I re-instantiated the service agent on every call and it fixed the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文