所以我在我们的企业环境中尝试做的是在 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),但我开始为此发疯。帮助将不胜感激。
提前致谢!