如何通过 php Zend_Soap_Client 将参数传递给soap 方法?

发布于 2024-12-17 13:37:16 字数 3456 浏览 1 评论 0原文

我正在尝试使用 zend 1.11.7 对 asp.net SOA Web 服务进行 Web 服务调用。

该文档指出我需要使用以下格式进行呼叫:

RequestCustomReport(CustomReportDef,SecurityCredential)

具有以下结构:

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

我的 zend 代码是:

$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);

但我收到以下错误:

致命错误:未捕获的 SoapFault 异常:[soap:Sender] 报告定义是必需参数,但在 C 中未提供: \wamp\www\libs\Zend-1.11.10\Zend\Soap\Client.php:1121 堆栈跟踪: #0 C:\wamp\www\libs\Zend-1.11.10\Zend\Soap\Client.php(1121): SoapClient->__soapCall('RequestCustomRe...', Array, NULL, NULL, Array) #1 [内部函数]: 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} 抛出在 C:\wamp\www\libs\Zend- 1.11.10\Zend\Soap\Client.php on line 1121

似乎它无法识别我已将报告定义参数作为正确的节点名称传递。

有人可以帮忙吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少年亿悲伤 2024-12-24 13:37:17

我对 SOAP 也有类似的问题。显然,Zend_Soap_Client 函数调用不接受变量作为函数参数,而是接受包含参数函数调用的键和值的数组。

所以:

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

实际上应该是:

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

我也不确定您是否需要创建 XML 文件。也许只需按原样传递 $reqFilter 即可。我相信 Zend_Soap_Client 会为您完成转换。

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

(注意它是函数调用中的一个数组)

您还可以查看我使用 zend_Soap_client 编写的 SOAP 用法示例。 https://github.com/aporat/ACH-Direct-Payments-Gateway-PHP

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文