我正在尋找一種方法來更改名稱空間:「ns1」到「ret」,使用SoapUI測試了下面的XML,命名空間設置爲「ret」,並且請求成功。我已經「谷歌搜索」了,並在SO搜索了其他相關問題的答案,但沒有運氣。所以,我有種絕望中找到了答案......在PHP SoapClient請求中更改命名空間?
這裏是產生被髮送到請求的XML:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://retailexpress.com.au/">
<SOAP-ENV:Header>
<ns1:ClientHeader>
<ns1:ClientID>Random-hash-clientID</ns1:ClientID>
<ns1:UserName>Username</ns1:UserName>
<ns1:Password>Password</ns1:Password>
</ns1:ClientHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:CustomerGetBulkDetails>
<ns1:LastUpdated>2000-01-01T00:00:00.000Z</ns1:LastUpdated>
<ns1:OnlyCustomersWithEmails>1</ns1:OnlyCustomersWithEmails>
</ns1:CustomerGetBulkDetails>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
雖然,這似乎有點奇怪,我們必須要求與同一個命名空間(RET),但是這是怎麼回事...
這裏是用來生成上面的PHP代碼:
$rexHost = '<domain of retail express>';
$rexApi = '<URI of retail express API/wsdl path>';
$rexUser = 'Username';
$rexPassword = 'Password';
$rexApiClient = 'Random-hash-clientID';
$rexApiHost = 'http://retailexpress.com.au/';
$client = new SoapClient($rexHost.$rexApi, array('trace' => true));
$auth = new stdClass();
$auth->ClientID = $rexApiClient;
$auth->UserName = $rexUser;
$auth->Password = $rexPassword;
$header = new SoapHeader($rexApiHost, 'ClientHeader', $auth, false);
$client->__setSoapHeaders($header);
$lastUpdate = '2000-01-01T00:00:00.000Z'; //hardcoded for test
$params = array();
$params[] = new SoapVar($lastUpdate, XSD_DATETIME, null, null, 'LastUpdated', $rexApiHost);
$params[] = new SoapVar(1, XSD_INTEGER, null, null, 'OnlyCustomersWithEmails', $rexApiHost);
try {
$users = null;
return $users = $client->CustomerGetBulkDetails(new SoapVar($params, SOAP_ENC_OBJECT));
} catch (Exception $e) {
Log::info($e->getMessage());
Log::info($client->__getLastRequest()); //laravel logger, where I got the generated SOAP XML request
return false;
}
我在代碼中找不到任何錯誤。你能找到問題嗎? –
我從來沒有找到如何改變命名空間。但是,現在似乎無需更改單個代碼即可運行。可能是因爲我們要求支持,他們設法解決這個問題。命名空間「ns1」現在與我們對其API的SOAP請求一起工作......謝謝! – jediscript
啊服務器問題:) –