21/04/2015 Development / soap

I development a solution for my company B2W Digital. We need using OAS real media SOAP and for this using Nodejs.

In my node index.js

var soap = require('soap');
var xml2js = require('xml2js');
var builder = new xml2js.Builder();
var parser = new xml2js.Parser({ explicitArray : false });

function requestOas( OasUrl, OasAccount, OasUser, OasPass, xml, callback){

  soap.createClient(OasUrl, function(err, client) {

    if (err) {
      callback(err);
      return;
    } 

    client.OasXmlRequest({
      String_1 : OasAccount,
      String_2 : OasUser,
      String_3 : OasPass,
      String_4 : xml
    }, function( err, data ) {

      if (err) {
        err = { errorStatus : err.code, errorMessage : 'SOAP error' };
      }

      if(data && data.result){
          parser.parseString(data.result, function(err, data) { 
            callback(err, data.AdXML.Response);
          });
      }else { 
        callback(err, data);
      }
    },
    {proxy: process.env.http_proxy || '', strictSSL: false});
  });
}

function OasApi(url, account, user, pass) { 
  this.url = url;
  this.account = account;
  this.user = user;
  this.pass = pass;
}

This a example for prototype method:

OasApi.prototype.addPage = function(url, callback) {

  var xml = {};
  xml.AdXML = {};
  xml.AdXML.Request = {
      $ : {
        type : 'Page'
      },
      Database : {
        $ : {
          action : 'add'
        },
        Pages : {
          Url : url
        }
      }
  };

  OasXml = builder.buildObject(xml);

  requestOas( this.url, this.account, this.user, this.pass, OasXml, callback );
};

Example for use this:

var oas = new OasApi('http://oas.realmedia.com.br?wsdl', 'Americanas', 'login','senha')

oas.addPage('url', function(resp){ console.log(resp) });

02/06/2015 Development / soap

Development a new service using SOAP for B2W Digital, i need tested service.

I used http://membrane-soa.org/soap-client/. Membrane its a free software.