2017-03-01 117 views
1

試圖與參數的SOAP調用:如何正確形成__soapCall參數

$client = new SoapClient(null, [ 
    'location' => $url, 
    'uri'  => $uri, 
    'trace'  => 1, 
    'exceptions' => 1 
]); 

$params['parameters'] = [ 
    'p1'=>'v1', 
    'p2'=>'v2' 
]; 

$client->__soapCall('generate',$params); 

我想我的要求是這樣的:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
        xmlns:ns1="some_url_here"> 
    <SOAP-ENV:Body> 
     <ns1:generate> 
      <parameters> 
       <p1>v1</p1> 
       <p2>v2</p2> 
      </parameters> 
     </ns1:generate> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

但我得到的是:

var_dump($client->__getLastRequest()); 

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
        xmlns:ns1="some_url_here" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
        xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
        SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
<SOAP-ENV:Body> 
    <ns1:generate> 
     <param0 xsi:type="ns2:Map"> 
      <item> 
       <key xsi:type="xsd:string">p1</key> 
       <value xsi:type="xsd:string">v1</value> 
      </item> 
      <item> 
       <key xsi:type="xsd:string">p2</key> 
       <value xsi:type="xsd:string">v2</value> 
      </item> 
     </param0> 
    </ns1:generate> 
</SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

任何想法如何正確地形成參數列表以獲得想要的請求? 您的幫助,將不勝感激。

回答

1

使用SOAP Web服務的最佳和快速方法是使用WSDL生成器,因爲您不會想知道如何構建請求。

嘗試PackageGenerator項目,您會發現構建請求很容易(除非您故意這麼做,否則不會發生任何錯誤;))。另外,收到的答覆很容易處理。每個部分都是一個對象。