最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - How to send a SOAP request in javascript, like in SoapUI - Stack Overflow

programmeradmin2浏览0评论

I am currently working on a NodeJS project where I need to use some soap/xml/wsdl. The problem is that can't figure out how any of these works, so forgive my ignorance. Here is what I need:

I have this WSDL site that I need to get some answers from. I have figured out how to do this in SoapUI, but I have no idea how to do it in Javascript. The request that I am sending in soapUI looks like this:

<soap:Envelope xmlns:soap="" xmlns:uni="">
   <soap:Header/>
   <soap:Body>
      <uni:hentDataAftaler>
         <uni:wsBrugerid>?</uni:wsBrugerid>
         <uni:wsPassword>?</uni:wsPassword>
      </uni:hentDataAftaler>
   </soap:Body>
</soap:Envelope>

I also have the wsdl-link:

I have also tried to use some npm-packages in nodeJS (SOAP, Strong-SOAP and Easy-SOAP), but I can't make these work either.

I hope you I have some suggestions and tell me if you need any more information to answer my question :)

I am currently working on a NodeJS project where I need to use some soap/xml/wsdl. The problem is that can't figure out how any of these works, so forgive my ignorance. Here is what I need:

I have this WSDL site that I need to get some answers from. I have figured out how to do this in SoapUI, but I have no idea how to do it in Javascript. The request that I am sending in soapUI looks like this:

<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>

I also have the wsdl-link: https://wsiautor.uni-login.dk/wsiautor-v4/ws?WSDL

I have also tried to use some npm-packages in nodeJS (SOAP, Strong-SOAP and Easy-SOAP), but I can't make these work either.

I hope you I have some suggestions and tell me if you need any more information to answer my question :)

Share Improve this question edited Apr 13, 2019 at 10:12 Chris asked Apr 5, 2019 at 16:36 ChrisChris 1151 gold badge4 silver badges18 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 6 +50

You can use easy-soap-request,and this article https://medium.com/@caleblemoine/how-to-perform-soap-requests-with-node-js-4a9627070eb6 may help. It is just a thin wrapper of axios.

My code for your question:

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);
});

for those who get an error after following @aristoll answer. Try this, its gonna work

before

soapRequest(url, headers, xml).....

after

soapRequest({url, headers, xml})......

It may be useful to someone in the future: Change this (url, headers, xml) to ( {url, headers, xml})

发布评论

评论列表(0)

  1. 暂无评论