如何使用PHP SoapClient调用重载SOAP方法? [英] How to call overloaded SOAP method with PHP SoapClient?

查看:90
本文介绍了如何使用PHP SoapClient调用重载SOAP方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Confluence soap api defines two methods with the same name but different parameters:


  • Page getPage(String token,long pageId)-返回单个Page(根据文档,第二个参数是String,但是在WSDL中很长)

  • Page getPage(字符串令牌,字符串spaceKey,字符串pageTitle)-返回单个页面

我需要使用PHP SoapClient调用带有两个参数的方法。在WSDL模式下,SoapClient坚持使用三参数之一。在非WSDL模式下,我设法用两个参数进行了调用,但是我不能使第二个参数的类型变长。如何让SoapClient调用带有正确类型的两个参数的getPage?

I would need to call the method with two parameters using PHP SoapClient. In WSDL mode SoapClient insists on using the three-parameter one. In non-WSDL mode I managed to make a call with two parameters, but I cannot make the type of the second parameter to be long. How can I get the SoapClient to call getPage with two parameters with the correct types?

这是我到目前为止所做的:

Here's what I've done so far:

在WSDL模式下使用SoapClient ...

Using SoapClient in WSDL mode...

$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);

...生成对三参数方法的请求(仅显示主体)...

...produces a request for the three-parameter method (only body shown)...

<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>

...这会导致故障:

...which causes fault:

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

具有该ID的页面确实存在并且可以查看,我可以通过输入以下内容来确认

The page with that ID does exist and I am allowed to see it, which I can confirm by making the correct kind of request with SoapUI.

使用SoapClient是非WSDL模式...

Using SoapClient is non-WSDL mode...

$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为字符串时,请求为...

...produces a request for the two-parameter method with incorrect type for the second parameter. When $confluence_article_id is string, the request is...

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

...它返回与上面相同的错误:

...which returns the same fault as above:

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

当$ confluence_article_id为整数时,请求为...

When $confluence_article_id is integer, the request is...

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

...这会返回另一种错误:

...which returns a different kind of fault:

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

如果我接受请求,请将int更改为long并与SoapUI一起尝试,效果很好。

If I take the request, change int to long and try it with SoapUI, it works just fine.

我也尝试使用__soapCall对其进行调用,但结果类似:

I have also tried to call it using __soapCall, but the results are similar:

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

有一个相关的PHP 错误报告另一,和在Atlassian论坛上进行讨论,但没有

There is a related PHP bug report and another one, and discussion on Atlassian forums, but none of them helped me.

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

So far the best suggestion has been to tweak the WSDL by removing the other getPage definition and saving it locally somewhere.

推荐答案

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

If I remember correctly you can call the function using an associative array instead ex:

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

未经测试,将应用标准警告

Not tested, standard warnings apply

这篇关于如何使用PHP SoapClient调用重载SOAP方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆