PHP SOAP空响应
我想用soapui访问soap接口。一切正常:PHP SOAP空响应
请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soc="www.example.com">
<soapenv:Header/>
<soapenv:Body>
<soc:getMailboxes>
<userId>512</userId>
</soc:getMailboxes>
</soapenv:Body>
</soapenv:Envelope>
响应:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getMailboxesResponse xmlns="http://www.example.com">
<getMailboxesReturn>
<mailboxes>
<mailboxes>
<administratorNumbers/>
<administratorUsers>
<administratorUsers>512</administratorUsers>
</administratorUsers>
<allowsSuppressedNumbers>true</allowsSuppressedNumbers>
<deactivatedByAdmin>false</deactivatedByAdmin>
<deactivatedByUser>false</deactivatedByUser>
<mailNotificationActive>true</mailNotificationActive>
<name>speech box</name>
<notificationNumber xsi:nil="true"/>
<number>123123123</number>
<pin xsi:nil="true"/>
<recordConferenceCallActive>false</recordConferenceCallActive>
<sendSmsCount>0</sendSmsCount>
<sendSmsLimit>0</sendSmsLimit>
<smsNotificationActive>false</smsNotificationActive>
<tag xsi:nil="true"/>
<type>CLASSIC</type>
<voicemailEnabled>false</voicemailEnabled>
<whitelistedNumbers/>
</mailboxes>
</mailboxes>
<responseCode>
<ID>0</ID>
<name>OK</name>
</responseCode>
</getMailboxesReturn>
</getMailboxesResponse>
</soapenv:Body>
</soapenv:Envelope>
我想这个代码,即可获得相同的结果:
$client = new SoapClient($soapURL,array('login' => "...",
'password' => "...",
'trace' => 1,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS));
$response = $client->getMailboxes(512);
echo var_dump(get_object_vars($response));
和我这个结果:
array(2) {
["mailboxes"]=>
object(stdClass)#4 (0) {
}
["responseCode"]=>
object(stdClass)#5 (2) {
["ID"]=>
int(0)
["name"]=>
string(2) "OK"
}
}
我假设有一些值,如在soapui响应中的响应(如object(stdClass)#5)?如果我发送错误的用户标识,我会得到正确的错误信息。谁能帮我?
更新1: 的getMailboxes方法创建此代码:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.example.com">
<SOAP-ENV:Body>
<ns1:getMailboxes>
<userId>512</userId>
</ns1:getMailboxes>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
更新2:
,如果我用这个代码:
$response = $client->getMailboxes(["userId"=>512]);
我得到这个肥皂码。用户ID应该是512,而不是1
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="www.example.com">
<SOAP-ENV:Body>
<ns1:getMailboxes>
<userId>1</userId>
</ns1:getMailboxes>
</SOAP-ENV:Body></SOAP-ENV:Envelope>
我用肥皂代码:
echo "REQUEST:\n" . $client->__getLastRequest()
此调用不正确:在原始XML
$response = $client->getMailboxes(512);
注意,你是告诉它什么512意味着什么?您也可以通过使用关联数组来标识您发送的参数:
$response = $client->getMailboxes(["userId"=>"512"]);
感谢您的回复。我尝试了你的代码,但是我得到了一个错误的结果: $ response = $ client-> getMailboxes([“userId”=> 512]);创建一个值为1的userId。
尝试将ID作为字符串传递,请参阅我的上次编辑。 – miken32
结果没有变化 – user3488359
您可以提供'getMailboxes'方法内容吗? – walkingRed
你是什么意思?我使用SoapClient类。 getMailboxes派生自wsdl(至少我认为是这样)。 – user3488359