首页 > 解决方案 > 将 WSDL 文件导入 Javascript

问题描述

我想将 XML 文件中的 WSDL 导入我的 JavaScript 项目,这将允许我使用 Web 客户端来搜索信息。

有什么特殊的方法可以导入到我的项目中,还是需要一个包,或者需要转成JS?我知道 NPM 中有一个 soap 包,但我希望这不是唯一的方法。我还阅读了有关 W3 的教程,但仍然不太确定如何管理它。

我有这样的事情:

    function soap() {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.open('POST', '127.0.0.1/start.html', true);

        // build SOAP request
        var sr =
                '<soapenv:Envelope ' +
                    'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" ' +
                    'xmlns:aut="http://demo.krd.pl/Authorization" xmlns:dto="http://demo.krd.pl/Chase3.1/Dto"> ' +
                    '<soapenv:Header> ' + 
                        '<aut:Authorization> '+
                            '<aut:AuthorizationType>LoginAndPassword</aut:AuthorizationType> ' +
                            '<aut:Login>login</aut:Login> ' +
                            '<aut:Password>password</aut:Password> ' +
                        '</aut:Authorization> ' +
                    '</soapenv:Header> ' +
                    '<soapenv:Body> ' +
                        '<dto:SearchNonConsumerRequest> ' +
                            '<dto:Number>24041803749</dto:Number> ' +
                            '<dto:NumberType>TaxId</dto:NumberType> ' +
                        '</dto:SearchNonConsumerRequest> ' +
                    '</soapenv:Body> ' +
                '</soapenv:Envelope> ';

        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {
                    alert('done. use firebug/console to see network response');
                }
            }
        }
        // Send the POST request
        xmlhttp.setRequestHeader('Content-Type', 'text/xml');
        xmlhttp.send(sr);
        // send request
        // ...
    }

此外,响应将保存在哪里,还是仅发布在控制台中?

标签: javascriptsoapwsdl

解决方案


推荐阅读