簡體   English   中英

如何使用PHP SoapClient調用重載的SOAP方法?

[英]How to call overloaded SOAP method with PHP SoapClient?

Confluence soap api定義了兩個名稱相同但參數不同的方法:

  • Page getPage(String token,long pageId) - 返回單個頁面(根據文檔,第二個參數是String,但在WSDL中它很長)
  • Page getPage(String token,String spaceKey,String 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 錯誤報告另一個 ,並在Atlassian論壇上討論 ,但沒有一個幫助我。

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

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

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

未經測試,標准警告適用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM