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

Confluence soap api定义了两个名称相同但参数不同的方法:

>页面getPage(String token,long pageId)-返回单个页面(根据文档,第二个参数是String,但是在WSDL中它很长)
>页面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.

解决方法:

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

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

未经测试,适用标准警告

上一篇:Confluence 6.15 附件(Attachments )宏


下一篇:Confluence 6 分享一个文件