如何使用PHP SoapClient调用重载的SOAP方法?

时间:2010-01-18 14:11:15

标签: php soap confluence

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 bug reportanother one以及discussion on Atlassian forums,但它们都没有帮助我。

到目前为止,最好的建议是通过删除其他getPage定义并将其保存在本地某处来调整WSDL。

1 个答案:

答案 0 :(得分:0)

如果我没记错的话你可以使用关联数组来调用函数,而不是ex:

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

未经测试,标准警告适用

相关问题