2014-03-27 103 views
0

我試圖用非WSDL模式下的PHP SoapClient發出請求。我傳遞參數作爲多維對象中所示的下面的代碼片斷:無用的<param0>從PHP SoapClient non-wsdl模式的節點

$params = new stdClass; 
$params->Characteristic = new stdClass; 
$params->Characteristic->Name = 'PRODUCT_TYPE'; 
$params->Characteristic->CharacteristicValue = new stdClass; 
$params->Characteristic->CharacteristicValue->Value = $type; 
$params->Characteristic->CharacteristicValue->Type = 'STRING'; 

$client = new SoapClient(NULL, array( 'trace' => true, 'exceptions' => true, 'uri' => $uri, 'location' => $location, 
     'connection_timeout'=>9999, 
     'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 
     'soap_version' => SOAP_1_1, 'encoding' => 'ISO-8859-1', 
     'use' => SOAP_LITERAL 
    )); 

$response = $client->thisIsTheFunction($params); 

生成的XML是幾乎右除了被包裹在標記:

<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://[removed]"> 
    <soap-env:body> 
     <ns1:thisisthefunction> 
      <param0> 
       <characteristic> 
        <name>PRODUCT_TYPE</name> 
        <characteristicvalue> 
         <value>Adhoc</value> 
         <type>STRING</type> 
        </characteristicvalue> 
       </characteristic> 
      </param0> 
     </ns1:thisisthefunction> 
    </soap-env:body> 
</soap-env:envelope> 

的問題是這被服務檢測爲畸形。有什麼方法可以刪除這個額外的標籤嗎?

+0

請問,$ uri','$ location','$ value'的值是多少? –

+0

嗨Log1c。 $ uri是命名空間,$ location是端點,$ type ='STRING'。我不能透露前兩項,因爲它們是保密的。但我認爲這不重要嗎?謝謝 – user3469919

+0

任何人有任何想法? – user3469919

回答

2

我想如果你想刪除param0並在這個地方放入characteristicValue,你需要使用一個SoapParam(http://www.php.net/manual/en/class.soapparam.php)。

事實上,你的電話必須繼續這樣的:

$response = $client->thisIsTheFunction(new SoapParam($params->Characteristic, 'ns1:Characteristic')); 

現在,您生成的XML看起來像這樣:

<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://[removed]"> 
<soap-env:body> 
    <ns1:thisisthefunction> 
     <ns1:characteristic> 
      <name>PRODUCT_TYPE</name> 
      <characteristicvalue> 
       <value>Adhoc</value> 
       <type>STRING</type> 
      </characteristicvalue> 
     </ns1:characteristic> 
    </ns1:thisisthefunction> 
</soap-env:body> 

祝你好運!

+1

另一個例子在這裏:http://stackoverflow.com/questions/928169/php-soap-non-wsdl-call - 如何-DO-你通參數 – M4kn4sh