开发者

PHP SoapClient with SuperPages API

开发者 https://www.devze.com 2023-03-03 18:08 出处:网络
So I\'m completely new to SOAP and the whole idea behind it, but I am forced to figure it out in order to work with the SuperPages API. For now, I am just trying to wrap my head around it, and how to

So I'm completely new to SOAP and the whole idea behind it, but I am forced to figure it out in order to work with the SuperPages API. For now, I am just trying to wrap my head around it, and how to make calls to the API. The API documentation can be found here: http://advertising.superpages.com/spapiweb/v2. I am able to login via the headers, but I can't quite figure out where to go from there. Here is documentation for the function I'm attempting to run:

getReportList

The getReportList method retrieves a list of the reports that are currently stored.

Request:

Field Name             Field Type  Field Description    Field
externalTransactionId   string(6)   External Transaction identifier used for logging. Provided by user. Optional

Response

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

My 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 "</pre>";

 $sp->__soapCall("getReportList",array("")); //empty array, because parameter is optional in documentation

My results:

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

What am I doing wrong here?


EDIT

When debugging via

try {
    var_dump($sp->getReportList());
} catch (SoapFault $exception) {
    var_dump($exception->getMessage());
    var_dump($exception);
}

, this is the error dump

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

EDIT

XML output after running

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>


Interesting: never used it before, but I think that this is wrong:

$header = new SoapHeader('[companyId]', '[username]', '[password]');
$sp->__setSoapHeaders($header);

I think you want this:

$headers = array();
$header[] = new SoapHeader('webobjects.reporting.pbap.spmd.com', 'username', '[username]');
$header[] = new SoapHeader('webobjects.reporting.pbap.spmd.com', 'password', '[password]');
$header[] = new SoapHeader('webobjects.reporting.pbap.spmd.com', 'companyId', '[companyId]');
$sp->__setSoapHeaders($headers);

see http://www.php.net/manual/en/soapclient.setsoapheaders.php for the setSoapHeaders() multiple header call and you should probably dump out the request XML to verify that it looks like the example at http://advertising.superpages.com/spapiweb/v2?wicket:interface=:11:3: .

Let me know if it works.

0

精彩评论

暂无评论...
验证码 换一张
取 消