lehh / nestjs-soap

Nestjs module wrapper for soap npm package
MIT License
21 stars 15 forks source link

How can i pass options to message. #14

Closed boggoriss closed 2 years ago

boggoriss commented 2 years ago

Hello, i need to refactor this code:

var SoapClient = require('soap');
var options = {
    'trace': 1,
    "overrideRootElement": {
        "namespace": "myns",
        "xmlnsAttributes": [{
            "name": "xmlns:ns2",
            "value": "http://russianpost.org/operationhistory"
        }]
    },
    forceSoap12Headers: true,
    connection: 'keep-alive',
    'soap_version': 2
};
SoapClient.createClient('./local_wsdl.xml', options, function (err, client) {
    client.getOperationHistory(
        {
        'ns1:OperationHistoryRequest': {
            'ns1:Barcode': trackValue,
            'ns1:MessageType': 0,
            'ns1:Language': 'RUS',
        },
        'ns1:AuthorizationHeader': {
            'ns1:login': login,
            'ns1:password': password,
        },
    },
    (err, result) => {
        if (err) {
            console.log(err);

            return;
        }

        console.log(result.OperationHistoryData);
    }
    );
}

so i need to pass options, while send a message, and i try this:

async getOperationHistory() {
        let options = {            
            'trace': 1,
            "overrideRootElement": {
                "namespace": "ns2",
                "xmlnsAttributes": [{
                    "name": "xmlns:ns2",
                    "value": "http://russianpost.org/operationhistory"
                }]
            },
            forceSoap12Headers: true,
            connection: 'keep-alive',
            'soap_version': 2
        }
        this.postClient.addHttpHeader('Content-Type', 'xml');
        return await this.postClient.getOperationHistory
        (
            {
                'ns2:OperationHistoryRequest': {
                    'ns2:Barcode': '',
                    'ns2:MessageType': 0,
                    'ns2:Language': 'RUS',
                },
                'ns2:AuthorizationHeader': {
                    'ns2:login': ,
                    'ns2:password': ,
                }

            },
            (r, e) => {
                if (e) console.log(e.config.data, e.data);
            },
            options,
        )
    }

but this doesn't work.

lehh commented 2 years ago

Hello,

Your question is about how to add a soap header, is that right?

If so, have you tried this.postClient.addSoapHeader('Content-Type', 'xml'); ?

If not, I need some more details about the problem.

lehh commented 2 years ago

Closing as there weren't any answers