2013-01-25 17 views
-2

我需要創建這個XML:SoapClient的創建XML

<soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <soapenv:Header> 
    <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext"> 
     <wsse:UsernameToken> 
     <wsse:Username>user</wsse:Username> 
     <wsse:Password>password</wsse:Password> 
     </wsse:UsernameToken> 
    </wsse:Security> 
    </soapenv:Header> 
    <soapenv:Body> 
    <vb:getAirportInfo xmlns:vb="http://www.example.com/schema/2005/02/booking.xsd"> 
     <airport>BNE</airport> 
     <airport>PPP</airport> 
     <airport>MEL</airport> 
    </vb:getAirportInfo> 
    </soapenv:Body> 
</soapenv:Envelope> 

我是新來使用SoapClients,需要一些幫助,這樣做。我會怎麼做?

+0

什麼語言?什麼平臺? –

+0

我使用PHP並在Apache服務器上使用SoapClient – user1087185

+0

您是否嘗試過某些功能? –

回答

0

我想通了。我需要做兩件事。 首先,我需要創建具有安全性的標題部分。 $ soap_client = new SoapClient(「airportinfo.wsdl」,array(「trace」=> 1,「exceptions」=> 0));

$header_part = ' 
     <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" SOAP-ENV:mustUnderstand="1"> 
      <wsse:UsernameToken> 
       <wsse:Username>'.$username.'</wsse:Username> 
       <wsse:Password>'.$password.'</wsse:Password> 
      </wsse:UsernameToken> 
     </wsse:Security> 
    '; 
    $soap_var_header = new SoapVar($header_part, XSD_ANYXML, null, null, null); 
    $soap_header = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'wsse', $soap_var_header, true); 
    $soap_client->__setSoapHeaders($soap_header); 

第二我需要創建一個數組並將其傳遞給WSDL所具有的函數。我通過使用__getFunctions()獲得了這些列表。然後我用這個代碼來生成最後的XML

$airports = array("AirportInfoRQ" => array("AirportCode" => "PPP", "AirportCode" => "BNE")); 
    $responce = $soap_client->AxisTransaction($airports); 

的這給了我稍微不同的XML我上面所述,但它是正確的XML得到SoapClient的正常工作

0

要successfuly使用SOAP從PHP,你需要兩樣東西:

  1. 首先是用PHP捆綁SoapClient的和/或SoapServer的類。他們工作正常,詳情請參閱http://php.net/manual/en/book.soap.php
  2. 第二個是WsdlDocument庫。它生成服務的WSDL描述,所以其他客戶可以輕鬆使用它。見http://code.google.com/p/wsdldocument/

和SoapClient使用很簡單,一旦你初始化它,你會得到對象,你可以調用方法和往常一樣,它會將這些調用服務器。

SoapServer僅用於創建服務的實例並調用句柄方法。

這些都不包括手動處理您發佈的XML。它神奇地在它自己的工作(完全字面上)。