在NodeJS中使用node-soap时出错

问题描述 投票:0回答:3

我正在尝试使用node-soap来使用WSDL。我在我的控制器中使用如下:

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

当我打电话时,我在浏览器中得到了这个回复:

对象函数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;}没有方法'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)

我使用这个文档:Github project


现在我的文件看起来:

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

并在我的服务器中获取此信息:

无法设置null的属性“描述”

xml node.js web-services soap wsdl
3个回答
1
投票

首先要做的事情 - 当一个错误被抛出来指定一个对象“没有方法”时,我们希望有一个给定名称,这通常表明对象(或类)未能通过定义正确定义或者不正确的要求声明(不一定是你不正确地使用它)。

查看您提供的文档链接,引发此问题的最新项目是require('node-soap');语句。虽然该项目在github上被称为“node-soap”,但文档中提供的require语句表明该软件包的名称为“soap”。

尝试更换:

var soap = require('node-soap');

附:

var soap = require('soap');

此外,Node.js社区认为最佳做法是不在函数内部使用require()包,而是在任何函数或类定义之外,例如在源文件的顶部。

如果这样可以解决问题,请告诉我们 - 干杯。

编辑(问题已更新代码):

这是一个单独的问题(您的第一个问题已经解决):

从文档中,client.describe()方法用于提供“作为JavaScript对象的服务,端口和方法的描述”。

测试显示.describe()方法的使用只有在断言不存在错误时才合法。当错误存在时,您的代码当前尝试使用describe()方法。

if (err) {
    throw err
    client.describe();
}

你的新错误现在是Cannot set property 'descriptions' of null,因为没有提供一个对象来创建定义,可能是连接上有错误,请尝试检查你的url是否有效(即发回soap包可以使用的响应),否则describe()没有任何东西。


0
投票

好吧,我改变了网络服务的网址:

之前:http://identificacion.uci.cu/servicios/v5/servicios.php

之后:http://rhoda.uci.cu/roa.php/interoperability/session?wsdl

并且错误消失,可能是此模块仅适用于?wsdl而不适用于.php


0
投票

你必须检查,肥皂端点完成下一个结构

serviceURL = http://localhost:8080/Evaluator?wsdl

还检查一下

enter code here

await soap.createClient(serviceURL, (err: any, client: any) => {
    if (err) {
      reject(err)
    } else {
      client[method](payload, (errr: any, result: any) => {
        if (errr) {
          reject(errr)
        } else {
          resolve(result)
        }
      })
    }
  })

我希望这对你有用!

© www.soinside.com 2019 - 2024. All rights reserved.