0

The following Node.js code gives me error "Unhandled rejection Error: Invalid WSDL":

// Purpose: via node platform to access another system from my company
// This is the project url to get web service, already working on soapUI
var url = "https://w3(intranet-link)/webservices/ws_GetUserData.wss?wsdl";
var args = {
  msg:"connecting!"
};
//define project access
var userid='';
var password='';

soap.createClientAsync(url).then((client) => {
  //add project access to logon to url
  client.setSecurity(new soap.BasicAuthSecurity(userid, password));
  return client.MyFunctionAsync(args);
}).then((result) => {
  console.log(result);
});

How can I fix this problem? Thank you!

Rup
  • 33,765
  • 9
  • 83
  • 112
Cathy
  • 9
  • 4
  • How to fix this problem on node platform, thank you! – Cathy Sep 11 '18 at 18:24
  • So you're saying that Node.js rejects the WSDL whereas SoapUI accepts it? Can you validate the WSDL somewhere else, particularly somewhere that might explain validation problems to you? Is there no information in the Node.JS error about why it thinks the WSDL is invalid? – Rup Sep 11 '18 at 19:17
  • Actually, I tested URL on SoapUI app, it is working. And could get my data via xml.But when I use it via node platform via using this soap method. it return the error as following: – Cathy Sep 11 '18 at 23:00
  • Unhandled rejection Error: Invalid WSDL URL: https://w3(intranet-link)/webservices/ws_GetUserData.wss?wsdl Code: 401 Response Body: at /Users/cathy/Desktop/UserDataChart/node_modules/soap/lib/wsdl.js:2306:18 at Request._callback (/Users/cathy/Desktop/UserDataChart/node_modules/soap/lib/http.js:137:7) So not sure if this soap menthod I am using is correct or any other menthod to implement. maybe it is crossing domain, so can not get. Not sure yet... Thank you. – Cathy Sep 11 '18 at 23:16
  • Looking at soap/lib/wsdl.js, that "Code: 401" is the HTTP response code, which means Unauthorized. So I guess your server needs authentication to just read the WSDL? – Rup Sep 12 '18 at 06:44
  • yeup, that's right.But I add the code as following "client.setSecurity(new soap.BasicAuthSecurity(userid, password));",it seems not working, right? Any other way to implement it ? – Cathy Sep 12 '18 at 08:41
  • That's too late: it fetches the WSDL in createClientAsync. You can pass an options parameter into createClientAsync with a wsdl_header map containing an Authorization header that the WSDL fetch will use: see this question: [Setting Authorization in Node.js SOAP Client](https://stackoverflow.com/q/26816715/243245). I've added a new answer to show how to reuse your security object to generate the header as well. – Rup Sep 12 '18 at 09:10
  • Note also the answers there have the callback arguments from createClientAsync as (err, client) not just (client). – Rup Sep 12 '18 at 09:13
  • thank you. I have changed my codes, it seems working.but still return error : Unhandled rejection Cannot set property 'descriptions' of null – Cathy Sep 12 '18 at 16:07
  • That could be a failure in the async part of createClientAsync. I'm afraid I'm out of ideas: you'll probably have to debug it with your WSDL, sorry. – Rup Sep 12 '18 at 16:41
  • No sorry. That's a big thanks to you as provided. :) – Cathy Sep 13 '18 at 04:19

0 Answers0