SOAP Client and Array problem
Posted: Tue Mar 16, 2010 6:55 pm
Folks,
Has anyone had to deal with sending arrays of complex XML elements as part of a SOAP message?
I'm attempting to use PHP's SoapClient to call a function on a remote server. The server's XML schema specifies the input type to the function as taking a complex type comprised of a couple elements. One of the elements is an array element, which encapsulates an unbounded array of another particular complex type.
My issue is that whenever I attempt to create an array of elements of the inner type, I get empty elements. I create a PHP stdObject to encapsulate the SOAP message as such:
Yet I get the following in my SOAP request:
The above XML shows that the AnswerContainer element is empty. It should have an Answer element in each one. Going back to the code, if I have only one AnswerContainer in the array, the same thing happens just with one empty AnswerContainer element. If I create just one AnswerContainer with no array and set Answers to just a single AnswerContainer, everything looks as expected and the SOAP call goes through.
I can't control the schema, but I've poured over documentation and can verify that the schema defines the array properly. I've tried using SoapVars instead, having found some cool suggestions on PHP.net, but SoapVars only introduce other problems specifically related to the array of AnswerContainer.
Has anyone encountered this issue before? Is this a shortcoming with PHP's SoapClient? I find it unlikely that PHP wouldn't be able to handle an array of elements, and I really don't want to pull out Java to do this. Seems like Java would be way to much of a headache for such a simple task.
Any ideas?
Has anyone had to deal with sending arrays of complex XML elements as part of a SOAP message?
I'm attempting to use PHP's SoapClient to call a function on a remote server. The server's XML schema specifies the input type to the function as taking a complex type comprised of a couple elements. One of the elements is an array element, which encapsulates an unbounded array of another particular complex type.
My issue is that whenever I attempt to create an array of elements of the inner type, I get empty elements. I create a PHP stdObject to encapsulate the SOAP message as such:
Code: Select all
$container1->AnswerContainer->Answer = "answer1";
$container2->AnswerContainer->Answer = "answer2";
$soapMsg->Answers = array( $container1, $container2 );
$soapMsg->QuestionId = 1;
Code: Select all
<ns1:QuestionId>1</ns1:QuestionId>
<ns1:Answers>
<ns1:AnswerContainer />
<ns1:AnswerContainer />
</ns1:Answers>
Code: Select all
<ns1:QuestionId>1</ns1:QuestionId>
<ns1:Answers>
<ns1:AnswerContainer>
<ns1:Answer>answer1</ns1:Answer>
</ns1:AnswerContainer>
</ns1:Answers>
Has anyone encountered this issue before? Is this a shortcoming with PHP's SoapClient? I find it unlikely that PHP wouldn't be able to handle an array of elements, and I really don't want to pull out Java to do this. Seems like Java would be way to much of a headache for such a simple task.
Any ideas?