如何生成以下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>

我已经在StackOverflow上浏览了几乎所有与"多元素"相关的问题,但仍然无法解决。

这是我现在正在尝试的:

$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到php生成器,因为您将处理与所需参数和操作相匹配的抽象类,因此您不必找出正确的语法,它将由生成的包自动完成。

两个发电机:

  • 我:https://github.com/WsdlToPhp/PackageGenerator
  • 来自其他:https://github.com/wsdl2phpgenerator/wsdl2phpgenerator
好运

终于想明白了。希望下面的代码对大家有所帮助:

$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));