Search code examples
node.jsxmlweb-servicessoapwsdl

Trouble understanding how to craft a SOAP request


I have to download something from a webservice via SOAP interface. The documentation for the interface is rather sparse so I have trouble understanding how to request from it.

This is the .wsdl specification.

This is the .xsd one.

The idea is:

  1. Logging in to get session key (I did this successfully)
  2. Using the session key to request available data (where I am having problems)
  3. Using this key to request specific data
  4. Logging out again

I am successfully getting the session key and using it with the request for the databox. Unfortunately, I'm only ever getting HTTP 404 as a response and I don't know how to find the problem since 404 also shows up when the session key is wrong ("asdfg" for example).

This is the XML I am sending:

    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <getDatabox xmlns="https://finanzonline.bmf.gv.at/fon/ws/databox">
            <tid>${tid}</tid>
            <benid>${benid}</benid>
            <id>${sessionToken}</id>
            <erltyp>${erltyp}</erltyp>
            <ts_zust_von>20-08-2017</ts_zust_von>
            <ts_zust_bis>25-08-2017</ts_zust_bis>   
        </getDatabox>
    </soap:Body>
</soap:Envelope>

This is the method I am using (I removed some ugliness from it, like the xmlDatabox which is initialized in the method for example):

function getDataBox(sessionToken, erltyp) {
  return new Promise((resolve, reject) => {
        var body = [];
        var https = require("https");
        var req = https.request(optionsDatabox, res => {
          res.setEncoding("utf8");
          res.on("data", chunk => {
            console.log("daty");
            console.log(chunk);
            body.push(chunk);
          });
          res.on("end", () => {
            console.log("STATUSCODE: " + res.statusCode);
            resolve(body.join(""));
          });
          res.on("error", err => {
            reject(err);
          });
        });
        req.write(xmlDatabox);

        req.end();
      });
    }

Now everything is sent as it should be sent. Also, the method and xml are (except for the important stuff) the same for getDatabox() and loginRequest() (which works). The only response is HTTPS 404.

How do I find what is wrong?

How do I prevent this frustration next time? (e.g. by knowing immediately what methods should be used)

EDIT: I'm not using the soap module because I had no success with it.


Solution

  • Okay..

    I used SoapUI to find out how the request should look like, since I didn't know much about the .wsld and .xsd formats.

    SoapUI reads those two files and creates the appropriate xml for it, which you just have to fill out. It also shows you the URL to which you have to send your request, which I didn't know at first either.