Search code examples
node.jsweb-servicessoapwebservice-client

SOAP Webservice result returns 500 error code


I consumed a SOAP Webservice through Nodejs :

$(document).ready(function() {

    $.ajax({
            url: "/track/vehicule/getWebserviceRetourKYC",
            type: "POST",
            success : function(data, status, xhr) {
              console.dir(data);
            },
            error : function(xhr, status, error) {
              console.dir(error);
            }
          });

  });

var express = require('express');
var request = require("request");
var fs = require('fs');
var path = require('path');
var async = require('async');
var router = express.Router();
var db = require('./db');
var utils = require('./utils');
var connexion = db.getConnexion();

router.post("/getWebserviceRetourKYC", function(req, res) {
    var soap = require('strong-soap').soap;
    // wsdl of the web service this client is going to invoke. For local wsdl you can use, url = './wsdls/stockquote.wsdl'
    var url = "https://www.telma.net/sentimsa/mvola/wsdl.php?module=jWSDL&action=WSDL:wsdl&service=mvola~WSMVolaGetInfosKYC";

    var requestArgs = {
        module:'jWSDL',
        action:'WSDL:wsdl',
        service:'mvola~WSMVolaGetInfosKYC'
    };

    var options = {};
    soap.createClient(url, options, function(err, client) {
        var method = client['WSMVolaGetInfosKYCCtrl']['WSMVolaGetInfosKYCCtrlPort']['getInfosKYC'];
        console.dir(client);//here
        method(requestArgs, function(err, result, envelope, soapHeader) {
            //response envelope
            console.log('Response Envelope: \n' + envelope);
            //'result' is the response body
            console.log('Result: \n' + JSON.stringify(result));
        });
    });
    res.send();
});

module.exports = router;

At runtime the returned result is :

{
    "statusCode": 500,
    "body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Client<\/faultcode><faultstring>Error cannot find parameter<\/faultstring><\/SOAP-ENV:Fault><\/SOAP-ENV:Body><\/SOAP-ENV:Envelope>\n",
    "headers": 
    {
        "date": "Thu, 04 Jul 2019 05:51:26 GMT",
        "server": "Apache/2.2.3 (Red Hat)",
        "content-length": "294",
        "content-type": "text/xml; charset=utf-8",
        "content-language": "en",
        "connection": "close"
    },
    "request": 
    {
        "uri": 
        {
            "protocol": "https:",
            "slashes": true,
            "auth": null,
            "host": "www.telma.net",
            "port": 443,
            "hostname": "www.telma.net",
            "hash": null,
            "search": "?service=mvola%7EWSMVolaGetInfosKYC",
            "query": "service=mvola%7EWSMVolaGetInfosKYC",
            "pathname": "/sentimsa/mvola/soap.php",
            "path": "/sentimsa/mvola/soap.php?service=mvola%7EWSMVolaGetInfosKYC",
            "href": "https://www.telma.net/sentimsa/mvola/soap.php?service=mvola%7EWSMVolaGetInfosKYC"
        },
        "method": "POST",
        "headers": 
        {
            "User-Agent": "strong-soap/1.20.0",
            "Accept": "text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8",
            "Accept-Encoding": "none",
            "Accept-Charset": "utf-8",
            "Connection": "close",
            "Host": "www.telma.net",
            "Content-Length": 396,
            "Content-Type": "text/xml; charset=utf-8",
            "SOAPAction": "\"https://www.telma.net/sentimsa/mvola/soap.php?service=mvola%7EWSMVolaGetInfosKYC&method=getInfosKYC\""
        }
    }
}

So what is wrong in my codes ?

------ edit ------ :

Here is an example of the envelope and the desired result :

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mvol="https://www.telma.net/sentimsa/mvola/">

   <soapenv:Header/>

   <soapenv:Body>

      <mvol:getInfosKYC soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">

         <zSubscriberId xsi:type="xsd:string"> 0340017729</zSubscriberId>

      </mvol:getInfosKYC>

   </soapenv:Body>

</soapenv:Envelope>

Response :

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://www.telma.net/sentimsa/mvola/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">

   <SOAP-ENV:Body>

      <ns1:getInfosKYCResponse>

         <getInfosKYCReturn xsi:type="ns1:CCodeReponse">

            <oDataKYC xsi:nil="true" xsi:type="ns1:CKycInfos"/>

            <status_Code xsi:type="xsd:string">101</status_Code>

            <status_Reason xsi:type="xsd:string">Le numéro 0340017728 n’existe pas dans Sentinel.</status_Reason>

         </getInfosKYCReturn>

      </ns1:getInfosKYCResponse>

   </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

Solution

  • The error:

    <faultstring>Error cannot find parameter<\/faultstring>
    

    Suggests you're missing a required parameter from your request. Do you have documentation for the SOAP service you're consuming? Are module, action, and service the only required parameters?

    Also, you've included those parameters in the URL string as well:

    var url = "https://www.telma.net/sentimsa/mvola/wsdl.php?module=jWSDL&action=WSDL:wsdl&service=mvola~WSMVolaGetInfosKYC";
    

    Not sure if this would cause a problem, but at the very least it shouldn't be required. I'd try removing those parameters from the URL string.