【问题标题】:Test if a SOAP WSDL is up or down in vb script?测试 SOAP WSDL 在 vb 脚本中是打开还是关闭?
【发布时间】:2015-10-28 13:56:03
【问题描述】:

我正在尝试验证 WSDL 是否已在 VB 脚本中启动和运行。

如果我们在浏览器中打开 WSDL,如果我们在其中得到一个 XML,那么 WSDL 就已启动并正在运行

如果它是空白/超时/没有响应,那么 WSDL 是 DOWN

我想为此编写一个 VB Script 程序?

我期待在 VB 脚本中这样的东西可以在 QTP/UFT 或 EXCEL VBA MACRO 中运行。

这个程序是用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?");
    }
}

这个程序只是检查内容是否正在加载并决定它是否运行

任何想法

【问题讨论】:

    标签: excel vbscript qtp hp-uft vba


    【解决方案1】:

    这样的事情应该可以工作。
    我使用 SharePoint 2010 Web 服务进行了测试。

    ' 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
    

    以下类似,使用Microsoft WinHTTP Services v5.1而不是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
    

    【讨论】:

    • 谢谢哥们。似乎是一个巨大的代码。查看 Java 中的代码并在 VB 中帮助我
    • 检查编辑,为您分解,如果您有任何问题,请告诉我。
    • 优秀的工作伙伴 :) 但我只是想知道如果 oHttpRequest.ReadyState 不是 4 并且如果 oHttpRequest.Status 不是 200 而是输入一个错误的 URL,我们将得到什么确切的错误消息跨度>
    • 干杯!请参阅 StatusReadyState 的编辑,以及任何特定的错误消息...
    • 我有一个问题,这个程序运行良好,但是当 WSDL 在浏览器中继续加载时,程序没有响应,那么我需要手动终止它。我使用我拥有的 wsdl 列表创建了 MACRO,并且我正在逐一运行并获取状态,如果其中一个 wsdl 继续加载,则宏被挂起,我需要终止进程并重新启动它。对于这种情况,我们有什么解决方案,并在超时后继续列表中的下一个 wsdl 吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-20
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多