簡體   English   中英

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

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

我試圖通過nodejs中的soap模塊點擊unicommerce的xml Api。 它在soapUI 中運行良好。但未集成到節點應用程序中。 我收到此錯誤。

錯誤:{錯誤:無法解析響應}。

   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);
    }
});

問題是:如何發送請求並打印答案? 你對這種問題有什么線索嗎?

非常感謝!

試試這個發送數據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