Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP SOAP-ERROR:对象没有';测试2';财产_Php_Xml_Wsdl_Soap Client - Fatal编程技术网

PHP SOAP-ERROR:对象没有';测试2';财产

PHP SOAP-ERROR:对象没有';测试2';财产,php,xml,wsdl,soap-client,Php,Xml,Wsdl,Soap Client,我从自动生成的web服务wsdl中获得了以下xml: <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="test"> <xs:element name="test"> <xs:complexType> <xs:sequence> &l

我从自动生成的web服务wsdl中获得了以下xml:

  <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="test">
     <xs:element name="test">
        <xs:complexType>
           <xs:sequence>
              <xs:element name="txt" nillable="true" type="xs:string"/>
           </xs:sequence>
        </xs:complexType>
     </xs:element>
     <xs:element name="test2">
        <xs:complexType>
           <xs:sequence>
              <xs:element name="txt" nillable="true" type="xs:string"/>
           </xs:sequence>
        </xs:complexType>
     </xs:element>
     <xs:element name="request_box">
        <xs:complexType>
           <xs:all minOccurs="0">
              <xs:element ref="ns0:test"/>
              <xs:element ref="ns0:test2"/>
           </xs:all>
        </xs:complexType>
     </xs:element>
  </xs:schema>
我得到这个错误:

SOAP-ERROR: Encoding: object has no 'test2' property
如果我更改
$params
并向其添加
test2
,则不会出现任何错误:

  $params = array(
    'test' => array(
      'txt' =>  $txt
    ),
    'test2' => array(
      'txt' =>  $txt
    )
  );
但是我希望
test2
是可选的

如果我更改xml并将
minOccurs=“0”
添加到
test2
中,问题将得到解决,并且不再出现任何错误:

 <xs:element name="request_box">
    <xs:complexType>
       <xs:all minOccurs="0">
          <xs:element ref="ns0:test"/>
          <xs:element ref="ns0:test2" minOccurs="0"/>
       </xs:all>
    </xs:complexType>
 </xs:element>

但是,难道所有的子元素(这里是
test
test2
)都不应该从父元素继承
minOccurs=“0”


xs:all minOccurs用于整个组,而不是元素。所以你所经历的行为是正确的

一般建议:在从编程语言进行测试之前,使用一些工具(如SOAPUI、Altova XML Spy(付费))验证XML。这将节省很多时间

类似问题:

 <xs:element name="request_box">
    <xs:complexType>
       <xs:all minOccurs="0">
          <xs:element ref="ns0:test"/>
          <xs:element ref="ns0:test2" minOccurs="0"/>
       </xs:all>
    </xs:complexType>
 </xs:element>
<xs:all minOccurs="0">