带有嵌套标记的SOAP消息

时间:2015-03-19 15:14:55

标签: php xml soap

我需要像这样编写SOAP消息:

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope     xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
     <soapenv:Body>
        <ns1:testFunction     xmlns:ns1="namespace">
             <Tag1>
                <Tag2>
                    <field01>test1</field01>
                    <field02>test2</field02>
                    <field03>test3</field03>
                </Tag2>
            </Tag1>
        </ns1:testFunction>
    </soapenv:Body>
</soapenv:Envelope>

我写了这个PHP代码:

$array = array();
$array[] = new SoapVar('test1', XSD_STRING, null, null, 'field01');
$array[] = new SoapVar('test2', XSD_STRING, null, null, 'field02');
$array[] = new SoapVar('test3', XSD_STRING, null, null, 'field03');
$parameter = new SoapVar($array, SOAP_ENC_OBJECT, null, null, 'Tag2');
$second = array($parameter);
$Tag1Parameter = new SoapVar($second, SOAP_ENC_OBJECT, null, null, 'Tag1');
$session = $client->__soapCall('testFunction', array($parameter));

在我执行对__getLastRequest()的调用之后,我只获得了

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:ns1="namaespace/">
<SOAP-ENV:Body>
<ns1:testFunction>
<field01>test1</field01>
<field02>test2</field02>
<field03>test3</field03>
</ns1:testFunction>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

没有主标签Tag1和Tag2 ...顺便说一下,如果我在$ Tag1Parameter变量上执行var_dump,Tag1和Tag2元素就存在了,但它们没有输入SOAP消息......这个是var_dump

的输出
object(SoapVar)#8 (3) {
["enc_type"]=>int(301)
["enc_value"]=> array(1) {
    [0]=> object(SoapVar)#7 (3) {
    ["enc_type"]=>int(301)
    ["enc_value"]=> array(3) {
        [0]=> object(SoapVar)#4 (3) {
        ["enc_type"]=> int(101)
        ["enc_value"]=> string(5) "test1"
        ["enc_name"]=> string(7) "field01" }
        [1]=> object(SoapVar)#5 (3) {
        ["enc_type"]=> int(101)
        ["enc_value"]=> string(5) "test2"
        ["enc_name"]=> string(7) "field02" }
        [2]=> object(SoapVar)#6 (3) {
        ["enc_type"]=> int(101)
        ["enc_value"]=> string(5) "test3"
        ["enc_name"]=> string(7) "field03" } }
    ["enc_name"]=> string(4) "Tag2" } }
["enc_name"]=> string(4) "Tag1" }

那么......如何使标签Tag1和Tag2正确出现在SOAP消息中?

0 个答案:

没有答案