为什么连续多次调用Async Web Service方法只执行一次该方法

发布于 2024-12-11 04:13:11 字数 1001 浏览 0 评论 0原文

我有一个 Web 服务,我尝试使用异步方法多次调用它。该方法只是记录调用,不会引发任何异常,也不会返回任何内容。

但是,仅记录第一个呼叫,其余呼叫不会记录。如果同步调用Web方法,或者每次之前都实例化Web服务代理,或者减慢调用速度,则调用可以工作。

不涉及防火墙,没有流量离开机器(我也尝试在另一台机器上托管该服务)。

谁能解释为什么只有第一个异步调用成功而其余的则失败?另外 - 完成的事件被触发了正确的次数,这很奇怪!我连接了 fiddler,只有第一个 Web 服务调用离开了我的机器。

调用代码(仅运行一次 Web 方法):

    Dim svc As New wsLogThisService.LogThisService
    AddHandler svc.LogTestCompleted, AddressOf Completed

    For i As Integer = 1 To 100
        Dim request As New TestRequest
        request.LogLevel = LogLevelOptions.Err
        request.Counter = i.ToString

        svc.LogTestAsync(request)
    Next

调用代码(有效):

    For i As Integer = 1 To 100

        Dim svc As New wsLogThisService.LogThisService
        AddHandler svc.LogTestCompleted, AddressOf Completed

        Dim request As New TestRequest
        request.LogLevel = LogLevelOptions.Err
        request.Counter = i.ToString

        svc.LogTestAsync(request)
    Next

I have an Web Service that I am trying to call multiple times using an async method. The method simply logs the call, no Exceptions are raised and it doesn't return anything.

However, only the first call is logged, the rest don't make it. If call the web method synchronously, or instantiate the web service proxy each time before, or slow down the calls, the calls works.

No fire walls are involved, no traffic leaves the machine (I've also tried hosting the service on another machine).

Can anyone explain why only the first async call succeeds and the rest don't? Also - the completed event is fired the correct number of times, which is very strange! I hooked up fiddler and only the first web service call leaves my machine.

Calling code (Runs web method once only):

    Dim svc As New wsLogThisService.LogThisService
    AddHandler svc.LogTestCompleted, AddressOf Completed

    For i As Integer = 1 To 100
        Dim request As New TestRequest
        request.LogLevel = LogLevelOptions.Err
        request.Counter = i.ToString

        svc.LogTestAsync(request)
    Next

Calling code (Works):

    For i As Integer = 1 To 100

        Dim svc As New wsLogThisService.LogThisService
        AddHandler svc.LogTestCompleted, AddressOf Completed

        Dim request As New TestRequest
        request.LogLevel = LogLevelOptions.Err
        request.Counter = i.ToString

        svc.LogTestAsync(request)
    Next

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

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

发布评论

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

评论(1

追风人 2024-12-18 04:13:11

此处找到了答案 -如果您不是每次都实例化服务代理,则需要包含一个状态对象。

Found the answer here - you need to include a state object if you aren't instantiating the service proxy each time.

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