dsns47611 2018-10-27 08:25
浏览 43
已采纳

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

I cant get this to work. I've read a bunch on it on the forum already but I just cant seem to find the solution to this.

I've created a SOAP call and its working etc but when I try to pass the same parameters multiple times it just overwrites itself wich is logical.

The code has to be done with objects only so i've used stdClass()

Example of the code below:

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

The soap should look as followed I tested this using 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 file for reference: https://api.perfectview.nl/V1/perfectview.asmx?WSDL

References: PHP SoapClient - Multiple attributes with the same key

SoapClient: how to pass multiple elements with same name?

  • 写回答

1条回答 默认 最新

  • duanshangying5102 2018-10-29 10:48
    关注

    You can try to put the items into an array.

    Example:

    $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; 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?