如何生成以下 SOAP XML 请求?

How to generate the following SOAP XML request?

我正在使用的 SOAP API,需要格式如下的请求 XML:

<SOAP-ENV:Body>
    <ns1:functionName/>
        <UserID>WEB</UserID>
        <Attribute>
            <ID>83</ID>
            <Value>34343</Value>
        </Attribute>
        <Attribute>
            <ID>84</ID>
            <Value>45343</Value>
        </Attribute>
</SOAP-ENV:Body>

我已经在 Whosebug 上解决了几乎所有 "multiple element" 相关问题,但仍然无法弄清楚。

这是我目前正在尝试的:

$args = new ArrayObject();
$args->UserID = WEB;

$Attribute = new stdClass();
$Attribute->ID = 83;
$Attribute->Value = 34343;
$args->append(new SoapParam($Attribute, 'Attribute'));

$Attribute = new stdClass();
$Attribute->ID = 84;
$Attribute->Value = 45343;
$args->append(new SoapParam($Attribute, 'Attribute'));

$soapClient->functionName($args);

有人可以帮我解决这个问题吗?

我建议您使用 WSDL to php 生成器,因为您将处理与所需参数和操作匹配的抽象 类,因此您不必弄清楚正确的语法,它将由生成的包自动完成。

两台发电机:

祝你好运

终于想通了。希望以下代码对某人有所帮助:

$args = array();
$args[] = new SoapVar('WEB', XSD_STRING, null, null, 'UserID');

$obj = new stdClass();
$obj->ID = 83;
$obj->Value = 34343;
$args[] = new SoapVar($obj, SOAP_ENC_OBJECT, null, null, 'Attribute');

$obj = new stdClass();
$obj->ID = 84;
$obj->Value = 45343;
$args[] = new SoapVar($obj, SOAP_ENC_OBJECT, null, null, 'Attribute');

$soapClient->functionName(new SoapVar($args, SOAP_ENC_OBJECT));