Experience with SoapClient, and nested ArrayOf...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Sofw_Arch_Dev
Forum Commoner
Posts: 60
Joined: Tue Mar 16, 2010 4:06 pm
Location: San Francisco, California, US

Experience with SoapClient, and nested ArrayOf...

Post by Sofw_Arch_Dev »

Folks,

Does anyone have experience using SoapClient to send nested arrays of data to a web service? I've been experiencing a problem that I can't seem to figure out. I've poured over PHP.net for info on Soap, researched WSDL to make sure my 3'rd party service provider's web-service is defined properly, and tried three different approaches to putting this outgoing soap call together but to no avail. What's happening is that the inner array of elements is getting populated with empty elements. Here's a snippet of wsdl:

Code: Select all

 
<s:element name="SurveyResponseInsert">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="SurveyId" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="Questions" type="tns:ArrayOfQuestionContainer" />
          </s:sequence>
        </s:complexType>
</s:element>
      
<s:complexType name="ArrayOfQuestionContainer">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="unbounded" name="QuestionContainer" type="tns:QuestionContainer" />
        </s:sequence>
</s:complexType>
      
<s:complexType name="QuestionContainer">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="1" name="QuestionId" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="Answers" type="tns:ArrayOfAnswerContainer" />
        </s:sequence>
</s:complexType>
 
<s:complexType name="ArrayOfAnswerContainer">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="unbounded" name="AnswerContainer" type="tns:AnswerContainer" />
        </s:sequence>
</s:complexType>
      
      <s:complexType name="AnswerContainer">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="1" name="Answer" type="s:string" />
        </s:sequence>
      </s:complexType>
 
I expect to send a SurveyResponseInsert element containing an array of QuestionContainer, each of which having an Answers element containing an array of AnswerContainer which contains an Answer element. Like so:

Code: Select all

 
    <ns1:SurveyResponseInsert>
      <ns1:SurveyId>2</ns1:SurveyId>
      <ns1:Questions>
        <ns1:QuestionContainer>
          <ns1:QuestionId>14</ns1:QuestionId>
          <ns1:Answers>
            <ns1:AnswerContainer>
              <ns1:Answer>answer1</ns1:Answer>
            </ns1:AnswerContainer>
            <ns1:AnswerContainer>
              <ns1:Answer>answer2</ns1:Answer>
            </ns1:AnswerContainer>
          </ns1:Answers>
        </ns1:QuestionContainer>
      </ns1:Questions>
    </ns1:SurveyResponseInsert>
 
What I get is this when I ask my SoapClient for it's getLastRequest()

Code: Select all

 
    <ns1:SurveyResponseInsert>
      <ns1:SurveyId>2</ns1:SurveyId>
      <ns1:Questions>
        <ns1:QuestionContainer>
          <ns1:QuestionId>14</ns1:QuestionId>
          <ns1:Answers>
            <ns1:AnswerContainer/>
            <ns1:AnswerContainer/>
          </ns1:Answers>
        </ns1:QuestionContainer>
      </ns1:Questions>
    </ns1:SurveyResponseInsert>
 
I've tried using nested arrays to set the data for the message, stdClasses and SoapVars but nothing seems to be working around this. Has anyone else experienced this problem, or something similar?
Post Reply