1

I am new to working with SOAP - especially within node, but i really want to learn how to work with different data transfer protocols.

I have built an Angular 5 application with and Express middleware and a Node.js server to communicate a REST api. However, now i have to pull some data from a different source, communicating over SOAP. I have a request and body looking like this:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetDashboardInfo xmlns ="http://IAmAURL.com/client">
<username>ThisIsNotTheRealUser</username>
<password>ThisIsNotTheRealPassword</password>
<applicationIdentifier>Identifier.827</applicationIdentifier>
<deviceIdentifier>DataTest</deviceIdentifier>
</GetDashboardInfo>
</soap:Body>
</soap:Envelope>

With a POST to a client: https://server.someplace.com/MobileClient.asmx

I do know that the request returns the data i want when using PostMan as such: working SOAP request

What are some ways to generally communicate a SOAP request like this with Node?

1 Answer 1

1

Allright! I figured it out. After a while of testing it turns out SOAP calls are not overly complicated. For my particular scenario, the Node js code looks like this:

var request = require("request");

var options = { method: 'POST',
  url: 'https://server.someplace.com/MobileClient.asmx',
  headers: 
   { 'Cache-Control': 'no-cache',
     'Content-Type': 'text/xml' },
  body: '<?xml version="1.0" encoding="utf-8"?>\r\n<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">\r\n<soap:Body>\r\n<GetDashboardInfo xmlns ="http://IAmAURL.com/client">\r\n<username>ThisIsNotTheRealUser</username>\r\n<password>ThisIsNotTheRealPassword</password>\r\n<applicationIdentifier>Identifier.827</applicationIdentifier>\r\n<deviceIdentifier>DataTest</deviceIdentifier>\r\n</GetDashboardInfo>\r\n</soap:Body>\r\n</soap:Envelope>' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

I will try to explain this as verbose as i can, please correct me if I'm wrong:

A few things going on here. request is a dependency for node that simplifies http calls. In the options object we define the method, which as i understand i always POST for SOAP calls. The URL is the URL to where you're directing your request. The Body is the part of your SOAP request containing the functions/methods and XML schemas to be used for formatting your data. The functions are dependent on the api you use, so check with whoever your pulling data from, what methods they offer for granting you the data you specifically need. The Body also contains the authentication needed to access my soap service. Finally i log the result (body) in the console, which returns all the data formatted in XML.

Awesome! What now? Well now i need to format the XML into JSON objects that i can actually use. For this i will probably use the node package xml2json , but that is a separate issue.

Hope this helps someone somewhere.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.