调用长时间运行的 Web 服务 - 在延续中获取请求的详细信息
假设我有类似以下代码的代码:
Dim serviceTasks As New List(Of Task)()
serviceTasks.Add(Task(Of XmlElement).Factory.FromAsync(AddressOf proxy.BeginLongRunningService, _
AddressOf proxy.EndLongRunningService, _
serviceInput, _
proxy) _
.ContinueWith(Sub(antecedent) HandleServiceReturn(antecedent)))
以及我的延续:
private sub HandleServiceReturn(antecedant As Task(Of XmlElement))
'Do stuff with our result here
dim data = antecedant.result
end sub
其中我的“serviceInput”对象是传递给长时间运行的 Web 服务的 XML 文档。我创建了这些任务组并异步运行它们,一切都很好,直到我在 Web 服务调用中遇到错误。在这种情况下,能够访问在我的延续中发送到服务的“请求”参数将很有用,因为结果只是一个例外。
我对 TPL 相当陌生,我想知道是否有办法做到这一点?
Say I have something like the following code:
Dim serviceTasks As New List(Of Task)()
serviceTasks.Add(Task(Of XmlElement).Factory.FromAsync(AddressOf proxy.BeginLongRunningService, _
AddressOf proxy.EndLongRunningService, _
serviceInput, _
proxy) _
.ContinueWith(Sub(antecedent) HandleServiceReturn(antecedent)))
And my continuation:
private sub HandleServiceReturn(antecedant As Task(Of XmlElement))
'Do stuff with our result here
dim data = antecedant.result
end sub
Where my 'serviceInput' object is an XML document being passed to a long running web service. I create groups of these tasks and run them asynchronously and all is fine until I hit an error in the web service call. In this case, it would be useful to be able to access the 'request' parameters that were sent to the service in my continuation, as the result is just an exception.
I'm fairly new to the TPL, and I was wondering if there is a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 serviceInput 变量的值传递给您的延续,如下所示:
You can pass the value of the serviceInput variable on to your continuation like so: