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

报告相同问题?

悬赏问题

  • ¥15 三向应力状态求剪应力
  • ¥15 jupyter notebook如何添加libGL.so.1库
  • ¥20 easyPoi能否实现下拉多选或者复选框
  • ¥15 网桥在转发帧时,会变帧的源地址和目的地址吗?
  • ¥15 用Multisim设计汽车尾灯控制电路
  • ¥100 求用matlab求解上述微分方程的程序代码
  • ¥15 MAC安装佳能LBP2900驱动的网盘提取码
  • ¥400 微信停车小程序谁懂的来
  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败