2010-01-18 61 views
4

Confluence soap api定義了兩種方法具有相同的名字,但不同的參數:如何使用PHP SoapClient調用重載的SOAP方法?

  • 頁GETPAGE(字符串令牌,長PAGEID) - 返回單個頁(根據文檔的第二個參數是字符串,但在WSDL它是長)
  • 頁GETPAGE(字符串令牌,廣州雄兵字符串,字符串PAGETITLE) - 返回一個頁面

我需要調用的方法用PHP SoapClient的兩個參數。在WSDL模式下,SoapClient堅持使用三參數。在非WSDL模式下,我設法使用兩個參數進行調用,但我無法使第二個參數的類型變長。如何讓SoapClient使用兩個正確類型的參數調用getPage?

這是我到目前爲止已經完成:

在WSDL模式下使用SoapClient的...

$soapClient = new SoapClient("http://xxx/confluence/rpc/soap-axis/confluenceservice-v1?wsdl", array("trace" => TRUE)); 
$token = $soapClient->login(CONFLUENCE_USERNAME, CONFLUENCE_PASSWORD); 
$page = $soapClient->getPage($token, $confluence_article_id); 

...產生三個參數方法(只顯示機構)的請求。 ..

<SOAP-ENV:Body><ns1:getPage><in0 xsi:type="xsd:string">dkjLIx00Ap</in0><in1 xsi:type="xsd:string">24445207</in1><in2 xsi:nil="true"/></ns1:getPage></SOAP-ENV:Body> 

...這會導致故障:

<faultstring>com.atlassian.confluence.rpc.RemoteException: You're not allowed to view that page, or it does not exist.</faultstring> 

帶有該ID的頁面確實存在,我可以看到它,我可以通過使用SoapUI進行正確的請求來確認。

使用SoapClient的是非WSDL模式...

$soapClient = new SoapClient(null, array(
    "location" => "http://xxx/confluence/rpc/soap-axis/confluenceservice-v1", 
    "uri" => "http://soap.rpc.confluence.atlassian.com", 
    "trace" => TRUE)); 
$token = $soapClient->login(CONFLUENCE_USERNAME, CONFLUENCE_PASSWORD); 
$page = $soapClient->getPage($token, $confluence_article_id); 

...產生用於雙參數方法使用不正確的類型爲第二個參數的請求。當$ confluence_article_id是字符串,請求...

<SOAP-ENV:Body><ns1:getPage><param0 xsi:type="xsd:string">8Or94ZLqe7</param0><param1 xsi:type="xsd:string">24445207</param1></ns1:getPage></SOAP-ENV:Body> 

...返回上述同樣的故障:

<faultstring>com.atlassian.confluence.rpc.RemoteException: You're not allowed to view that page, or it does not exist.</faultstring> 

當$ confluence_article_id是整數,請求...

<SOAP-ENV:Body><ns1:getPage><param0 xsi:type="xsd:string">y0kF4z0m9L</param0><param1 xsi:type="xsd:int">24445207</param1></ns1:getPage></SOAP-ENV:Body> 

...它返回一個不同類型的故障:

<faultstring>org.xml.sax.SAXException: Bad types (int -> class java.lang.String)</faultstring> 

如果我接受請求,將int更改爲long並使用SoapUI進行嘗試,它工作得很好。

我也曾嘗試使用__soapCall稱呼它,但結果是相似的:

$page = $soapClient -> __soapCall('getPage', array('in0'=>$token,'in1'=>$confluence_article_id)); 

有一個相關的PHP bug reportanother one,並且discussion on Atlassian forums,但沒有人幫助我。

到目前爲止,最好的建議是通過刪除其他getPage定義並將其保存在本地某處來調整WSDL。

回答

0

如果我沒記錯的話,你可以使用關聯數組,而不是前調用該函數:

//Page getPage(String token, String spaceKey, String pageTitle) 
$soapClient->getPage(array("token" => $token,"spaceKey" => $spaceKey,"pageTitle" => $pageTitle)); 

沒有測試,標準的警告適用

+0

感謝您的回答,但我想我試過,也沒有成功(我不再參與該項目,所以我無法驗證)。我最終使用了一個已經刪除了另一個getPage定義的WSDL的調整版本。無論如何,接受你的答案:) – jarnoan 2010-03-08 11:13:21