I'm trying to consume a WSDL with node-soap. I use it as follows in my controller:
this.getSoap = function (request, response) {
var soap = require('node-soap');
var url = 'http://identificacion.uci.cu/servicios/v5/servicios.php';
var args = { IdExpediente: '016381' };
soap.createClient(url, function (err, client) {
client.ObtenerFotoDadoIdExpediente(args, function (err, result) {
if (err) {
throw err
client.describe();
} else
console.log(result);
});
});
return response.render('index', {
variable: 'valor'
});
};
And when I call I get this response in the browser:
Object function SOAPClient(options, fn) { fn = this.fn = fn; options =
this.options = _.extend({}, defaults, options); var deferred;
this.namespaces = ''; this.methods = ''; this.body = function
(options) { return "" +
"http://schemas.xmlsoap.org/soap/envelope\/\" " +
"xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\" " +
"xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\" " + options.namespaces
+ ">" + "" + options.methods + "" + ''; }; this.newRequest(); return this; } has no
method 'createClient'
TypeError: Object function SOAPClient(options, fn) {
fn = this.fn = fn;
options = this.options = _.extend({}, defaults, options);
var deferred;
this.namespaces = '';
this.methods = '';
this.body = function (options) {
return "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<SOAP-ENV:Envelope " +
"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope\/\" " +
"xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\" " +
"xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\" " +
options.namespaces +
">" +
"<SOAP-ENV:Body>" +
options.methods +
"</SOAP-ENV:Body>" +
'</SOAP-ENV:Envelope>';
};
this.newRequest();
return this;
} has no method 'createClient'
at Object.getSoap (/home/heimdall/Proyectos/myNODE/src/SoapModule /controller/soapController.js:19:10)
at module.exports (/home/heimdall/Proyectos/myNODE/src/SoapModule/resources/config/routing.js:16:20)
at Layer.handle [as handle_request] (/home/heimdall/Proyectos/myNODE/node_modules/express/lib/router/layer.js:82:5)
at next (/home/heimdall/Proyectos/myNODE/node_modules/express/lib/router/route.js:110:13)
at Route.dispatch (/home/heimdall/Proyectos/myNODE/node_modules/express/lib/router/route.js:91:3)
at Layer.handle [as handle_request] (/home/heimdall/Proyectos/myNODE/node_modules/express/lib/router/layer.js:82:5)
at /home/heimdall/Proyectos/myNODE/node_modules/express/lib/router/index.js:267:22
at Function.proto.process_params (/home/heimdall/Proyectos/myNODE/node_modules/express/lib/router/index.js:321:12)
at next (/home/heimdall/Proyectos/myNODE/node_modules/express/lib/router/index.js:261:10)
at expressInit (/home/heimdall/Proyectos/myNODE/node_modules/express/lib/middleware/init.js:23:5)
I use this documentation: Github project
Now my file look that:
var soap = require('soap');
// url del wsdl
this.getSoap = function (request, response) {
var url = 'http://identificacion.uci.cu/servicios/v5/servicios.php';
var args = { IdExpediente: '016381' };
soap.createClient(url, function (err, client) {
if (err) {
console.log(err);
} else {
client.ObtenerFotoDadoIdExpediente(args, function (err, result) {
if (err) {
throw err
client.describe();
} else
console.log(result);
});
}
});
And obtain this in my server:
Cannot set property 'descriptions' of null
Best Answer
First things first -- when an error is thrown specifying an object "has no method," and we expect there to be one by the given name, this typically suggests the object (or class) failed to be defined properly via the definition or an incorrect require statement (not necessarily that you're using it improperly).
Looking at the documentation link you've provided, the initial item that stands out to me to be causing this issue is the
require('node-soap');
statement. While the project is called "node-soap" on github, the require statements provided in the documentation indicate that the package is by the name of "soap".Try replacing:
With:
Also, the Node.js community considers it best practice to not
require()
packages within functions, but rather outside of any functions or class definitions, such as at the top of the source file.Let us know if that solves the issue -- cheers.
Edit (question has updated code):
This is a separate issue (your first one has been solved):
From the documentation, the
client.describe()
method is used to offer a "description of services, ports and methods as a JavaScript object."The tests show usage of the
.describe()
method to only be legal if the assertion is made that an error does not exist. Your code currently attempts to use thedescribe()
method when an error exists.Your new error is
Cannot set property 'descriptions' of null
now because an object hasn't been provided to create definitions on, likely there is an error along the connection, try checking if your url is valid (i.e. sending back a response the soap package can work with), otherwise there isn't anything todescribe()
.