在 IIS 上显示来自 javascript 文件(SOAP 请求)的 XML 响应

Display XML response from javascript file (SOAP Request) on IIS

我目前使用的日历系统具有 API 我可以通过 SOAP 请求进行访问。它存在于 IIS 服务器上。

最初我想我可以创建一个 HTML 页面,然后我将使用 Javascript 到 return SOAP 请求的内容 - 我的 SOAP 请求 return 正是我想要的,但不是有效的 XML - 它只是显示在屏幕上(目前在下面注释掉)。

我需要知道的是如何让 return 的页面只是有效的 XML 响应(没有其他标签,因此它被识别为 XML)? PHP 更适合这个 - 还是 ASP?

我目前的 javascript 看起来像这样:

function soap() {
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open('POST', 'http://myserver/EMSAPI/', true);

            //Todays Date                       now = new Date();
              year = "" + now.getFullYear();
              month = "" + (now.getMonth() + 1); if (month.length == 1) { month = "0" + month; }
              day = "" + now.getDate(); if (day.length == 1) { day = "0" + day; }
              hour = "" + now.getHours(); if (hour.length == 1) { hour = "0" + hour; }
              minute = "" + now.getMinutes(); if (minute.length == 1) { minute = "0" + minute; }
              second = "" + now.getSeconds(); if (second.length == 1) { second = "0" + second; }
              todaydate =  year + "-" + month + "-" + day + "T" + hour + ":" + minute + ":" + second + ".000";



            // build SOAP request
            var sr =
                '<?xml version="1.0" encoding="utf-8"?>' +
                '<soap:Envelope ' + 
                    'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
                    'xmlns:api="http://127.0.0.1/Integrics/Enswitch/API" ' +
                    'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
                    'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
                    '<soap:Body>' +
                        '<GetAllBookings xmlns="http://DEA.EMS.API.Web.Service/">' +
                            '<UserName>EmsAPI</UserName>' +
                            '<Password>Mypass</Password>' +
                            '<StartDate>'+todaydate+'</StartDate>' +
                            '<EndDate>'+todaydate+'</EndDate>' +
                            '<BuildingID>36</BuildingID>' +
                            '<ViewComboRoomComponents>false</ViewComboRoomComponents>' +
                        '</GetAllBookings>' +
                    '</soap:Body>' +
                '</soap:Envelope>';

            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4) {
                    if (xmlhttp.status == 200) {
                        ret = xmlhttp.responseText;
                        //$(document.body).append(ret);

                    }
                }
            }
            // Send the POST request
            xmlhttp.setRequestHeader('Content-Type', 'text/xml');
            xmlhttp.send(sr);
            // send request
            // ...
        }

window.onload = function() {   soap(); };

我的 HTML 非常简单 - 除了 javascript.

之外,它是一个空白文档

问题是我使用的一些软件不能直接与压延机交互——而且该软件只接受有效的 XML 响应——所以无论我写什么页面,它都必须 return 只是纯粹的 XML 这样当我告诉软件页面 URL - 它会得到适当的 XML 响应。

只是想知道还有什么其他方法可以让它发挥作用。如果问题令人困惑,我深表歉意 - 如果需要,我可以详细说明。

我选择经典 ASP 是为了做我想做的事。

我的最终代码在经典 ASP 中看起来像这样 ASP:

<%
Dim objXMLHTTP : set objXMLHTTP = Server.CreateObject("MSXML2.XMLHTTP")

Dim strRequest, strResult, strFunction, strURL, strNamespace

'URL to SOAP namespace and connection URL
strNamespace = "http://DEA.EMS.API.Web.Service/"
strURL = "http://myserver/EMSAPI/"

'function you want to call
strFunction = "GetBuildings"
'strFunction = "test" 'no parameters required

strRequest ="<?xml version=""1.0"" encoding=""utf-8""?>" &_
      "<soap:Envelope" &_
      " xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""" &_
      " xmlns:api=""http://127.0.0.1/Integrics/Enswitch/API""" &_
      " xmlns:xsd=""http://www.w3.org/2001/XMLSchema""" &_
      " xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">" &_
        "<soap:Body>" &_
                "<GetBuildings xmlns=""http://DEA.EMS.API.Web.Service/"">" &_
                    "<UserName>Myusername</UserName>" &_
                    "<Password>mypassword</Password>" &_
                "</GetBuildings>" &_
        "</soap:Body>" &_
      "</soap:Envelope>"


objXMLHTTP.open "POST", ""& strURL &"", True

objXMLHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
objXMLHTTP.setRequestHeader "Content-Length", Len(strRequest) 
objXMLHTTP.setRequestHeader "SOAPAction", strNamespace & strFunction


'send the request and capture the result
objXMLHTTP.send(strRequest)

'Set a timer to wait for response
set shell = CreateObject("WScript.Shell")
 t1 = timer()
 sleep(1)
 t2 = timer()
 response.write "waited "& t2-t1 &" secs"

 function sleep(seconds)
    if seconds>=1 then shell.popup "pausing",seconds,"pause",64
 end function


strResult = objXMLHTTP.responseText


'display the XML
response.write strResult

%>