简体   繁体   English

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

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

Confluence soap api defines two methods with the same name but different parameters: Confluence soap api定义了两个名称相同但参数不同的方法:

  • Page getPage(String token, long pageId) - returns a single Page (according to the documentation the second parameter is String, but in WSDL it is long) Page getPage(String token,long pageId) - 返回单个页面(根据文档,第二个参数是String,但在WSDL中它很长)
  • Page getPage(String token, String spaceKey, String pageTitle) - returns a single Page Page getPage(String token,String spaceKey,String pageTitle) - 返回单个页面

I would need to call the method with two parameters using PHP SoapClient. 我需要使用PHP SoapClient使用两个参数调用该方法。 In WSDL mode SoapClient insists on using the three-parameter one. 在WSDL模式下,SoapClient坚持使用三参数。 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. 在非WSDL模式下,我设法用两个参数进行调用,但我不能使第二个参数的类型变长。 How can I get the SoapClient to call getPage with two parameters with the correct types? 如何让SoapClient使用正确类型的两个参数调用getPage?

Here's what I've done so far: 这是我到目前为止所做的:

Using SoapClient in WSDL mode... 在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);

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

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. 具有该ID的页面确实存在,我可以看到它,我可以通过使用SoapUI发出正确的请求来确认。

Using SoapClient is non-WSDL mode... 使用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);

...produces a request for the two-parameter method with incorrect type for the second parameter. ...生成对双参数方法的请求,第二个参数的类型不正确。 When $confluence_article_id is string, the request is... 当$ 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>

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

When $confluence_article_id is integer, the request is... 当$ 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>

...which returns a different kind of fault: ......返回一种不同的错误:

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

If I take the request, change int to long and try it with SoapUI, it works just fine. 如果我接受请求,将int更改为long并使用SoapUI进行尝试,它可以正常工作。

I have also tried to call it using __soapCall, but the results are similar: 我也尝试使用__soapCall调用它,但结果类似:

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

There is a related PHP bug report and another one , and discussion on Atlassian forums , but none of them helped me. 有一个相关的PHP 错误报告另一个 ,并在Atlassian论坛上讨论 ,但没有一个帮助我。

So far the best suggestion has been to tweak the WSDL by removing the other getPage definition and saving it locally somewhere. 到目前为止,最好的建议是通过删除其他getPage定义并在某处将其保存在本地来调整WSDL。

If I remember correctly you can call the function using an associative array instead ex: 如果我没记错的话你可以使用关联数组来调用函数,而不是ex:

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

Not tested, standard warnings apply 未经测试,标准警告适用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM