调用长时间运行的 Web 服务 - 在延续中获取请求的详细信息

发布于 2025-01-01 10:57:41 字数 911 浏览 3 评论 0原文

假设我有类似以下代码的代码:

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 技术交流群。

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

发布评论

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

评论(1

沉鱼一梦 2025-01-08 10:57:41

您可以将 serviceInput 变量的值传递给您的延续,如下所示:

serviceTasks.Add(Task(Of XmlElement).Factory.FromAsync(AddressOf proxy.BeginLongRunningService, _  
                                                       AddressOf proxy.EndLongRunningService, _  
                                                       serviceInput, _  
                                                       proxy) _  
                             .ContinueWith(Sub(antecedent) HandleServiceReturn(serviceInput, antecedent)))

private sub HandleServiceReturn(input As XmlDocument, antecedant As Task(Of XmlElement))

You can pass the value of the serviceInput variable on to your continuation like so:

serviceTasks.Add(Task(Of XmlElement).Factory.FromAsync(AddressOf proxy.BeginLongRunningService, _  
                                                       AddressOf proxy.EndLongRunningService, _  
                                                       serviceInput, _  
                                                       proxy) _  
                             .ContinueWith(Sub(antecedent) HandleServiceReturn(serviceInput, antecedent)))

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