我遇到過使用SOAP的麻煩,我從來沒有遇到過這個問題,也找不到任何幫助我解決問題的信息。php soapclient返回null,但getPreviousResults有正確的結果
下面的代碼
$wsdl = "path/to/my/wsdl";
$client = new SoapClient($wsdl, array('trace' => true));
//$$textinput is passed in and is a very large string with rows in <item></item> tags
$soapInput = new SoapVar($textinput, XSD_ANYXML);
$res = $client->dataprofilingservice(array("contents" => $soapInput));
$response = $client->__getLastResponse();
var_dump($res);//outputs null
var_dump($response);//provides the proper response as I would expect.
我已經試過路過PARAMS到SoapClient的構造函數中定義的肥皂版本但didnt的幫助。我也試過跟蹤參數設置爲false,不存在,正如預期的那樣,$ response null爲空,但$ res仍然爲空。我已經嘗試了運行Apache的Linux和Windows安裝上的代碼。
在WSDL函數定義爲(xxxx是出於安全原因)
<portType name="xxxxServiceSoap">
<operation name="dataprofilingservice">
<input message="tns:dataprofilingserviceSoapIn"/>
<output message="tns:dataprofilingserviceSoapOut"/>
</operation>
</portType>
我有工作使用__getLastResponse(),但它的討厭我,這將無法正常工作。
我已經放在一起一個小測試腳本,有沒有人看到這裏的任何問題。我是否需要返回類型的結構?
//very simplifed dataset that would normally be
//read in from a CSV file of about 1mb
$soapInput = getSoapInput("asdf,qwer\r\nzzxvc,ewrwe\r\n23424,2113");
$wsdl = "path to wsdl";
try {
$client = new SoapClient($wsdl,array('trace' => true,'exceptions' => true));
} catch (SoapFault $fault) {
$error = 1;
var_dump($fault);
}
try {
$res = $client->dataprofilingservice(array("contents" => $soapInput));
$response = $client->__getLastResponse();
echo htmlentities($client->__getLastRequest());//proper request echoed
echo '<hr>';
var_dump($res);//null
echo "<hr>";
echo(htmlentities($response));//proper response echoed
} catch (SoapFault $fault) {
$error = 1;
var_dump($fault);
}
function getSoapInput($input){
$rows = array();
$userInputs = explode("\r\n", $input);
$userInputs = array_filter($userInputs);
//
$inputTemplate = " <contents>%s</contents>";
$rowTemplate = "<Item>%s</Item>";
//
$soapString = "";
foreach ($userInputs as $row) {
// sanitize
$row = htmlspecialchars(addslashes($row));
$xmlStr = sprintf($rowTemplate, $row);
$rows[] = $xmlStr;
}
$textinput = sprintf($inputTemplate, implode(PHP_EOL, $rows));
$soapInput = new SoapVar($textinput, XSD_ANYXML);
return $soapInput;
}
感謝您的回覆 - 不幸的是,我無法提供整個WSDL /代碼。我知道getLastResponse是用於調試的,但是如果它提供的是響應的裸XML而不是響應。由於唯一的soap函數調用是$ res = $ client-> dataprofilingservice(array(「contents」=> $ soapInput));這就是產生「最後的迴應」的原因。 –