2011-07-06 57 views
1

我很難獲得SOAP請求正常工作,這需要XML字符串作爲輸入。返回SOAP錯誤的PHP SOAP:服務器無法使用.asmx Web服務處理請求

它拋出

「SOAP錯誤:服務器無法處理請求--->值不能爲空參數名:的」

不管我送什麼投入,我有使用nusoap但無濟於事,PHP肥皂庫。 我使用的代碼是:

<? 
$aOptions = array(
'location' => 'http://webserviceurl.asmx', 
'uri' => 'http://tempuri.org/', 
"style" => SOAP_RPC, 
"use" => SOAP_ENCODED 
); 
$client = new SOAPClient(null, $aOptions); 

$request ='<item xmlns="rmsItem"> 
     <columns> 
     <column>description</column> 
     <column>department</column> 
     <column>brand</column> 
     <column>lastsold</column> 
     <column>lastupdated</column> 
     <column>quantityonhand</column> 
     <column>weight</column> 
     </columns> 
     <filters> 
     <filter> 
      <filterColumn>quantityonhand</filterColumn> 
      <operator>greaterthan</operator> 
      <filterValue>20</filterValue> 
     </filter> 
     <filter> 
      <filterColumn>lastsold</filterColumn> 
      <operator>greaterthan</operator> 
      <filterValue>01-01-2005</filterValue> 
     </filter> 
     </filters> 
     <sortColumns> 
     <sortColumn> 
      <sortColumnName>lastsold</sortColumnName> 
      <sortType>ascending</sortType> 
     </sortColumn> 
     <sortColumn> 
      <sortColumnName>quantityonhand</sortColumnName> 
      <sortType>descending</sortType> 
     </sortColumn> 
     </sortColumns> 
    </item>'; 

//$result = $client->__soapCall('getAllInfo',array('infoRequestXml'=>(string)($request),'errorMessage'=>'') ,array('soapaction' => 'http://webserviceurl/getAllInfo')); 

$soapvar = new SoapVar($request , XSD_ANYXML); 

$params = array("infoRequestXml" => $soapvar); 

//print_r($params); 
//$result = $this->soapclient->__soapCall("SaveItem", array("parameters"=>$params), null, $this->soapheaders); 
try 
{ 
$result=$client->__soapCall('getAllInfo',array("parameters"=>$params),array('soapaction' => 'http://webserviceurl/getAllInfo')); 
} 
catch (SoapFault $e) { 
    echo "SOAP Fault: ".$e->getMessage()."<br />\n"; 
} 
echo "<pre>\n"; 
echo htmlspecialchars($client->__getLastRequest())."\n"; 
echo "Response:\n".htmlspecialchars($client->__getLastResponse())."\n"; 
echo "</pre>"; 

var_dump($result); 

?> 

我敲我的頭靠在從最近兩天的牆壁,谷歌搜索這個問題,但沒有得到答覆,解決或指導我。

任何人都可以拋出一些光在此將不勝感激。 在此先感謝。

回答

1

不要通過SOAPVar運行XML,如果你可以把你的Web服務的WSDL選項的優勢:

<?php 

$client = new SOAPClient(
    'http://webserviceurl.asmx?WSDL', 
    array(
     'location' => 'http://webserviceurl.asmx', 
     'trace' => 1, 
     'style' => SOAP_RPC, 
     'use' => SOAP_ENCODED, 
    ) 
); 

$request = '<item xmlns="rmsItem"> 
     <columns> 
     <column>description</column> 
     <column>department</column> 
     <column>brand</column> 
     <column>lastsold</column> 
     <column>lastupdated</column> 
     <column>quantityonhand</column> 
     <column>weight</column> 
     </columns> 
     <filters> 
     <filter> 
      <filterColumn>quantityonhand</filterColumn> 
      <operator>greaterthan</operator> 
      <filterValue>20</filterValue> 
     </filter> 
     <filter> 
      <filterColumn>lastsold</filterColumn> 
      <operator>greaterthan</operator> 
      <filterValue>01-01-2005</filterValue> 
     </filter> 
     </filters> 
     <sortColumns> 
     <sortColumn> 
      <sortColumnName>lastsold</sortColumnName> 
      <sortType>ascending</sortType> 
     </sortColumn> 
     <sortColumn> 
      <sortColumnName>quantityonhand</sortColumnName> 
      <sortType>descending</sortType> 
     </sortColumn> 
     </sortColumns> 
    </item>'; 

$result = array(); 

$params = array("infoRequestXml" => $request); 

try { 
    $result = $client->__soapCall('getAllInfo', array("parameters"=>$params)); 
} catch (SoapFault $e) { 
    echo "SOAP Fault: ".$e->getMessage()."<br />\n"; 
} 

echo "<pre>"; 
echo htmlspecialchars($client->__getLastRequestHeaders())."\n"; 
echo htmlspecialchars($client->__getLastRequest())."\n"; 
echo "Response:\n".htmlspecialchars($client->__getLastResponseHeaders())."\n"; 
echo htmlspecialchars($client->__getLastResponse())."\n"; 
echo "</pre>"; 

var_dump($result); 

?> 
+0

....非常感謝皮特。它的工作就像一個魅力。 ..你救了我的一天....如果你不介意我可以再問你一件事,你能指出我究竟是在做錯什麼,所以下一次我不要再把事情搞砸了。新的PHP SOAP場景...我如何從結果數組中訪問我的結果XML ...再次感謝您寶貴的時間和想法...... –

+0

我得到了響應工作,並在將Object轉換回來之後一個數組並將該數組的所需元素傳遞給** simplexml_load_string()** ... –