如何使用php从具有复杂类型的wsdl获取响应


How to get response from wsdl with complex Type using php

请帮帮我。我有一个wsdl,上面有这样的复杂类型示例:

<WL5G3N0:definitions name="commandModificationiSiska">
  <xsd:complexType name="Input">
    <xsd:sequence>
      <xsd:element minOccurs="0" name="dn" nillable="true" type="xsd:string"/>
      <xsd:element name="ptOffer" nillable="true" type="tns:ptOffer"/>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="ptOffer">
    <xsd:sequence>
      <xsd:element maxOccurs="unbounded" name="array" nillable="true" type="tns:array"/>
    </xsd:sequence>
  </xsd:complexType>
  <xsd:complexType name="array">
    <xsd:sequence>
      <xsd:element name="itemTyp" nillable="true" type="xsd:string"/>
      <xsd:element name="itemCode" nillable="true" type="xsd:string"/>
      <xsd:element name="itemRefPack" nillable="true" type="xsd:string"/>
    </xsd:sequence>
  </xsd:complexType>

事实上,我在这个链接中找到了一个解决方案。在那个环节与我的问题相似,但仍然不起作用。

这是我在中编写的php脚本

error_reporting(E_ALL);
ini_set('display_errors', 1);
$param = new StdClass();
$param->array = new StdClass();
$param->input = new StdClass();
$param->input->dn = "XX2042XXXX";
$param->array->itemTyp = "2";
$param->array->itemcode = "AUTOCON2";
$param->array->itemRefPack = "";
$wsdl_file =  "test.wsdl";
  $client = new SoapClient($wsdl_file,array("trace"=> 1,"exceptions" => 0,"cache_wsdl" => 0));
  print_r($client->commandModificationiSiska($param));
  echo "<br/>================<br/>";
  echo "<p>Request :".htmlspecialchars($client->__getLastRequest()) ."</p>";
  echo "<p>Response:".htmlspecialchars($client->__getLastResponse())."</p>";

也许某个地方已经解决了这个问题,可以在这里帮助我。。

问题已解决。非常简单的解决方案。输入已分离两个参数:

  1. dn

  2. ptoffer

    "ptoffer"分隔在3个输入参数中,用"array"命名。"array"有3个参数,分别是itemCode、itemtyp和itemrefpack。这就是重点。

我只需要从wsdl文件中获取响应就可以了。

$client=新SoapClient($wsdl_file,数组("trace"=>1,"exceptions"=>0,"cache_wsdl"=>0));

print_r( $client->commandModificationiSiska(array(
                                                "dn" => "1222XXX",
                                                "ptOffer" => array('array' => array("itemTyp" => 2,
                                                                  "itemCode" => "blabla",
                                                                  "itemRefPack" => ""
                                                                  ))
                                                )));