node.js - 在 node-soap 中,如何查看/调试生成的 XML SOAP 请求?

标签 node.js soap

我尝试像这样使用 node-soap 模块:

const soap = require('soap');

soap.createClient('some-wsdl-url', function(err, client) {
    const args = {
        'ValidateCustomerRequest': {
            'memberNumber': 12345
        }
    };

    client.ValidateCustomer(args, function(err, result) {
        console.log(result);
    });
});

现在我从网络服务收到“无效格式”响应。为了调试它,我非常想看看发送到 web 服务的实际 XML 是什么样子的。

我已经尝试过这个:
require('request').debug = true

... 这是 another SO answer 中的建议.

但是输出没有那么有用:
[ERROR] REQUEST { uri:
  Url { ... },
  method: 'GET',
  headers:
   { 'User-Agent': 'node-soap/0.18.0',
     Accept: 'text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8',
     'Accept-Encoding': 'none',
     'Accept-Charset': 'utf-8',
     Connection: 'close',
     Host: 'xxx' },
  followAllRedirects: true,
  body: null,
  callback: [Function] }

我在那里看不到我的“ValidateCustomerRequest”,并且正文为空。另外我想知道为什么方法是GET,不应该是POST吗?

那么这个调试输出看起来是否正常和/或是否有其他方法可以查看创建的 XML 请求?

最佳答案

我忽略了 documentation 的这一点:

Client.lastRequest - the property that contains last full soap request for client logging



您可以在 web 服务调用的回调中记录这一点。所以上面的代码将如下所示:
const soap = require('soap');

soap.createClient('some-wsdl-url', function(err, client) {
    const args = {
        'ValidateCustomerRequest': {
            'memberNumber': 12345
        }
    };

    client.ValidateCustomer(args, function(err, result) {
        console.log(result);
        console.log('last request: ', client.lastRequest) // <-- here
    });
});

这将输出生成的 XML 请求。

关于node.js - 在 node-soap 中,如何查看/调试生成的 XML SOAP 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42119190/

相关文章:

node.js - 使用 begin_with 查询 dynamodb

javascript - 如何将 item 更新到 PostgreSQL 中的 jsonb 数据类型列

c++ - 在 c++ WWSAPI Web 服务中处理 WS-Security PasswordDigest 模式

javascript - 如何使用 $http POST 传递对象参数并在 Nodejs 服务中访问

javascript - 警告 : flatten is not a function Use --force to continue

javascript - Google Slides API 无法从页面实例读取幻灯片内容 (Node.Js)

java - JAX-WS 和 Joda-Time?

使用 basicHttpBinding 的 WCF 服务仍在发送内容类型 "text/xml"

eclipse - WSDL : java. lang.NoClassDefFoundError 的代码生成期间发生异常:org/apache/ws/commons/schema/utils/NamespacePrefixList

java - 轻量级 Java Web 服务