我有一个基于 SOAP 协议的网络服务。SOAP 提供了一个方法 Add,它将一个 OO 对象变量作为输入。
我正在尝试将数据添加到他们的服务中。这是代码:
// this classes create a structure for WSSE security headers
class clsWSSEAuth
{
private $Username;
private $Password;
function __construct($u, $p)
{
$this->Username = $u;
$this->Password = $p;
}
}
class clsWSSEToken
{
private $UsernameToken;
function __construct($i)
{
$this->UsernameToken=$i;
}
}
$params = array('trace' => true);
$user = 'xxxxxx';
$pass = base64_encode(sha1('yyyyy', true)); //sha1 is sth like mdf - it codes the pass
$wssens = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'; //namespace
$soapVarUser = new SoapVar ($user, XSD_STRING, NULL, $wssens, NULL, $wssens);
$soapVarPass = new SoapVar ($pass, XSD_STRING, NULL, $wssens, NULL, $wssens);
//PREPARATION OF VARIABLE FO USER AND PASS - END
//Create Object for Auth Class and pass in soap var
$wsseAuth = new clsWSSEAuth ($soapVarUser, $soapVarPass);
//Create SoapVar out of object of Auth class
$soapVarAuth = new SoapVar ($wsseAuth, SOAP_ENC_OBJECT, NULL, $wssens, 'UsernameToken', $wssens);
//Create object for Token Class
$wsseToken = new clsWSSEToken ($soapVarAuth);
//Create SoapVar out of object of Token class
$soapVarToken = new SoapVar ($wsseToken, SOAP_ENC_OBJECT, NULL, $wssens, 'UsernameToken', $wssens);
//Create SoapVar for 'Security' node
$soapHeader = new SoapVar ($soapVarToken, SOAP_ENC_OBJECT, NULL, $wssens, 'Security', $wssens);
//Create header object out of security soapvar
$header = new SoapHeader($wssens, 'Security', $soapHeader, true, 'htpp://abce.com');
//Create object of Soap Client
$client = new SoapClient('https://xxxxxx.support.xxxxxxx.pl:8443/webservices/LAB/LabResultsManagerEP?wsdl', $params);
//Set headers for soapclient object
$client->__setSoapHeaders($header);
//definition of example object
class CreateOrderResultListVO {
public $ord;
function CreateOrderResultListVO(){
//and some other stuff here too
$this -> ord = $any_structure_of_objects_maching_required_fields;
}
}
$test = new CreateOrderResultListVO(); //this is preety much any php OO object
try
{
$id=$client->add($test -> ord);
} catch (Exception $e) { echo "error in add method: <pre>"; var_dump($e);echo "</pre>"; }
用 Java 编写了客户端,并且工作正常。C# 中的客户端也是如此。但据我所知,我是第一个尝试在 PHP 中做到这一点的人。
事实上,传递给 Add 方法的对象结构很复杂(它匹配的不是那么小的 xml 文件),但显然这不是问题。
我得到 var_dump 错误:整个对象结构 + 这个:
["faultstring"]=>
string(23) "VO object can't be null"
["faultcode"]=>
string(10) "env:Server"
["detail"]=>
object(stdClass)#19 (1) {
["ErlabException"]=>
object(stdClass)#20 (2) {
["code"]=>
string(10) "WRONG_DATA"
["message"]=>
string(23) "VO object can't be null"
}
}
这意味着(我认为)soap 连接没问题(我在 get_data 方法中有相同的连接并且工作正常)但是由于某种原因 Method Add 对我发送的日期没有做任何事情,就像它没有看到它一样?
我真的很乐意提供任何帮助。我该如何处理这个问题,或者至少我如何查找问题所在?
编辑:我希望这会有所帮助:我已经安装了 Fiddler,以便收听从我的电脑发送到互联网的内容。我已经配置了 Firefox 来使用它。我得到的只是浏览器中显示的 php 网页的内容。除了由 SOAP Add 方法生成的 xml 之外,c# 和 Jave 客户端什么都不显示。我几乎确定 php 与 SOap webserwice 连接得很好(除非我得到的错误不是 Soap Add 错误而是 Soap serwer 错误),所以我不明白为什么 Fiddler 什么也没显示。