如何在 javascript 中发送 SOAP 请求,就像在 SoapUI 中一样

2024-04-08

我目前正在开发一个 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 链接:https://wsiautor.uni-login.dk/wsiautor-v4/ws?WSDL 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 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);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 javascript 中发送 SOAP 请求,就像在 SoapUI 中一样 的相关文章

随机推荐