简体   繁体   English

如何在nodejs中集成unicommerce的soap xml API

[英]How to integrate soap xml API of unicommerce in nodejs

I am trying to hit xml Api of unicommerce by soap module in nodejs.我试图通过nodejs中的soap模块点击unicommerce的xml Api。 It is working fine in soapUI.But is not integrated in node Application.它在soapUI 中运行良好。但未集成到节点应用程序中。 I am getting this error.我收到此错误。

ERROR: {Error: Cannot parse response}.错误:{错误:无法解析响应}。

   var express = require("express");
    var soap = require("soap");
    var http = require('http');
    var app = express();
    var router = express.Router();
var username = "*********";
var password = "************";
var auth = "Basic " + new Buffer(username + ":" + password).toString("base64");// not working 

var wsdlUrl = 'https://lensclues.unicommerce.com/services/soap/uniware16.wsdl?facility=01';

const Autentication = '<soapenv:Header>' +
'<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">' +
'<wsse:UsernameToken wsu:Id="UsernameToken-D6BE484999DA5E97D4148483888689316">' +
'<wsse:Username>**********</wsse:Username>' +
'<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">*******************</wsse:Password>'+
'<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">$$$$$$$$$$$</wsse:Nonce>'+
'<wsu:Created>2017-01-19T15:14:46.893Z</wsu:Created>'+
'</wsse:UsernameToken>'+
'</wsse:Security>' +
'</soapenv:Header>'
 soap.createClient(wsdlUrl, function (err, soapClient) {
soapClient.addSoapHeader(Autentication);
const data = '<soapenv:Envelope xmlns:ser="http://uniware.unicommerce.com   /services/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">' + '<soapenv:Body>' +
    '<ser:GetInventorySnapshotRequest>' +
    '<ser:ItemTypes>' +
    '<ser:ItemType>' +
    '<ser:ItemSKU>LCSGDB555xD15165S4PURx124</ser:ItemSKU>' +
    '</ser:ItemType>' +
    '</ser:ItemTypes>' +
    '<ser:UpdatedSinceInMinutes>600</ser:UpdatedSinceInMinutes>' +
    '</ser:GetInventorySnapshotRequest>' +
    '</soapenv:Body>' +
    '</soapenv:Envelope>'
if (err) {
    console.log("err", err);
}
soapClient.GetInventorySnapshot({    
    data
}, function (err, result) {
    if (err) {
        console.log("ERROR:", err);
    }
    else {
        console.log("result", result);
    }
});

The question is: How do I send the request and print the answer?问题是:如何发送请求并打印答案? Could you have any clues about this kind of issue?你对这种问题有什么线索吗?

Thanks a lot!非常感谢!

Try this send data xml format试试这个发送数据xml格式

 xw = new XMLWriter;
            xw.startDocument();
            xw.startElement('soapenv:Envelope');
            xw.writeAttribute('xmlns:ser', 'http://uniware.unicommerce.com/services/');
            xw.writeAttribute('xmlns:soapenv', 'http://schemas.xmlsoap.org/soap/envelope/');
            xw.startElement('soapenv:Header');
            xw.startElement('wsse:Security');
            xw.writeAttribute('soapenv:mustUnderstand', '1');
            xw.writeAttribute('xmlns:wsse', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd');
            xw.startElement('wsse:UsernameToken');
            xw.startElement('wsse:Username');
            xw.text('******');
            xw.endElement('wsse:Username');
            xw.startElement('wsse:Password');
            xw.text('*******password');
            xw.endElement('wsse:Password');
            xw.endElement('wsse:UsernameToken');
            xw.endElement('wsse:Security');
            xw.endElement('soapenv:Header');
            xw.startElement('soapenv:Body');
            xw.startElement('ser:GetInventorySnapshotRequest');
            xw.startElement('ser:ItemTypes');
            xw.startElement('ser:ItemType');
            xw.startElement('ser:ItemSKU');
            xw.text(sku);
            xw.endDocument();
            /*************************Request Module******************/
            request(
                {
                    'method': "POST",
                    'url': 'https://lensclues.unicommerce.com/services/soap/uniware16.wsdl?',
                    'body': xw.toString(),
                    'Content-Type': 'text/xml'
                },
                function (error, response, body) {
                    if (!error && response.statusCode == 200) {
                        parseString(body, function (err, result) {
                            let tt = result['SOAP-ENV:Envelope']['SOAP-ENV:Body'][0]['GetInventorySnapshotResponse'][0]['Successful'][0]
                            console.log("Error---------->", tt);
                            console.log("Result---------->", result);
                            if (tt == "false") {
                                var check = result['SOAP-ENV:Envelope']['SOAP-ENV:Body'][0]['GetInventorySnapshotResponse'][0]['Errors'][0]['Error'][0];
                                console.log("check", check);
                                mainCallback(check, err);
                            }
                            else {
                                let inventoryValue = result['SOAP-ENV:Envelope']['SOAP-ENV:Body'][0]['GetInventorySnapshotResponse'][0]['InventorySnapshots'][0]["InventorySnapshot"][0]['Inventory'][0];
                                console.log("inventoryValue", inventoryValue);
                                if (inventoryValue >= prodQty) {
                                    mainCallback(null, inventoryValue);
                                }
                                else {
                                    mainCallback("Inventory not be available", err);
                                }

                            }
                        });
                    }
                    else {
                        console.log("------------->", error)
                        mainCallback("error in to fetch inventory data", error);
                    }
                }
            );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM