通过HTML Soap XML请求

时间:2018-03-20 04:54:56

标签: xml soap boomi

我对SOAP不太熟悉。我试图通过XML请求使用SOAP WSDL。此请求工作正常,由Chrome扩展程序Boomerang创建。当我从Boomerang运行它时,我也在SOAP UI中执行它,一个进程在云应用程序“boomi”中执行,这是预期的结果。

但是,出于演示目的,我想知道是否可以使用HTML或JavaScript来运行此请求?

<x:Envelope xmlns:x="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://api.platform.boomi.com/">
    <x:Header/>
    <x:Body>
        <api:executeProcess>
            <api:properties processId="1876e5e9-ceb7-4417-a465-04f1ee381d01" processName="Box CSV to HA" atomId="de5b7bf7-2cf2-4fa1-952f-ad960db0990b">
                <api:ProcessProperties>
                  <api:ProcessProperty>
                     <api:Name>LoginName</api:Name>
                     <api:Value>XXXXX@XXXXXX.com</api:Value>
                  </api:ProcessProperty>
                  <api:ProcessProperty>
                     <api:Name>Password</api:Name>
                     <api:Value>XXXXXX</api:Value>
                  </api:ProcessProperty>
                </api:ProcessProperties>
            </api:properties>
        </api:executeProcess>
    </x:Body>
</x:Envelope>

1 个答案:

答案 0 :(得分:0)

我有一个解决方案。

<html>
<head>
    <title>SOAP JavaScript Client Test</title>
    <script type="text/javascript">
        function soap() {

            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open('POST', 'https://api.XXXXXXXXXXXXXX', false);

            //xmlhttp.withCredentials = true;
            // build SOAP request
            var sr = '<soapenv:Envelope xmlns:api="http://api.XXXXXXXXX" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">'+
                       '<soapenv:Header>'+
                          '<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/'+
                          'oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/'+
                          'oasis-200401-wss-wssecurity-utility-1.0.xsd">'+
                             '<wsse:UsernameToken wsu:Id="XXXXXXXXXXXXXXXXXXXXXXXX>'+
                                '<wsse:Username>#####@#####.com</wsse:Username>'+
                                '<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/'+
                                'oasis-200401-wss-username-token-profile-1.0#PasswordText" '+
                                '>########</wsse:Password>'+
                                '<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/'+
                                'oasis-200401-wss-soap-message-security-1.0#Base64Binary">djyUzLptXhdTx20wbKCcQQ==</wsse:Nonce>'+
                                '<wsu:Created>2018-03-20T22:39:11.110Z</wsu:Created>'+
                             '</wsse:UsernameToken>'+
                          '</wsse:Security>'+
                       '</soapenv:Header>'+
                       '<soapenv:Body>'+
                          '<api:executeProcess>'+
                             '<!--Optional:-->'+
                             '<api:properties atomId="XXXXXXXXXXXXXXXX" processId="XXXXXXXXXXXXXXXXX" '+
                             'processName="XXXXXXXXX">'+
                                '<api:ProcessProperties>'+
                                   '<!--Zero or more repetitions:-->'+
                                   '<api:ProcessProperty>'+
                                      '<api:Name>LoginName</api:Name>'+
                                      '<api:Value>XXXXXXXXXXXX</api:Value>'+
                                   '</api:ProcessProperty>'+
                                   '<api:ProcessProperty>'+
                                      '<api:Name>Password</api:Name>'+
                                      '<api:Value>XXXXXXXXXXXXXX</api:Value>'+
                                   '</api:ProcessProperty>'+
                                '</api:ProcessProperties>'+
                             '</api:properties>'+
                          '</api:executeProcess>'+
                       '</soapenv:Body>'+
                    '</soapenv:Envelope>'         ;

            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4) {
                    if (xmlhttp.status == 200) {
                        alert('Process Request Started');
                    }
                }
            }
            // Send the POST request
            xmlhttp.setRequestHeader('Content-Type', 'text/xml');
            xmlhttp.send(sr);
            // send request
            // ...
        }
    </script>
</head>
<body>
    <form name="Demo" action="" method="post">
        <div>
            <input type="button" value="Execute Process" onclick="soap();" />
        </div>
    </form>
</body>
</html> <!-- typo -->