简体   繁体   English

在SOAP调用中传递PHP数组

[英]Passing a PHP array in a SOAP call

So I am trying to include the following XML in my SOAP request: 因此,我试图在我的SOAP请求中包括以下XML:

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

I looked at this posting, which is vaguely on the same topic, but it produces output like so: 我看了一下这个帖子, 这个帖子含糊地涉及同一主题,但它产生的输出如下:

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

The problem with that is that the arrays now have indices, which the web service I'm calling appears to not like. 问题在于,数组现在具有索引,我正在调用的Web服务似乎不喜欢该索引。 Any way I can generate something like the above XML? 有什么办法可以生成类似上述XML的内容吗?

TIA. TIA。

It's hard to test this without a SOAP server with your WSDL to go against. 没有WSDL的SOAP服务器,很难进行测试。 You should be able to create associative arrays like so: 您应该能够像这样创建关联数组:

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

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM