Так что я совершенно новичок в SOAP и всей идее, лежащей в его основе, но я вынужден выяснить это для работы с API SuperPages.Сейчас я просто пытаюсь обдумать это и узнать, как делать вызовы API.Документацию по API можно найти здесь: http://advertising.superpages.com/spapiweb/v2. Я могу войти через заголовки, но не могу понять, куда идти дальше.Вот документация для функции, которую я пытаюсь запустить:
getReportList
Метод getReportList возвращает список отчетов, которые в данный момент хранятся.
Запрос:
Field Name Field Type Field Description Field
externalTransactionId string(6) External Transaction identifier used for logging. Provided by user. Optional
Ответ
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ns2:getReportListResponse xmlns:ns2="webobjects.reporting.pbap.spmd.com">
<return>
<ns2:report>
<ns2:reportName></ns2:reportName>
<ns2:reportId></ns2:reportId>
<ns2:reportType></ns2:reportType>
<ns2:status></ns2:status>
<ns2:startDate></ns2:startDate>
<ns2:endDate></ns2:endDate>
<ns2:createdDate></ns2:createdDate>
</ns2:report>
<ns2:totalRows></ns2:totalRows>
<ns2:dateCreated></ns2:dateCreated>
<ns2:internalTransactionId></ns2:internalTransactionId>
</return>
</ns2:getReportListResponse>
</soap:Body>
</soap:Envelope>
Мой код:
<code> $options = array('trace' => true);
$sp = new SoapClient('http://services.superpages.com/spexternalservicesv3/services/reportingservice?wsdl', $options);
$header = new SoapHeader('[companyId]', '[username]', '[password]');
$sp->__setSoapHeaders($header);
echo "<pre>";
var_dump($sp->__getFunctions()); //check that I'm at least doing something right
echo "
"; $ sp -> __ soapCall (" getReportList ", array (" ")); // пустой массив, поскольку параметр является необязательнымв документации
Мои результаты:
array(5) {
[0]=>
string(59) "getReportURLResponse getReportURL(getReportURL $parameters)"
[1]=>
string(83) "scheduleAgencyReportResponse scheduleAgencyReport(scheduleAgencyReport $parameters)"
[2]=>
string(65) "scheduleReportResponse scheduleReport(scheduleReport $parameters)"
[3]=>
string(59) "deleteReportResponse deleteReport(deleteReport $parameters)"
[4]=>
string(62) "getReportListResponse getReportList(getReportList $parameters)"
}
Fatal error: Uncaught SoapFault exception: [soap:Client] Error reading XMLStreamReader. in /home/a2op/public_html/billing/sp/index.php:11 Stack trace: #0 /home/a2op/public_html/billing/sp/index.php(11): SoapClient->__soapCall('getReportList', Array) #1 {main} thrown in /home/a2op/public_html/billing/sp/index.php on line 11
Что я здесь не так делаю?
РЕДАКТИРОВАТЬ
При отладке с помощью
try {
var_dump($sp->getReportList());
} catch (SoapFault $exception) {
var_dump($exception->getMessage());
var_dump($exception);
}
, это дамп ошибки
string(32) "Fault occurred while processing."
object(SoapFault)#5 (8) {
["message:protected"]=>
string(32) "Fault occurred while processing."
["string:private"]=>
string(0) ""
["code:protected"]=>
int(0)
["file:protected"]=>
string(43) "/home/a2op/public_html/billing/sp/index.php"
["line:protected"]=>
int(19)
["trace:private"]=>
array(2) {
[0]=>
array(6) {
["file"]=>
string(43) "/home/a2op/public_html/billing/sp/index.php"
["line"]=>
int(19)
["function"]=>
string(6) "__call"
["class"]=>
string(10) "SoapClient"
["type"]=>
string(2) "->"
["args"]=>
array(2) {
[0]=>
string(13) "getReportList"
[1]=>
array(0) {
}
}
}
[1]=>
array(6) {
["file"]=>
string(43) "/home/a2op/public_html/billing/sp/index.php"
["line"]=>
int(19)
["function"]=>
string(13) "getReportList"
["class"]=>
string(10) "SoapClient"
["type"]=>
string(2) "->"
["args"]=>
array(0) {
}
}
}
["faultstring"]=>
string(32) "Fault occurred while processing."
["faultcode"]=>
string(11) "soap:Server"
}
РЕДАКТИРОВАТЬ
Вывод XML после запуска
try{
var_dump($sp->getReportList());
}catch (SoapFault $exception) {
var_dump($exception->getMessage());
var_dump($exception);
}
echo $sp->__getLastRequest();
-
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="webobjects.reporting.pbap.spmd.com">
<SOAP-ENV:Header>
<ns1:username>[username]</ns1:username>
<ns1:password>[password]</ns1:password>
<ns1:companyId>[companyId]</ns1:companyId>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getReportList/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>