Simple soap call is failing (Nodejs, easysoap) - node.js

I am having some problems with easysoap (https://npmjs.org/package/easysoap) and I have been unable to find much documentation or people talking about it, so I hope some of you can help:
I’m making a simple call like this:
var clientParams = {
host : 'somewhere.com',
port : '9001',
path : '/somews.asmx',
wsdl : '/somews.asmx?WSDL'
};
var clientOptions = {
secure : false
};
//create new soap client
var SoapClient = new soap.Client(clientParams, clientOptions);
SoapClient.once('initialized', function() {
//successful initialized
SoapClient.once('soapMethod', function(data, header) {
});
console.log('call');
SoapClient.call({
'method' : 'Execute',
'params' : {
'ExecuteXML' : 1
}}, function(attrs, err, responseArray, header){
}
);
});
//initialize soap client
SoapClient.init();
The problem Is that I get a response saying that I am not authorized to make my request.However if I manually try the same url in the browser http://somewhere.com:9001/somews.asmx it does work.
Do you know what am I doing wrong?
Many many thanks in advance.
If any of you know of any other node module to achieve this please let me know. I attempted to use node-soap but got lost in all the dependencies required: python, Visual Studio... you really need all that to make a couple of soap calls to a server???
Thanks

For other nodejs soap modules. I currently use node-soap and am happy with it. You can find the project here.
Here is an example of how I'm using it.
var soap = require('soap');
//example url
var url = 'http://ws.strikeiron.com/GlobalAddressVerification5?WSDL';
var soapHeader = ''//xml string for header
soap.createClient(url, function(err, client){
client.addSoapHeader(soapHeader);
var args = {
StreetAddressLines: "5322 Otter Lane",
CountrySpecificLocalityLine: "Middleberge FL 32068",
Country: "USA"
};
client.BasicVerify(args, function(err, result){
if(err){
throw err;
}
console.log(result);
});
});

For me this worked:
"use strict";
var easysoap = require('easysoap');
var clientParams = {
host : 'http://somewhere.com:9001',
path : '/somews.asmx',
wsdl : '/somews.asmx?WSDL'
};
var clientOptions = {
secure : false
};
var soapClient = easysoap.createClient(clientParams, clientOptions);
soapClient.call({'method' : 'Execute',
'params' : {
'ExecuteXML' : 1
}})
.then(function (callResponse) {
console.log(callResponse);
})
.catch(function (err) {
console.log("Got an error making SOAP call: ", err);
});

Related

How to capture ftp-client connect attempt errors

I use the npm package ftp-client to download files from an ftp server. I cannot determine how to capture possible errors when attempting to connect to the remote server. Documentation on the ftp-client package is very sparse.
Can anyone help?
My code is below. As it stands any connection error (e.g. invalid password) just crashes the application.
const ftpClient = require('ftp-client');
require('dotenv').config();
const dtf_login = process.env.dtf_login;
const dtf_psw = process.env.dtf_psw;
const dtf_host = process.env.dtf_host;
function doDirDownload(remoteDir, localDir, callback){
var ftpOptions = {logging : 'none', overwrite : 'all'};
var ftpConfig = {host : dtf_host,
port : 21,
user : dtf_login,
password : dtf_psw};
c = new ftpClient(ftpConfig, ftpOptions);
c.connect((err) => {
if(err){
callback(err);
} else {
c.download(remoteDir, localDir,
{overwrite: 'all'}, (result) => {
callback(result);
});
}
});
}

How to get mail id of twitter account through nodejs

I am trying to get mail id from twitter user through nodejs at the result I only got tweets and other details of users but I don't get mail id. I attach my code anyone tell me whether my code is write way to get mail id
// twitter api script
var config = require("./config");
// In config file I have my consumer_key, consumer_secret, access_token_key,access_token_secret
var fs = require('fs');
var Twitter = require('twitter');
var client = new Twitter(config.twitter);
var writer = fs.createWriteStream('tweets.json')
var start_time = 0;
var handles = "";
fs.readFile('./t_handle.csv', 'utf8', function(err, contents) {
var params = {
'include_email' : true
};
handles = contents.split("\n");
writer.write("[");
handles.forEach(function(handle){
handle = handle.split("/")[3];
if(typeof handle !== 'undefined' && handle){
handle = handle.split("?")[0];
get_handle_tweets(handle,params);
}
});
});
function get_handle_tweets(handle){
client.get('statuses/user_timeline', { screen_name: handle }, function(error, tweets,params,response) {
if(error){
console.log(error);
}else{
tweets.forEach(function(tweet){
writer.write(JSON.stringify(tweet)+",\n");
});
}
});
}
First check if when you Authorize for your app in the Will be able to see field, "see your email address" is there , if not check if you have valid privacy policy and TOS URL since white listing the app is no longer required, also in php I had to Change 'include_email' : true to 'include_email' : 'true' sometime ago when I tried this, so that could be the issue.

Node + Mongodb + ObjectId not working

I am working with nodejs+ express and mongodb.
I am using postman and access the API.
When I use ObjectId the server not responding anything. If i removed means working good.
I am not able to fix this issue. Please can anyone help for this.
test.js
//Post Data:
{
"list_id": "56963e4dbcd5d4ff27ced0fbd"
}
var app = require('express');
var router = app.Router();
var server = require('./../../server');
var mongoUtil = require('./../../mongoUtil');
var ObjectId = require('mongodb').ObjectID;
router.post('/share', function(req, res, next) {
var data = {
query : {}
};
console.log(req.body['list_id']);
//printed 56963e4dbcd5d4ff27ced0fbd
console.log(data.query);
//printed {}
data.query = ObjectId(req.body['list_id']);
console.log(data.query);
//Here not getting any response
// this line not printed and server no response.
//Also tried the following things. but its not working.
// data.query['_id'] = new ObjectID(req.body['list_id']);
//data.query._id = ObjectId(req.body['list_id']);
var collection = mongoUtil.list;
collection.findOne(data.query, function(err, list) {
console.log(err);
console.log(list);
if (!err && list) {
res.send("Sucess");
return;
} else {
res.send("Error");
return;
}
});
});
56963e4dbcd5d4ff27ced0fbd should be of length 24. But it is 25. Make sure it is 24. It might work.
ObjectID()
Constructor
Create a new ObjectID instance
class ObjectID()
Arguments:
id (string) – Can be a 24 byte hex string, 12 byte binary string or a Number.
Returns:
object instance of ObjectID
Caught with the same error. Seems like ObjectId from mongoDB not working.
FOllowing import fixed the issue:
import { ObjectId } from "bson"

Node-Soap Cannot read property 'Body' of undefined

Using node-soap:
I'm trying to use this service : http://services.resumeparsing.com/ParsingService.asmx?op=ParseResume
I get a successful response when I query GetAccountInfo so I know my account/servicekey are correct: http://services.resumeparsing.com/ParsingService.asmx?op=GetAccountInfo
The error I'm seeing is: TypeError: Cannot read property 'Body' of undefined when I try to use the ParseResume service.
Here's how I call ParseResume:
var buff_string = new Buffer(upload, 'base64')
var soap_args = {
url:"http://services.resumeparsing.com/ParsingService.asmx?wsdl",
args: {
request: {
AccountId : myAccountId,
ServiceKey : myServiceKey,
FileBytes : buff_string,
OutputXmlDoc : true,
Configuration: myConfString
}
}
}
client.ParsingService.ParsingServiceSoap12.ParseResume(soap_args.args, function(err, result){
if(err) console.log ( err )
if(result) console.log (result)
})
As you can probably tell, I've never used SOAP before, any guidance is greatly appreciated!
edit: FileBytes is asking for a base64Binary string
changed
var buff_string = new Buffer(upload, 'base64')
to
var buff_string = (new Buffer(upload)).toString('base64')

RESTful CRUD for Angular and Express $resource

I have my JSON querying and creating correctly. I'm a bit stuck on how to remove items from the server. They are being removed in angular but I can't seem to get the connection right for removing them on the server.
My server.js:
var hcController = require('./server/controllers/services-controller.js')
//REST API
app.get('/api/hc', hcController.list);
app.post('/api/hc', hcController.create);
app.delete('/api/hc:_id', hcController.delete);
My server-side model
var mongoose = require('mongoose');
module.exports = mongoose.model('HealingCenterData',{
title: String,
shortname: String,
summary: String,
description: String
});
My server-side controller
var Hc = require('../models/healingcenter-model.js')
module.exports.create = function (req, res) {
var hc = new Hc(req.body);
hc.save(function (err, result){
res.json(result);
});
}
module.exports.list = function (req,res) {
Hc.find({}, function (err, results){
res.json(results);
});
}
module.exports.delete = function (req, res) {
???????
});
}
My angular service:
app.factory("HC", ["$resource", function($resource) {
return {
API: $resource('/api/hc/:id')
}
}]);
My angular controller:
app.controller('servicesController', ['$scope', 'HC','$resource', function ($scope, HC, $resource) {
HC.API.query(function(results) {
$scope.services = results;
});
$scope.createService = function() {
var service = new HC.API();
service.title = $scope.serviceTitle;
service.shortname = $scope.serviceShortname;
service.summary = $scope.serviceSummary;
service.description = $scope.serviceDescription;
service.$save(function(result){
$scope.services.push(result);
$scope.serviceTitle = '';
$scope.serviceShortname = '';
$scope.serviceSummary = '';
$scope.serviceDescription = '';
});
}
$scope.removeItem = function(index){
$scope.services.splice(index, 1);
}
}]);
My JSON structure
{ "_id" : ObjectId("53bea9366a03a66c2dad68bb"), "title" : "Auto Clinic", "shortname" : "auto_clinic", "summary" : "Volunteers evaluate car problems and make minor repairs. Labor is free, and the car owner pays for any needed parts. Oil changes are performed at a reduced cost. All services are performed on Saturdays.", "description" : "No additional information yet.", "__v" : 0 }
On the server side try (I'm assuming you are using moongose) :
exports.delete = function(req,res){
if(req.params.id !==null || req.params.id!==undefined){
Hc.remove({_id:req.params.id},function(err){
res.send(200);
});
}
};
on the client side:
angular controller:
var endPoint = $resource('/api/hc/:id', {id:'#tId'});
$scope.removeItem = function(id){
var ep = new endPoint({tId:id});
ep.$delete(function(res){
//TODO: update local array in scope
});
};
EDIT:
you can just use the resource directly in the controller or just the service as you have done in your case, that's totally fine.

Resources