不必要的& lt; param0>从PHP SoapClient非wsdl模式


Unwanted <param0> node from PHP SoapClient non-wsdl mode

我试图在非wsdl模式下使用PHP SoapClient发出请求。我将参数作为多维对象传递,如下面的代码片段所示:

$params = new stdClass;
$params->Characteristic = new stdClass;
$params->Characteristic->Name = 'PRODUCT_TYPE';
$params->Characteristic->CharacteristicValue = new stdClass;
$params->Characteristic->CharacteristicValue->Value = $type;
$params->Characteristic->CharacteristicValue->Type = 'STRING';
$client = new SoapClient(NULL, array(   'trace' => true,  'exceptions' => true, 'uri' => $uri, 'location' => $location,
        'connection_timeout'=>9999, 
        'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 
        'soap_version' => SOAP_1_1, 'encoding' => 'ISO-8859-1', 
        'use' => SOAP_LITERAL
    ));
$response = $client->thisIsTheFunction($params);

生成的XML几乎是正确的,除了被包装在一个标签:

<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://[removed]">
    <soap-env:body>
        <ns1:thisisthefunction>
            <param0>
                <characteristic>
                    <name>PRODUCT_TYPE</name>
                    <characteristicvalue>
                        <value>Adhoc</value>
                        <type>STRING</type>
                    </characteristicvalue>
                </characteristic>
            </param0>
        </ns1:thisisthefunction>
    </soap-env:body>
</soap-env:envelope>

问题是服务检测到这是错误的。我们有没有办法去掉这个额外的标签?

我认为如果你想删除param0,并把characteristicValue在这个地方,你需要使用一个SoapParam (http://www.php.net/manual/en/class.soapparam.php)。

实际上,您的调用必须这样进行:

$response = $client->thisIsTheFunction(new SoapParam($params->Characteristic, 'ns1:Characteristic'));
现在,生成的XML如下所示:
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://[removed]">
<soap-env:body>
    <ns1:thisisthefunction>
        <ns1:characteristic>
            <name>PRODUCT_TYPE</name>
            <characteristicvalue>
                <value>Adhoc</value>
                <type>STRING</type>
             </characteristicvalue>
        </ns1:characteristic>
    </ns1:thisisthefunction>
</soap-env:body>