douxing2652 2011-08-26 18:02
浏览 181

如何在PHP中将对象参数传递给SOAP方法调用?

I'm trying to make a soap request and the method I'm calling takes any number of objects define by this:

<xs:complexType name="thing">
  <xs:sequence>
    <xs:element minOccurs="0" name="string1" type="xs:string"/>
    <xs:element minOccurs="0" name="string2" type="xs:string"/>
    <xs:element minOccurs="0" name="string3" type="xs:long"/>
  </xs:sequence>
</xs:complexType>

How do I create an object like that in PHP and pass it to the soap method? Right now the (not working) code I have looks like this:

$obj->string1 = 'something';
$obj->string2 = 'something';
$obj->string3 = 'something';
$param = new SoapParam(new SoapVar($obj, SOAP_ENC_OBJECT, 'method', 'http://ns'), 'paramName');

$soapClient->method($param);

UPDATE:

This is the body of the request of the shown method:

<SOAP-ENV:Body>
  <ns2:method xsi:type="ns1:method">
    <string1>something</string1>
    <string2>something</string2>
    <string3>something</string3>
  </ns2:placeHolds>
</SOAP-ENV:Body>

If I just pass $obj instead of creating a SoapParam, this is the body in the request:

<SOAP-ENV:Body>
  <ns1:method/>
</SOAP-ENV:Body>
  • 写回答

1条回答 默认 最新

  • down00111 2014-02-15 06:17
    关注
    $client = new SoapClient('endpoint');
    
    $sequence->string1 = 'something';
    $sequence->string2 = 'something';
    $sequence->string3 = 'something';
    
    $obj = array();
    $obj['sequence'] = $sequence;
    
    $param = new SoapParam(new SoapVar($obj, SOAP_ENC_OBJECT), 'paramName');
    
    $client->__soapCall('method',array($param));
    
    评论

报告相同问题?

悬赏问题

  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件