Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

xml - Node-soap: How to create a complex message with specific attributes?

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"
        }

Which results this:

<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>

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

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

Any help will be appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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'
                    ]
                }
            }
        }
    }    
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...