1

I'm trying to make a SOAP request to a WSDL service with ws-security. The code is simple:

var fs = require('fs');
var soap = require('soap');
var url = '<WSDL-URL>';
var args = { 
    "param1": '1', 
    "param2": '2', 
    "param3": '3', 
    "param4": '4',
};
const options = {
    envelopeKey: 'soapenv',
    forceSoapVersion: '1.1',
};


var privateKey = fs.readFileSync('<PRIVATE-KEY>');
var publicKey = fs.readFileSync('<PUBLIC-KEY>');
var password = ''; // NO PASSWORD
var wsOptions = { hasTimeStamp: true };
soap.WSSecurityCert(privateKey, publicKey, password, wsOptions)

soap.createClient(url, options, function(err, client) {
    //console.log(err);
    client.setEndpoint('<SERVICE-ENDPOINT>');
    
    client.setSecurity(new soap.ClientSSLSecurity('<SSL-KEY>', '<SSL-CERT>', {}));
    client.METHOD(args, function(err, result, envelope, soapHeader) {
        console.log(err);
        //console.log(client.lastRequest);
        
        //console.log('Response Envelope: \n' + envelope);
        // 'result' is the response body
        //console.log('Result invoke: \n' + JSON.stringify(result));
    });
});

but when i try to run the script, i got this error:

Error: soap:Server: These policy alternatives can not be satisfied: 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}AsymmetricBinding: Received Timestamp does not match the requirements
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}X509Token: The received token does not match the token inclusion requirement
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}InitiatorToken
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}RecipientToken
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}IncludeTimestamp: Received Timestamp does not match the requirements
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}SignedParts: {http://schemas.xmlsoap.org/soap/envelope/}Body not SIGNED
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}EncryptedParts: {http://schemas.xmlsoap.org/soap/envelope/}Body not ENCRYPTED

I think I don't have set correctly the ws-security to the header and i'm still missing how to encrypt my body too.

Can someone help me to figure out how to solve this issue?

LandL
  • 35
  • 4

0 Answers0