Asp classic 在经典ASP中使用Web服务

Asp classic 在经典ASP中使用Web服务,asp-classic,Asp Classic,以下代码在WinServer2003机器上不适用于我,但在XP上适用。 我已经在服务器上安装了SOAP Toolkit 3.0。 原因可能是什么 这里是在经典ASP中使用.NET web服务的另一种方法 <html> <head><title></title></head> <body> <% Dim objHTTP, strEnvelope S

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


这里是在经典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>


“这是在经典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>


您是否尝试在IIS之外的Windows Server 2003计算机上运行脚本,即用CreateObject和Response替换Server.CreateObject。使用MsgBox写入并另存为VBS?这将告诉您服务器是否能够在不涉及IIS的情况下创建对象。它给我的错误是:ActiveX组件无法创建对象:“MSSOAP.SoapClient30”我与Windows Server 2008 64位有类似的问题。您的服务器是否也存在64位问题?查看此问题确实重申了我为什么喜欢Restful Json web服务。您是否尝试在IIS之外的Windows server 2003计算机上运行该脚本,即用CreateObject和Response替换server.CreateObject。使用MsgBox写入并另存为VBS?这将告诉您服务器是否能够在不涉及IIS的情况下创建对象。它给我的错误是:ActiveX组件无法创建对象:“MSSOAP.SoapClient30”我与Windows Server 2008 64位有类似的问题。您的服务器是否也存在64位问题?查看此问题确实重申了我为什么喜欢Restful Json web服务。很高兴有一个完整的答案,但请查看关于Microsoft.XMLHTTP的警告很高兴有一个完整的答案,但请查看关于Microsoft.XMLHTTP的警告