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 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度