visual basic stop web服务连接

时间:2015-04-15 08:39:42

标签: vb6

我有Visual Basic Web Service连接代码:

Dim webService As SchnittstelleRechte.Service1 = New SchnittstelleRechte.Service1

如果超过5秒,我想停止此连接。有可能这样做???谢谢。

2 个答案:

答案 0 :(得分:1)

尝试这样做:

 Dim webServiceSchnittstelle As SchnittstelleRechte.Service1
 'Dim number as integer = 1
 Public Sub WebServiceConnection()
    'While True
    '  number = number + 1
    'End While
    webServiceSchnittstelle = New SchnittstelleRechte.Service1
 End Sub



 Public Sub angGetSchnittstelle()
   ' Create a thread object
   Dim thread As Thread = New Thread(AddressOf WebServiceConnection)
   ' Start the worker thread
   thread.Start()
   ' Wait 5 seconds on the main thread
   thread.Sleep(5000)
   ' Stop the worker thread
   thread.Abort()
 End Sub

你也可以测试它,取消注释4行,但是有一个问题,你每次都会等待5秒

答案 1 :(得分:1)

或尝试这样做:

Dim webServiceSchnittstelle As SchnittstelleRechte.Service1
Dim HttpWReq As HttpWebRequest = CType(WebRequest.Create(Url), HttpWebRequest)
Dim HttpWResp As HttpWebResponse = CType(HttpWReq.GetResponse(), HttpWebResponse)

If Not IsNothing(HttpWResp) Or Not IsNothing(HttpWResp) Then
    webServiceSchnittstelle = New SchnittstelleRechte.Service1      
End If

HttpWResp.Close()