2

我为我的项目添加了网络参考。

我正在使用线程,它们以这种方式调用 Web 服务:

Private Sub principal()
    Dim arrayH As New ArrayList
    Dim h As Thread
    Dim z As Integer = 150

    For i As Integer = 1 To Z
        h= New Thread(AddressOf doWork)
        arrayH.Add(h)
    Next


    For Each _h As Thread In arrayH
        _h.Start()
    Next
End Sub

Private Sub doWork()
    Dim service As webService.Query
    Dim parameter, response As String

    parameter = "..."'The parameter is a xml

    Try
        service = New Query
        response = service.Report(parameter)

    Catch ex As Exception
        'do something
    End Try

End Sub

当有很多线程(Z = 150)时,它会抛出:

System.InvalidOperationException

There is an error in XML document (1, 279).

Unable to read data from the transport connection: The connection was closed. 

如果 Z 很小,没有问题。我该如何避免这种情况?

4

1 回答 1

1

错误“无法从传输连接读取数据:连接已关闭。” 实际上是服务器端问题。您可能一次请求太多请求。

于 2012-11-03T14:14:59.990 回答