Node.js SOAP客户端参数格式 [英] Node.js SOAP client parameter formatting

查看:179
本文介绍了Node.js SOAP客户端参数格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用将node.js作为客户端的node-soap模块正确格式化一个特定的soap参数到第三方SOAP服务.

I'm having trouble properly formatting one particular soap parameter using the node-soap module for node.js as a client, to a 3rd-party SOAP service.

此方法的client.describe()表示此特定输入应采用以下形式:

The client.describe() for this method says this particular input should be in the shape of:

params: { 'param[]': {} }

我尝试了多种不同的JSON表示法,以尝试使我的数据适合该形状. 无效的格式示例:

I have tried a bunch of different JSON notations to try to fit my data to that shape. Examples of formats that do NOT work:

"params": { "param": [ {"myParameterName": "myParameterValue"} ] }
"params": [ "param": { "name": "myParameterName", "_": "myParameterValue"} ]
"params": { "param" : [ {"name": "myParameterName", "_": "myParameterValue"} ] }
"params": { "param[]": {"myParameterName": "myParameterValue" } }
"params": { "param[myParameterName]": {"_": "myParameterValue" } }

我一定是在俯视一些事情,而且当一些好人指出我做错事情时,我怀疑我会感觉像上尉队长.

I must be overlooking something, and I suspect I'm going to feel like Captain Obvious when some nice person points out what I'm doing wrong.

这是使用其他soap客户端的工作原理,以及它们如何处理带有值的命名参数"

Here is what DOES work, using other soap clients, and how they handle the "named parameter with a value"

此方法的soapUI通过XML以以下形式成功接受此特定输入:

soapUI for this method successfully accepts this particular input via XML in the shape of:

<ns:params>
    <ns:param name="myParameterName">myParameterValue</ns:param>
</ns:params>

此外,使用PHP,我可以通过创建如下数组的stdClass来成功进行调用:

Also, using PHP, I can successfully make the call by creating a stdClass of arrays like so:

$parms = new stdClass;
$parms->param = array(
    array(
        "name"=>"myParameterName","_"=>"myParameterValue"
    )
);

,然后最终通过

'params' => $parms 

到PHP soap客户端

to the PHP soap client

非常感谢!

推荐答案

为更好地了解node-soap生成的XML,我向node_modules/soap/lib添加了console.log(message)语句/client.js在对象到XML编码之后.然后,我开始尝试各种JSON结构,以凭经验找出它们是如何映射到XML结构的.

To get a better look at what XML was being generated by node-soap, I added a console.log(message) statement to the node_modules/soap/lib/client.js after the object-to-XML encoding. I then began experimenting with various JSON structures to figure out empirically how they were mapping to XML structures.

我找到了一个用于node-soap的JSON结构,以生成我的第三方所需的named-parameter-with-value格式的XML.我完全不知道"$ value"特殊关键字.从2014年6月中旬开始,似乎已在0.4.6版本中添加了此内容.请参见

I found a JSON structure for node-soap to generate the XML in my 3rd-party's required named-parameter-with-value format. I was completely unaware of the "$value" special keyword. Looks like this may have been added in the 0.4.6 release from mid-June 2014. See the change history

"params": [
  { 
    "param": {
       "attributes": {
          "name": "myParameterName"
       },
       $value: "myParameterValue"
    } 
  }
]

(请注意外部数组,这使我可以指定多个"param"条目,而这种特殊的第三方API有时需要此条目)

(note the outer array, which gives me the luxury of specifying multiple "param" entries, which is sometimes needed by this particular 3rd-party API)

生成此XML:

<tns:params>
  <tns:param name="myParameterName">myParameterValue</tns:param>
</tns:params>

它与soapUI(我已经知道的工作原理)的结构完全匹配:

which perfectly matches the structure in soapUI (which I already knew worked) of:

<ns:params>
    <ns:param name="myParameterName">myParameterValue</ns:param>
</ns:params>

这篇关于Node.js SOAP客户端参数格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆