1
votes

I am trying to make a web service call using zend 1.11.7 to an asp.net soap web service.

The documentation states that I need to make a call with the following format:

RequestCustomReport(CustomReportDef, SecurityCredential)

With the following structure:

<securityCredentials> 
  <Key>string</Key> 
  <UserName>string</UserN
  <Password>string</Passw
</securityCredentials> 

<reportDefinition> 
    <CustomTemplateId>int</CustomTemplateId> 
    <StartDate>dateTime</StartDate> 
    <EndDate>dateTime</EndDate> 
    <PeriodId>int</PeriodId> 
    <SiteId>int</SiteId> 
    <ReportGUID>string</ReportGUID> 
    <ReportData>base64Binary</ReportData> 
    <ReportDataType>xml or csv or tsv or txt</ReportDataType> 
    <CompressReportData>boolean</CompressReportData> 
    <ReportStatus>Pending or Ready or Error or Deleted</ReportStatus> 
    <ErrorMessage>string</ErrorMessage> 
  </reportDefinition>

My zend code is:

$client = new Zend_Soap_Client($ws_url);

$reqFilter = array();
$reqFilter['CustomTemplateId'] = 33117; //33117 = report id
//$reqFilter['StartDate'] = 
//$reqFilter[''] ='';
$reqFilter['PeriodId'] = 4; //4 = last 7 days
$reqFilter['SiteId'] =3672;
$reqFilter['ReportDataType'] ='xml';
$reqFilter['CompressReportData'] =0;

$reptXml=new XMLWriter();
$reptXml->openMemory();
$reptXml->startDocument('1.0','UTF-8');
$reptXml->startElement("reportDefinition");
  $reptXml->startElement("CustomTemplateId");
    $reptXml->text($reqFilter['CustomTemplateId']);
  $reptXml->endElement();//CustomTemplateId

  $reptXml->startElement("PeriodId");
    $reptXml->text($reqFilter['PeriodId']);
  $reptXml->endElement();//PeriodId

  $reptXml->startElement("SiteId");
    $reptXml->text((int)$reqFilter['SiteId']);
  $reptXml->endElement();//SiteId

  $reptXml->startElement("ReportDataType");
    $reptXml->text($reqFilter['ReportDataType']);
  $reptXml->endElement();//ReportDataType

  $reptXml->startElement("CompressReportData");
    $reptXml->text(0);
  $reptXml->endElement();//  CompressReportData
$reptXml->endElement();//reportDefinition

/*
 * securityCredentials xml
 */
$secXml=new XMLWriter();
$secXml->openMemory();
$secXml->startDocument('1.0','UTF-8');
$secXml->startElement("securityCredentials");
  $secXml->startElement("Key");
    $secXml->text('----');
  $secXml->endElement();
  $secXml->startElement("UserName");
    $secXml->text('--.--');
  $secXml->endElement();  
  $secXml->startElement("Password");
    $secXml->text('----');
  $secXml->endElement();    
$secXml->endElement();

$result = $client->RequestCustomReport($reptXml,$secXml);

But I am getting an error of:

Fatal error: Uncaught SoapFault exception: [soap:Sender] The report definition is a required parameter but was not supplied in C:\wamp\www\libs\Zend-1.11.10\Zend\Soap\Client.php:1121 Stack trace: #0 C:\wamp\www\libs\Zend-1.11.10\Zend\Soap\Client.php(1121): SoapClient->__soapCall('RequestCustomRe...', Array, NULL, NULL, Array) #1 [internal function]: Zend_Soap_Client->__call('RequestCustomRe...', Array) #2 C:\wamp\www\ProFound_test\wsdl.php(109): Zend_Soap_Client->RequestCustomReport(Object(XMLWriter), Object(XMLWriter)) #3 {main} thrown in C:\wamp\www\libs\Zend-1.11.10\Zend\Soap\Client.php on line 1121

It seems that it is not recognising I have passed the report definition parameter as the correct node name.

Can anyone help?

1

1 Answers

6
votes

I had a similar issue with SOAP. apparently the Zend_Soap_Client function calls don't accept variables as function parameters, but an array containing the keys and the values of the parameter function calls.

So:

$result = $client->RequestCustomReport($reptXml,$secXml);

should actually be:

$result = $client->RequestCustomReport(array('xml' => $reptXml, 'key2' => $secXml));

I'm also not sure if you need to create a XML file. maybe just pass $reqFilter as is. I believe the Zend_Soap_Client will do the conversion for you.

$client->setSoapVersion(SOAP_1_1);
$result = $client->RequestCustomReport(array('startDate' => $startDate, 'endDate' => $endDate));

(Note it's an array in the function call)

You can also check out an example SOAP usage I wrote using the zend_Soap_client. https://github.com/aporat/ACH-Direct-Payments-Gateway-PHP