kornylovamargarita
@kornylovamargarita

Soap запрос на node js возвращает undefined, как исправить?

Не могу получить ответ на Soap запрос при помощи node js. Тестировала при помощи SoapUI ответ приходит, а через ноду только undefined. Такой запрос проходит через UI:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.snowball.progmatic.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:getCompetitionDataJSON>
         <credentials>
            <login>System</login>
            <password>Snowball</password>
         </credentials>
         <competitionId>34</competitionId>
         <period>3</period>

      </ser:getCompetitionDataJSON>
   </soapenv:Body>
</soapenv:Envelope>

У меня есть 2 варианта кода:

var http = require('http');

var body = `
<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.snowball.progmatic.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:getCompetitionDataJSON>
         <credentials>
            <login>System</login>
            <password>Snowball</password>
         </credentials>
         <competitionId>34</competitionId>
         <period>3</period>

      </ser:getCompetitionDataJSON>
   </soapenv:Body>
</soapenv:Envelope>`;

let url = 'http://test.mobangels.com/snowball/SbService?wsdl';

let postRequest = {
    host: 'test.mobangels.com',
    path: "snowball/SbService",
    // path: "snowball/SbService?wsdl",
    port: 80,
    method: "POST",


headers: {
        'Accept-Encoding': 'gzip,deflate',
        'Content-Type': 'text/xml;charset=UTF-8',
        'SOAPAction': "getCompetitionDataJSON",
        'Host': 'test.mobangels.com',
        'Connection': 'Keep-Alive',
        'User-Agent': 'Apache-HttpClient/4.1.1 (java 1.5)',
        'Content-Length': Buffer.byteLength(body)
    }
};


let req = http.request( postRequest, function( res ){

    console.log( res.statusCode );
    // console.log( res );
   var buffer = "";
    console.log( 'test' );
   res.on( "data", function( data ) { console.log( '_0_', data ); buffer = buffer + data;  } );
   res.on( "end", function( data ) { console.log('_1_', data ); console.log( '_2_', buffer ); } );

});

req.on('error', function(e) {
    console.log('problem with request: ' + e.message);
});

req.write( body );
req.end();

и второй:

let soap = require('soap');
let url = 'http://test.mobangels.com/snowball/SbService?wsdl';

let args = {
    credentials:{
        login: 'System',
        password: 'Snowball'
    },  
    competitionId: '34',
    period: '1',
    startFrom: '2017-07-12T15:20:54.120+04:00'
};

var wsdlOptions = {
  "overrideRootElement": {
    "namespace": "ser",
    "xmlnsAttributes": [{
      "name": "xmlns:ser",
      "value": "http://service.snowball.progmatic.com/"
    }]
  }
};

let app = express();


    soap.createClient(url,wsdlOptions, function(err, client) {
        client.getCompetitionDataJSON(args, function(err, result) {
            console.log(result);
        });
        console.log(client.lastRequest)
    });

такой результат

400
test
_1_ undefined
_2_

и такой

<?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:tns="http://service.snowball.progmatic.com/"><soap:Body><ser:getCompetitionDataJSON xmlns:ser="http://service.snowball.progmatic.com/"><credentials><login>System</login><password>Snowball</password></credentials><competitionId>34</competitionId><period>1</period><startFrom>2017-07-12T15:20:54.120+04:00</startFrom></ser:getCompetitionDataJSON></soap:Body></soap:Envelope>
undefined
  • Вопрос задан
  • 86 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через TM ID
Похожие вопросы