Array response with single element fails

Help
2010-06-25
2013-06-06
  • Jesper Skytte

    Jesper Skytte - 2010-06-25

    Hi everybody,

    FIrst: Is there any way to search the forums? I've looked and looked, but can't seem to find a search button or search field.

    Next: My problem:

    I'm requesting data from a soap server and getting the response back - no problem. My problem arises when NuSOAP parses and returns the array with data. If there are more than one elements returned, they are correctly returned as they should:

    array(3) {
      [0]=>
      array(2) {
        ["Id"]=>
        string(6) "803001"
        ["Name"]=>
        string(6) "Item 1"
      }
      [1]=>
      array(2) {
        ["Id"]=>
        string(6) "803002"
        ["Name"]=>
        string(6) "Item 2"
      }
      [2]=>
      array(2) {
        ["Id"]=>
        string(6) "803003"
        ["Name"]=>
        string(6) "Item 3"
      }
    }
    

    But if there is only returned one element, this element is not returned in an numerical indexed array, but as a single item:

    array(2) {
      ["Id"]=>
      string(6) "803001"
      ["Name"]=>
      string(6) "Item 1"
    }
    

    Instead of - as I would believe

    array(1) {
      [0]=>
      array(2) {
        ["Id"]=>
        string(6) "803001"
        ["Name"]=>
        string(6) "Item 1"
      }
    }
    

    The response type is defined as follows in my WSDL file:

    <?xml version='1.0' encoding='UTF-8'?>
    <s0:definitions name="InfoDefinitions" targetNamespace="https://mydomain.dk" xmlns="" xmlns:s0="http://schemas.xmlsoap.org/wsdl/" xmlns:s1="https://mydomain.dk" xmlns:s2="http://schemas.xmlsoap.org/wsdl/soap/">
      <s0:types>
        <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="https://mydomain.dk" xmlns:s0="http://schemas.xmlsoap.org/wsdl/" xmlns:s1="mydomain.dk" xmlns:s2="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
          <xs:import namespace="java:com.example.webservice.returTyper"/>
          <xs:complexType name="ArrayOfMyType_literal">
            <xs:sequence>
              <xs:element maxOccurs="unbounded" minOccurs="0" name="MyType" nillable="true" type="java:MyType" xmlns:java="java:com.example.webservice.returTyper"/>
            </xs:sequence>
          </xs:complexType>
          <xs:element name="ArrayOfMyType_literal" type="inf:ArrayOfMyType_literal" xmlns:inf="https://mydomain.dk"/>
          <xs:element name="getMyTypes">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="user" type="xs:string"/>
                <xs:element name="pass" type="xs:string"/>
                <xs:element name="typea" type="xs:string"/>
                <xs:element name="typeb" type="xs:string"/>
                <xs:element name="typec" type="xs:string"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
          <xs:element name="getMyTypesResponse">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="return" type="inf:ArrayOfMyType_literal" xmlns:inf="https://mydomain.dk"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:schema>
      </s0:types>
      <s0:message name="getMyTypes">
        <s0:part element="s1:getMyTypes" name="parameters"/>
      </s0:message>
      <s0:message name="getMyTypesResponse">
        <s0:part element="s1:getMyTypesResponse" name="parameters"/>
      </s0:message>
      <s0:portType name="InfoPort">
        <s0:operation name="getMyTypes" parameterOrder="parameters">
          <s0:input message="s1:getMyTypes"/>
          <s0:output message="s1:getMyTypesResponse"/>
        </s0:operation>
      </s0:portType>
      <s0:binding name="InfoSoapBinding" type="s1:InfoPort">
        <s2:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <s0:operation name="getMyTypes">
          <s2:operation soapAction="" style="document"/>
          <s0:input>
            <s2:body parts="parameters" use="literal"/>
          </s0:input>
          <s0:output>
            <s2:body parts="parameters" use="literal"/>
          </s0:output>
        </s0:operation>
      </s0:binding>    
      <s0:service name="Info">
        <s0:port binding="s1:InfoSoapBinding" name="InfoPort">
          <s2:address location="https://mydomain.dk:443/info-ws/ws"/>
        </s0:port>
      </s0:service>
    </s0:definitions>
    

    Can anyone tell me if NuSOAP is handling the response correct or if it parses my WSDL file incorrectly?

    Best regards - and thanks in advance!!
    /Jesper

     
  • Scott Nichol

    Scott Nichol - 2010-06-25

    What you are experiencing is the expected behavior of NuSOAP, even though it is incorrect.  It is a known deficiency of NuSOAP which arises because NuSOAP does not use the WSDL to de-serialize XML, only to serialize it.  The workaround is to write your SOAP client code to handle both of the ways that NuSOAP presents the return value to you.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks