dsfdsf23423 2012-08-06 07:34
浏览 50
已采纳

如何在php中为soapclient构建KeyValuePair

In my case of SoapClient, the request XML should look like this:

<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope">
<SOAP-ENV:Body>
    <SoapFunction xmlns="http://services.***/">
        <prop1>value1</prop1>
        <prop2>value2</prop2>
        <prop3>
            <KeyValuePair>
                <Key>string</Key>
                <Value>string</Value>
            </KeyValuePair>
            <KeyValuePair>
                <Key>string</Key>
                <Value>string</Value>
            </KeyValuePair>
        </prop3>
    </SoapFunction>
</SOAP-ENV:Body>
</sSOAP-ENV:Envelope>

I could build prop1 and prop2 correctly by the following code:

$parameters = array(
    'prop1' => value1,
    'prop2' => value2
);
$request = array($parameters);
$client->__soapCall('SoapFunction', $request);

But how could i build property prop3, especially construct type KeyValuePair which is defined in the WSDL file

  • 写回答

3条回答 默认 最新

  • dongxi2014 2012-08-07 01:17
    关注

    According the definition in WSDL file

    <s:complexType name="KeyValuePair">
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="Key" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="Value" type="s:string" />
        </s:sequence>
    </s:complexType>
    

    I created a new class KeyValuePair which has the property 'Key' and 'Value'. Then i could use a SoapVar to be the prop3 like this

    $kvp1= new SoapVar(new KeyValuePair('key1', 'value1'), XSD_ANYTYPE, 'KeyValuePair');
    $kvp2= new SoapVar(new KeyValuePair('key2', 'value2'), XSD_ANYTYPE, 'KeyValuePair');
    $parameters = array(
        'prop1' => value1,
        'prop2' => value2,
        'prop3' => array($kvp1, $kvp2)
    );
    $request = array($parameters);
    $client->__soapCall('SoapFunction', $request);
    

    BTW: If the generated request xml has litter difference with one you desired, you could override the __doRequest of SoapClient to do some preg_replace etc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值