Test if a SOAP WSDL is up or down in vb script?

好久不见. 提交于 2019-12-11 10:33:39

问题


I am trying to Verify if the WSDL is UP and Running or NOT in VB Script.

IF we open the WSDL in browser, if we get an XML in that then the WSDL is UP and Running

If it is blank/timing out/not responding then WSDL is DOWN

I want to write a VB Script program for this?

I was expecting some thing like this in VB Script to run in QTP/UFT or EXCEL VBA MACRO.

This program is written in Java

public static void main(String args[]) {
    String wsdl = "http://lxomavnat005.dev.qintra.com:10301/icl/services/ICL_2_0?wsdl";
    URL url = null;
    URLConnection urlConnection = null;
    try {

        url = new URL(wsdl);
        urlConnection = url.openConnection();

        if (urlConnection.getContent() != null) {
            System.out.println("GOOD URL");
        } else {
            System.out.println("BAD URL");
        }

    } catch (IOException ex) {

        System.out
                .println("Failed opening connection. Perhaps WS is not up?");
    }
}

This Program just check the content is loading or not and decides if it running or not

Any Ideas


回答1:


Something like this should work.
I tested using a SharePoint 2010 web service.

' TestWSDL - Test if WSDL is up and running
Public Sub TestWSDL()
  Dim oHttpRequest As Object
  Dim oHttpResponse As Object

  On Error GoTo Trap

  Set oHttpRequest = CreateObject("Microsoft.XMLHTTP")
  oHttpRequest.Open "GET", "http://domain/path/_vti_bin/UserGroup.asmx?wsdl", False
  oHttpRequest.Send

  If oHttpRequest.ReadyState = 4 Then
    If oHttpRequest.Status = 200 Then
      Set oHttpResponse = oHttpRequest.ResponseXML
      If oHttpResponse Is Nothing Then
        MsgBox "bad url"
      Else
        MsgBox "good url"
        Set oHttpResponse = Nothing
      End If
    Else
      MsgBox oHttpRequest.Status & " - " & oHttpRequest.StatusText
    End If
  Else
    MsgBox oHttpRequest.ReadyState
  End If

Trap:
  If Err <> 0 Then
    MsgBox Error(Err)
  End If

  Set oHttpRequest = Nothing
End Sub

Following is similar, using Microsoft WinHTTP Services v5.1 instead of Microsoft XMLHTTP

Public Sub TestWinHTTP()
  Dim oHttpRequest As Object

  On Error GoTo Trap

  Set oHttpRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
  oHttpRequest.Open "GET", "http://domain/path/_vti_bin/UserGroup.asmx?wsdl", False

  ' Need to use SetCredentials OR SetAutoLogonPolicy
  ' Set specific username / password
  'oHttpRequest.SetCredentials "username", "password", 0

  ' Use windows authentication
  oHttpRequest.SetAutoLogonPolicy 0

  ' Set timeout values -- host, connect, send, receive
  oHttpRequest.SetTimeouts 30000, 60000, 30000, 30000

  oHttpRequest.Send

  If oHttpRequest.Status = 200 Then
    If oHttpRequest.ResponseText = "" Then
      MsgBox "bad url"
    Else
      MsgBox "good url"
    End If
  Else
    MsgBox "bad url"
  End If

Trap:
  If Err <> 0 Then
    MsgBox Error(Err)
  End If

  Set oHttpRequest = Nothing
End Sub


来源:https://stackoverflow.com/questions/33392981/test-if-a-soap-wsdl-is-up-or-down-in-vb-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!