如何使用javascript(例如SoapUI)发送SOAP请求

我目前正在开发一个NodeJS项目,需要在其中使用soap / xml / wsdl.问题是无法弄清楚这些方法的工作原理,请原谅我的无知.这是我需要的:

我有这个WSDL网站,我需要从中获得一些答案.我已经知道如何在SoapUI中执行此操作,但是我不知道如何在Javascript中执行此操作.我在soapUI中发送的请求如下所示:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:uni="https://uni-login.dk">
   <soap:Header/>
   <soap:Body>
      <uni:hentDataAftaler>
         <uni:wsBrugerid>?</uni:wsBrugerid>
         <uni:wsPassword>?</uni:wsPassword>
      </uni:hentDataAftaler>
   </soap:Body>
</soap:Envelope>

我也有wsdl-link:
https://wsiautor.uni-login.dk/wsiautor-v4/ws?WSDL

我也尝试过在nodeJS中使用一些npm包(SOAP,Strong-SOAP和Easy-SOAP),但是我也无法使它们工作.

希望您有一些建议,并告诉我是否需要更多信息来回答我的问题:)

解决方法:

您可以使用easy-soap-request,这篇文章https://medium.com/@caleblemoine/how-to-perform-soap-requests-with-node-js-4a9627070eb6可能会有所帮助.它只是axios的薄薄包装.

我的问题代码

const soapRequest = require('easy-soap-request');
const url = 'https://wsiautor.uni-login.dk/wsiautor-v4/ws';
const headers = {
    'Content-Type': 'application/soap+xml;charset=UTF-8',
    'soapAction': 'https://wsiautor.uni-login.dk/hentDataAftaler',
};
// example data
const xml = `
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:uni="https://uni-login.dk">
   <soap:Header/>
   <soap:Body>
      <uni:hentDataAftaler>
         <uni:wsBrugerid>?</uni:wsBrugerid>
         <uni:wsPassword>?</uni:wsPassword>
      </uni:hentDataAftaler>
   </soap:Body>
</soap:Envelope>
`;


// usage of module
soapRequest(url, headers, xml).then(({response: {body, statusCode}}) => {
    console.log(body);
    console.log(statusCode);
}).catch((errorBody) => {
    console.error(errorBody);
});

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念