如何使用javascript(例如SoapUI)发送SOAP请求 [英] How to send a SOAP request in javascript, like in SoapUI

查看:387
本文介绍了如何使用javascript(例如SoapUI)发送SOAP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在一个NodeJS项目上,我需要使用一些soap/xml/wsdl.问题是无法弄清楚其中的任何一个如何工作,所以请原谅我的无知.这是我需要的:

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:

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

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>

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

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

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

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

推荐答案

您可以使用easy-soap-request,而本文

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

这篇关于如何使用javascript(例如SoapUI)发送SOAP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆