使用PHP到SAP Web Service的SOAP

时间:2013-05-22 16:32:40

标签: php web-services soap sap soap-client

所以我在企业环境中尝试做的是使用wsdl模式的PHP类SoapClient连接到SAP Web服务。

到目前为止,我所取得的成就是“失踪属性”错误。在解决所有丢失的属性错误后,我得到了与身体可怕的http错误500:soap-env:Server

所以这是我的代码:

class SapTest {
 const SAP_WSDL_URI  = *wsdl_uri*;
 const SAP_USER = *username*;
 const SAP_PWD  = *password*;

public function execute() {

        $client = new SoapClient('http://'.urlencode(self::SAP_USER).':'.urldecode(self::SAP_PWD).'@'.self::SAP_WSDL_URI,
                array("trace" => 1,
                      "exceptions" => 1,
                      "login" => self::SAP_USER,
                      "password" => self::SAP_PWD,
                      'features' => SOAP_SINGLE_ELEMENT_ARRAYS)
        );

        $method = '_-bic_-nf2';

        $parameter = array('ETColumnDescription' => null,
                           'ETGridData' => null,
                           'ETMessageLog' => null,
                           'ETRowDescription' => null,
                           'ISVar_01xwerbet' => array('Sign' => 'I',
                                                      'Option' => 'LE',
                                                      'Low' => '3',
                                                      'High' => null));

        try
        {

        $result = $client->$method($parameter);
        print_r($result);
        } catch(SoapFault $e) {

        echo "REQUEST HEADER:\n" . $client->__getLastRequestHeaders() . "\n";
          echo "REQUEST:\n" . $client->__getLastRequest() . "\n";

          echo "RESPONSE HEADER:\n" . $client->__getLastResponseHeaders() . "\n";

          echo "RESPONSE:\n" . $client->__getLastResponse() . "\n";
        print_r($e);
    }


}

}

$oSap = new SapTest();
$oSap->execute();

我的xml输出如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:sap-com:document:sap:soap:functions:mc-style">
 <SOAP-ENV:Body>
  <ns1:_-bic_-nf2>
   <ETColumnDescription/>
   <ETGridData/>
   <ETMessageLog/>
   <ETRowDescription/>
   <ISVar_01xwerbet>
    <Sign>I</Sign>
    <Option>LE</Option>
    <Low>3</Low>
    <High/>
   </ISVar_01xwerbet>
  </ns1:_-bic_-nf2>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

预期的xml应如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:sap-com:document:sap:soap:functions:mc-style">
 <soapenv:Body>
  <urn:_-bic_-nf2>
   <ETColumnDescription/>
   <ETGridData/>
   <ETMessageLog/>
   <ETRowDescription/>
   <ISVar_01xwerbet>
    <Sign>I</Sign>
    <Option>LE</Option>
    <Low>3</Low>
    <High/>
   </ISVar_01xwerbet>
  </urn:_-bic_-nf2>
 </soapenv:Body>
</soapenv:Envelope>

我不确定它是否是缺少的空白标题标记,我似乎无法添加基本PHP(我可以添加标题,但添加空白标题似乎是困难的部分)。或者如果它是不同的前缀(ns1 / urn或soapenv / SOAP-ENV),但我开始对此疯狂。非常感谢帮助。

提前致谢!

1 个答案:

答案 0 :(得分:0)

您的SOAP请求没问题。 ns1 / urnsoapenv / SOAP-ENV只是表示命名空间的前缀。不同的Webservice引擎以不同方式生成其名称空间前缀,Webservice必须预期它们。

对于Web服务,SOAP标头不是强制性的东西,但是如果您的服务需要它,那么您应该提供它。

我建议您与服务提供商讨论该请求出了什么问题,如果不可能,请使用SOAP测试工具,例如SOAPui

要创建空SOAP标头,请尝试

$header =new SoapHeader('urn:sap-com:document:sap:soap:functions:mc-style', null);
$client->__setSoapHeaders($header);