Node-soap:如何创建具有特定属性的复杂消息? [英] Node-soap: How to create a complex message with specific attributes?

查看:24
本文介绍了Node-soap:如何创建具有特定属性的复杂消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我需要发送给 wsdl 的消息:

This is the message I need to send to wsdl:

<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://WSDLPROVIDER" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:enqueue>
            <domain xsi:type="xsd:string">STH</domain>
            <messageBodies SOAP-ENC:arrayType="xsd:string[1]" xsi:type="SOAP-ENC:Array">
                <item xsi:type="xsd:string">STHE</item>
            </messageBodies>
            <recipientNumbers SOAP-ENC:arrayType="xsd:string[2]" xsi:type="SOAP-ENC:Array">
                <item xsi:type="xsd:string">09xxxxxxxx</item>
                <item xsi:type="xsd:string">09xxxxxxxx</item>
            </recipientNumbers>
            <senderNumbers SOAP-ENC:arrayType="xsd:string[1]" xsi:type="SOAP-ENC:Array">
                <item xsi:type="xsd:string">3000xxxxx</item>
            </senderNumbers>
            <encodings xsi:nil="true" xsi:type="SOAP-ENC:Array" />
            <udhs xsi:nil="true" xsi:type="SOAP-ENC:Array" />
            <messageClasses xsi:nil="true" xsi:type="SOAP-ENC:Array" />
            <priorities xsi:type="SOAP-ENC:Array" />
            <checkingMessageIds SOAP-ENC:arrayType="xsd:long[2]" xsi:type="SOAP-ENC:Array">
                <item xsi:type="xsd:long">100</item>
                <item xsi:type="xsd:long">101</item>
            </checkingMessageIds>
        </ns1:enqueue>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

到目前为止,我已经做到了:

And so far, I've made this:

var args = {
    domain: 'STHE',
    messageBodies: {
        item: {
            attributes: {
                'xsi:type': 'xsd:string'
            },
            $value: "hi"
        }
    },
    "recipientNumbers": {
        attributes:{
            "SOAP-ENC:arrayType": "xsd:string[2]",
            "xsi:type": "SOAP-ENC:Array"
        },
        "item": {
            attributes:{
                "xsi:type": "xsd:string"
            },
            $value: "09xxxxxx"
        }
    },
    "senderNumbers": {
        attributes:{
            "SOAP-ENC:arrayType": "xsd:string[1]",
            "xsi:type": "SOAP-ENC:Array"
        },
        "item": {
            attributes: {
                "xsi:type": "xsd:string"
            },
            $value: "30xxxxx"
        }

结果如下:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:impl="WSDLPROVIDER" xmlns:intf="WSDLPROVIDER" xmlns:tns1="urn:SOAPSmsQueue">
    <soap:Header></soap:Header>
    <soap:Body>
        <impl:enqueue>
            <domain>STHE</domain>
            <messageBodies>
                <item xsi:type="xsd:string">hi</item>
            </messageBodies>
            <recipientNumbers>
                <item xsi:type="xsd:string">09xxxxxx</item>
            </recipientNumbers>
            <senderNumbers>
                <item xsi:type="xsd:string">30xxxxx</item>
            </senderNumbers>
        </impl:enqueue>
    </soap:Body>
</soap:Envelope>

我尝试在 messageBodies 部分使用属性,但我使用的任何组合都失败了,输出没有任何变化.

I tried to use attributes on messageBodies part, but any combination I used failed with no change in the output.

有没有什么办法可以在XML而不是Json接口中传递消息?

Is there any way to pass the message in XML instead of Json interface?

任何帮助将不胜感激.

推荐答案

假设 enqueue 是 WSDL 中定义的 SOAP 方法,并且您是从 node-soap-created 客户端调用它,我会采用类似的方法:

Assuming that enqueue is a SOAP method defined in the WSDL and you're calling it from the node-soap-created client, I would go with something like:

args: {
    attributes: {
        'xmlns:xsd':'http://www.w3.org/2001/XMLSchema',
        'xmlns:xsi':'http://www.w3.org/2001/XMLSchema-instance',
        'xmlns:SOAP-ENC':'http://schemas.xmlsoap.org/soap/encoding/'
    },
    $value: {
        'domain': {
            attributes: {'xsi:type':'xsd:string'},
            $value: 'STH'
        },
        'messageBodies': {
            attributes: {
                'SOAP-ENC:arrayType':'xsd:string[1]',
                'xsi:type':'SOAP-ENC:Array'
            },
            $value: {
                'item': {
                    attributes: {'xsi:type':'xsd:string'},
                    $value: [
                        'STHE'
                    ]
                }
            }
        },
        'recipientNumbers': {
            attributes: {
                'SOAP-ENC:arrayType':'xsd:string[2]',
                'xsi:type':'SOAP-ENC:Array'
            },
            $value: {
                'item': {
                    attributes: {'xsi:type':'xsd:string'},
                    $value: [
                        '09xxxxxxxx',
                        '09xxxxxxxx'
                    ]
                }
            }
        },
        'senderNumbers': {
            attributes: {
                'SOAP-ENC:arrayType':'xsd:string[1]',
                'xsi:type':'SOAP-ENC:Array'
            },
            $value: {
                'item': {
                    attributes: {'xsi:type':'xsd:string'},
                    $value: [
                        '3000xxxxx'
                    ]
                }

            }
        },
        'encodings': {
            attributes: {
                'xsi:nil':'true',
                'xsi:type':'SOAP-ENC:Array'
            }
        },
        'udhs': {
            attributes: {
                'xsi:nil':'true',
                'xsi:type':'SOAP-ENC:Array'
            }
        },
        'messageClasses': {
            attributes: {
                'xsi:nil':'true',
                'xsi:type':'SOAP-ENC:Array'
            }
        },
        'priorities': {
            attributes: {
                'xsi:type':'SOAP-ENC:Array'
            }
        },
        'checkingMessageIds': {
            attributes: {
                'SOAP-ENC:arrayType':'xsd:long[2]',
                'xsi:type':'SOAP-ENC:Array'
            },
            $value: {
                'item': {
                    attributes: {'xsi:type':'xsd:long'},
                    $value: [
                        '100',
                        '101'
                    ]
                }
            }
        }
    }    
}

这篇关于Node-soap:如何创建具有特定属性的复杂消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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