Silverlight链接多个异步web请求在两次调用服务调用时崩溃
救命 我正在链接多个web服务,当我调用它时,它就会工作。第二次尝试调用同一个调用时,其中一个服务崩溃!!我已经尝试了所有的方法,做了大量的研究,但还没有找到解决方案,我们的最后期限就要到了。这是我的密码Silverlight链接多个异步web请求在两次调用服务调用时崩溃,silverlight,asynchronous,chaining,Silverlight,Asynchronous,Chaining,救命 我正在链接多个web服务,当我调用它时,它就会工作。第二次尝试调用同一个调用时,其中一个服务崩溃!!我已经尝试了所有的方法,做了大量的研究,但还没有找到解决方案,我们的最后期限就要到了。这是我的密码 public void RejectViolation(ViolationPage currentPage, Violation currentViolation, RejectionReason rejectionReason) { //C
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);
}
}
它在检索结果时崩溃。如果您有任何帮助,我们将不胜感激。谢谢你找到了答案
由于服务代理是静态的,因此回调事件处理程序不断累积。我在每次通话中都重新实例化了服务代理,它解决了这个问题
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;
}