gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-10-31 23:50:40 26 4
gpt4 key购买 nike

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

  • Page getPage(String token, long pageId) - 返回单个页面(根据文档,第二个参数是字符串,但在 WSDL 中它是长的)
  • Page getPage(String token, String spaceKey, String pageTitle) - 返回单个页面

我需要使用 PHP SoapClient 调用带有两个参数的方法。在 WSDL 模式下,SoapClient 坚持使用三参数。在非 WSDL 模式下,我设法用两个参数进行调用,但我不能将第二个参数的类型设置为 long。我怎样才能让 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>

如果我接受请求,将其更改为 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));

未测试,适用标准警告

关于php - 如何用 PHP SoapClient 调用重载的 SOAP 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2086542/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com