PHP SOAP:使用相同的名称传递相同的参数

时间:2018-10-27 08:25:54

标签: php api soap soap-client

我无法使它正常工作。我已经在论坛上阅读过很多内容,但似乎无法找到解决方案。

我创建了一个SOAP调用及其工作方式,但是当我尝试多次传递相同的参数时,它只是覆盖自己,这是合乎逻辑的。

该代码仅需使用对象完成,因此我使用了stdClass()

以下代码示例:

$relationCreate = new stdClass();

$relationCreate->credentials = new stdClass();
$relationCreate->credentials->ApiKey = ''; //Removed for security reasons.
$relationCreate->credentials->DatabaseId = ''; //Removed for security reasons.;
$relationCreate->credentials->UserId = ''; //Removed for security reasons.;

$relationCreate->parentRelationId = $company;
$relationCreate->relationEntityTypeId = "84a15869-5b88-49df-ad47-7b6f9648ae07";

//surname
$relationCreate->relationFieldValues = new stdClass();
$relationCreate->relationFieldValues->PvFieldValueData = new stdClass();
$relationCreate->relationFieldValues->PvFieldValueData->Id = "9d549512-dc8a-4774-84d1-27a349e8a8c7";
$relationCreate->relationFieldValues->PvFieldValueData->Value = $name;

// This one has to repeat wich does not work. Wich is logical
$relationCreate->relationFieldValues = new stdClass();
$relationCreate->relationFieldValues->PvFieldValueData = new stdClass();
$relationCreate->relationFieldValues->PvFieldValueData->Id = "9d549512-dc8a-4774-84d1-27a349e8a8c7";
$relationCreate->relationFieldValues->PvFieldValueData->Value = $name;

肥皂的外观应如下所示,我使用SoapUI对其进行了测试:

<api:fieldValues>
    <!--Zero or more repetitions:-->
    <api:PvFieldValueData>
        <api:Id>c2fcb464-92e6-4227-8672-56f88e219279</api:Id>
        <!--Optional:-->
        <api:Value>Test</api:Value>
    </api:PvFieldValueData>
</api:fieldValues>

<api:fieldValues>
<!--Zero or more repetitions:-->
<api:PvFieldValueData>
    <api:Id>d900fe23-8549-451c-82f4-c5918cb3abbb</api:Id>
    <!--Optional:-->
    <api:Value>Test</api:Value>
</api:PvFieldValueData>
</api:fieldValues>

供参考的WSDL文件:https://api.perfectview.nl/V1/perfectview.asmx?WSDL

参考: PHP SoapClient - Multiple attributes with the same key

SoapClient: how to pass multiple elements with same name?

1 个答案:

答案 0 :(得分:0)

您可以尝试将项目放入数组中。

示例:

$relationCreate->relationFieldValues = [];

// repeat this in a foreach loop:
$item = new stdClass();
$item->PvFieldValueData = new stdClass();
$item->PvFieldValueData->Id = $uuid;
$item->PvFieldValueData->Value = $name;

// Add item to values
$relationCreate->relationFieldValues[] = $item;