在SOAP调用中传递PHP数组

时间:2009-08-27 02:32:50

标签: php xml arrays soap

所以我试图在我的SOAP请求中包含以下XML:

<Responses>
    <Response>
        <QuestionAnswerID>someint</QuestionAnswerID>
        <QuestionID>someint</QuestionID>
    </Response>
    <Response>
        <QuestionAnswerID>someint</QuestionAnswerID>
        <QuestionID>someint</QuestionID>
    </Response>
</Responses>

我看了this帖子,这个帖子含糊不清,但产生的输出如下:

object(stdClass)#1 (1) {
    ["Responses"]=>
    object(stdClass)#2 (1) {
        ["Response"]=>
        array(2) {
            [0]=>
            object(stdClass)#3 (2) {
                ["QuestionAnswerID"]=>
                int(someint)
                ["QuestionID"]=>
                int(someint)
            }
            [1]=>
            object(stdClass)#4 (2) {
                ["QuestionAnswerID"]=>
                int(someint)
                ["SurveyQuestionID"]=>
                int(someint)
            }
        }
    }
}

问题在于数组现在有索引,我正在调用的Web服务似乎不喜欢。我可以用任何方式生成类似上面的XML吗?

TIA。

1 个答案:

答案 0 :(得分:10)

如果没有带有WSDL的SOAP服务器,很难对此进行测试。你应该能够像这样创建关联数组:

$responses = array();
$responses[] = array("QuestionAnswerID" => someint, "QuestionID" => someint);
$responses[] = array("QuestionAnswerID" => someint, "QuestionID" => someint);

$response = array("Response" => $responses);

$soapData = array("Responses" => $response);