douchang8758 2018-05-05 09:23
浏览 80

PHP SOAP-ERROR:对象没有'test2'属性

I have the following xml from part of an auto generated web service wsdl:

  <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>

when I do a soap call from php:

  $xml = "test.xml";
  $params = array(
    'test' => array(
      'txt' =>  $txt
    )
  );
  try {
    $client = new SoapClient($xml);
    $test = $client->request_box($params);
  } catch (SoapFault $fault) {
    var_dump($fault);
  }

I get this error:

SOAP-ERROR: Encoding: object has no 'test2' property

If I change $params and add test2 to it then I dont get any erros:

  $params = array(
    'test' => array(
      'txt' =>  $txt
    ),
    'test2' => array(
      'txt' =>  $txt
    )
  );

But I want test2 to be optional.

If I change xml and add minOccurs="0" to test2 the problem will be solved and I dont get any errors anymore:

 <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>

But should't all the child elements (here test and test2) already inherit minOccurs="0" from the parent <xs:all minOccurs="0"> ?

  • 写回答

1条回答 默认 最新

  • dongqie4402 2018-05-07 04:00
    关注
    <xs:all minOccurs="0">
    

    The xs:all minOccurs is for the whole group, not for elements. So the behavior you are experiencing is correct.

    General suggestion: Use some tool (like SOAPUI, Altova XML Spy(paid)) to validate the XML before testing from a programming language. It will save a lot of time.

    Similar question: How do I make items optional in <xs:all>?

    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探