【问题标题】:Consume webservice in classic ASP在经典 ASP 中使用 Web 服务
【发布时间】:2009-04-20 06:40:58
【问题描述】:

以下代码在 Win Server 2003 机器上不适用于我,但在 XP 上有效。 我已经在服务器上安装了 SOAP Toolkit 3.0。 可能是什么原因?

【问题讨论】:

  • 您是否尝试过在 IIS 之外的 Windows Server 2003 机器上运行脚本,即将 Server.CreateObject 替换为 CreateObject 并将 Response.Write 替换为 MsgBox 并保存为 VBS?这应该告诉您服务器是否能够在不涉及 IIS 的情况下创建对象。
  • 我已经尝试过 .vbs 文件中的代码。它给了我错误:ActiveX 组件无法创建对象:'MSSOAP.SoapClient30'
  • 我在使用 Windows Server 2008 64 位时遇到了类似的问题。有问题的服务器也是 64 位的吗?
  • 看这个问题真的重申了我为什么喜欢Restful Json web services。

标签: asp-classic


【解决方案1】:

'这是在经典 ASP 中使用 .NET Web 服务的另一种方式。

<html>
    <head><title></title></head>
    <body>


    <%    
        Dim objHTTP, strEnvelope
        Set objHTTP = Server.CreateObject("Microsoft.XMLHTTP")

        'Create the SOAP Envelope.
        'Start with standard xml name space and XML Schema Definition.
        strEnvelope = "<?xml version='1.0' encoding='utf-8'?>"
        strEnvelope = strEnvelope & "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"

        'Define body of SOAP with method name and parameter names and vlaues to be passed.
        strEnvelope = strEnvelope & "<soap:Body>"
        strEnvelope = strEnvelope & "<AuthenticateUser xmlns='http://wwwte.abc.com/cpp'>"
        strEnvelope = strEnvelope & "<db>1</db>"
        strEnvelope = strEnvelope & "<_username>MYUSERNAME</_username>"
        strEnvelope = strEnvelope & "<_password>MYPASSWORD</_password>"
        strEnvelope = strEnvelope & "</AuthenticateUser>"
        strEnvelope = strEnvelope & "</soap:Body></soap:Envelope>"    

        'Set properties of HTTP object and send SOAP envelop while calling 'Send' method
        Dim url
        url = "http://cpp.abc.com/cpp/CPPLDAP/CPPLDAP.asmx"
        With objHTTP
            .Open "post", url, False
            .setRequestHeader "Content-Type", "text/xml; charset=utf-8"
            .setRequestHeader "SOAPAction", "http://wwwte.abc.com/cpp/AuthenticateUser"
            .send strEnvelope
        End With
        ' Following will write xml received from web services in the browser
        Dim strResponse
        strResponse = objHTTP.responseXML.Text
        If (strResponse = "") Then
            Response.Write("Invalid user")
        Else        
            Set myXmlDoc = Server.CreateObject("MSXML2.DOMDocument")
            myXmlDoc.loadXML (strResponse)
            Set objLst = myXmlDoc.getElementsByTagName("directoryEntry")
            Set objListNodes = objLst.Context.childNodes(0).childNodes
            For i = 0 To (objListNodes.Length - 1)
               Response.Write(objListNodes.Item(i).nodeName & ":------ " & objListNodes.Item(i).Text)
               Response.Write("</BR>")
            Next
        End If

    %>


    </body>
</html>

【讨论】:

  • 很高兴有一个完整的答案,但请查看this 关于 Microsoft.XMLHTTP 的警告
猜你喜欢
  • 1970-01-01
  • 2018-05-27
  • 2010-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-05
  • 1970-01-01
相关资源
最近更新 更多