我创建了正确的SOAP请求,但我需要LogOn节点具有xmlns属性。这就是属性的样子:xmlns =“http://www.ultipro.com/dataservices/bidata/2”。我使用SOAPUI来测试请求,看来如果我添加xmlns,那么响应应该是成功的。
这是我目前的代码:
function Login($username, $password, $clientaccesskey, $useraccesskey)
{
class LogOn
{
function __construct($request)
{
$this->logOnRequest = $request;
}
}
// Class handler for the request
class logOnRequest {
function __construct($usr, $pwd, $cak, $uak)
{
$this->UserName = $usr;
$this->Password = $pwd;
$this->ClientAccessKey = $cak;
$this->UserAccessKey = $uak;
}
}
// Conversion to a SOAP object
$lor = new LogOnRequest($username, $password, $clientaccesskey, $useraccesskey);
$lo = new LogOn($lor);
$logOnRequest = new SoapVar($lor, SOAP_ENC_OBJECT, 'logOnRequest');
$loi = new SoapVar($lo, SOAP_ENC_OBJECT);
$headers = array();
$headers[] = new SoapHeader('http://www.w3.org/2005/08/addressing', 'Action', 'http://www.ultipro.com/dataservices/bidata/2/IBIDataService/LogOn');
$headers[] = new SoapHeader('http://www.w3.org/2005/08/addressing', 'To', 'https://service4.ultipro.com/services/BiDataService');
try
{
$soapclient = new SoapClient('https://service4.ultipro.com/services/BiDataService', array('soap_version' => SOAP_1_2, 'encoding' => 'UTF-8', 'exceptions' => TRUE, 'trace' => TRUE));
$soapclient->__setSoapHeaders($headers);
// Direct call to the LogOn method and SOAP parameter pass
$response = $soapclient->LogOn(new SoapParam($loi, 'LogOn'));
echo json_encode($response);
echo htmlentities($soapclient->__getLastRequest());
}
catch(SoapFault $fault){
echo $fault->faultstring;
}
}
这就是我的要求:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://www.ultipro.com/dataservices/bidata/2" xmlns:ns2="http://www.w3.org/2005/08/addressing">
<env:Header>
<ns2:Action>http://www.ultipro.com/dataservices/bidata/2/IBIDataService/LogOn</ns2:Action>
<ns2:To>https://service4.ultipro.com/services/BiDataService</ns2:To>
</env:Header>
<env:Body>
<ns1:LogOn>
<logOnRequest>
<UserName></UserName>
<Password></Password>
<ClientAccessKey></ClientAccessKey>
<UserAccessKey></UserAccessKey>
</logOnRequest>
</ns1:LogOn>
</env:Body>
</env:Envelope>
它需要看起来像这样:
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://www.ultipro.com/dataservices/bidata/2" xmlns:ns2="http://www.w3.org/2005/08/addressing">
<env:Header>
<ns2:Action>http://www.ultipro.com/dataservices/bidata/2/IBIDataService/LogOn</ns2:Action>
<ns2:To>https://service4.ultipro.com/services/BiDataService</ns2:To>
</env:Header>
<env:Body>
<ns1:LogOn xmlns="http://www.ultipro.com/dataservices/bidata/2">
<logOnRequest>
<UserName></UserName>
<Password></Password>
<ClientAccessKey></ClientAccessKey>
<UserAccessKey></UserAccessKey>
</logOnRequest>
</ns1:LogOn>
</env:Body>
</env:Envelope>