在非WSDL模式下将数组作为参数传递给Soap Webservice

时间:2011-03-07 14:56:52

标签: php zend-framework soap sap webservice-client

我使用Zend_Soap_Client查询SAP提供的Web服务中的数据。由于自动生成的WSDL文件有一些缺陷,我使用客户端的非WSDL模式。

我设法成功调用了一个只需要简单参数的web服务,比如字符串。例如:

这是SAP所期望的:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style">
  <soapenv:Header/>
  <soapenv:Body>
    <urn:Ze12RfcGetCustHistoryNew>
      <PiDateHigh>2011-12-31</PiDateHigh>
      <PiDateLow>1970-01-01</PiDateLow>
      <PiKunnr>1</PiKunnr>
    </urn:Ze12RfcGetCustHistoryNew>
  </soapenv:Body>
</soapenv:Envelope>

这是我在PHP中的(工作)代码($ SOAPClient已在非WSDL模式下初始化):

$soapClient->Ze12RfcGetCustHistoryNew(
  new SoapParam(date('Y-m-d'), 'PiDateHigh'),
  new SoapParam('1970-01-01', 'PiDateLow'),
  new SoapParam('1', 'PiKunnr')
);

但是一旦我必须将更复杂的参数传递给服务,它就不起作用。再举一个例子:

这是SAP所期望的:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style">
  <soapenv:Header/>
  <soapenv:Body>
    <urn:Ze12RfcGetCustHistoryNew>
      <PiDateHigh>2011-12-31</PiDateHigh>
      <PiDateLow>1970-01-01</PiDateLow>
      <PiKunnr>1</PiKunnr>
      <PiTBelegart>
        <item>
          <BelegartTyp>FAKTURA</BelegartTyp>
          <Belegart>ZF2</Belegart>
        </item>
      </PiTBelegart>
    </urn:Ze12RfcGetCustHistoryNew>
  </soapenv:Body>
</soapenv:Envelope>

我曾尝试使用包含SoapParams的多维数组,但这不起作用。在WSDL模式下,我可以将params作为数组传递,而无需使用SoapParams。如何在非WSDL模式下执行此操作?

2 个答案:

答案 0 :(得分:1)

只是一个“快速打击”......我在不同的环境中工作,但最初也有我的肥皂价值问题。 针对特定问题的一种解决方案是以这种方式传递复杂数组:

$data = (object)$complexArray;
$result = $webserviceClient->getResult($data);

“转换”到对象会产生一个StdClass对象...这通常适用于Web服务。

祝你好运!

答案 1 :(得分:0)

我还没有想出一个很好的解决方案 - 目前我将参数作为原始xml传递给客户端对象。这有效,但似乎不是最好的方法。这是我现在的代码:

$params = '
  <PiDateHigh>2011-12-31</PiDateHigh>
  <PiDateLow>1970-01-01</PiDateLow>
  <PiKunnr>1</PiKunnr>
  <PiTBelegart>
    <item>
      <BelegartTyp>FAKTURA</BelegartTyp>
      <Belegart>ZF2</Belegart>
    </item>
  </PiTBelegart>
  ';

$result = $this->_client->Ze12RfcGetCustHistoryNew(new SoapVar($params,XSD_ANYXML));