Joomla 和 XMLRPC:“传递给方法的参数不正确...”

发布于 2024-08-23 20:21:47 字数 4041 浏览 5 评论 0原文

我一直在尝试为 Joomla 1.5 编写一个简单的 echo 服务,但没有成功。 我的代码是这样的:

echo.php:

<?php

defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.plugin.plugin');


class plgXMLRPCEcho extends JPlugin{

    function plgXMLRPCEcho(&$subject, $config){
        parent::__construct($subject, $config);
    }


    function onGetWebServices(){
       global $xmlrpcString;

        $services = array();

        // Site search service
        $services['echo.echoService'] = array(
            'function' => 'plgXMLRPCEchoServices::echoService',
            'docstring' => 'Returns its parameter.',
            'signature' => array(array($xmlrpcString))
            );

        return $services;
    }

}


class plgXMLRPCEchoServices{    
    function echoService($key){
        return $key;    
    }
}

echo.xml:

   <?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="plugin" group="xmlrpc">
    <name>XML-RPC - Echo API</name>
    <author>G. N. Mueller</author>
    <creationDate>February 2010</creationDate>
    <copyright>
        Copyright (C) 2010 - 2013 G. Mueller. All rights reserved.
    </copyright>
    <license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
    <authorEmail>[email protected]</authorEmail>
    <authorUrl>www.joomla.org</authorUrl>
    <version>1.0</version>
    <description>Joomla! XML-RPC Echo API</description>
    <files>
        <filename plugin="echo">echo.php</filename>
    </files>
        <params>
        <param name="key" type="string" default=""
            label="hello" description="echo param" />
    </params>
</install>

我的客户端,client.py:

import xmlrpclib


url = 'http://www.live-grammar.com/xmlrpc/index.php'
proxy = xmlrpclib.ServerProxy(url, verbose=True)
print proxy.system.listMethods()
print proxy.system.methodSignature('echo.echoService')
print proxy.echo.echoService([['hello']])

输出是这样的:

['echo.echoService', 'system.listMethods', 'system.methodHelp', 'system.methodSignature', 'system.multicall', 'system.getCapabilities']

[['string']]

body: '<?xml version="1.0"?>\n<methodResponse>\n<fault>\n<value>\n<struct><member><name>faultCode</name>\n<value><int>3</int></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string>Incorrect parameters passed to method: No method signature matches number of parameters</string></value>\n</member>\n</struct>\n</value>\n</fault>\n</methodResponse>'
Traceback (most recent call last):
  File "jav/rpc_client.py", line 11, in <module>
    print proxy.echo.echoService([['hello']])
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line 1199, in __call__
    return self.__send(self.__name, args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line 1489, in __request
    verbose=self.__verbose
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line 1253, in request
    return self._parse_response(h.getfile(), sock)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line 1392, in _parse_response
    return u.close()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line 838, in close
    raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault 3: 'Incorrect parameters passed to method: No method signature matches number of parameters'>

谁能告诉我我做错了什么?我是 Joomla 的新手。非常感谢任何帮助。 谢谢, 格洛丽亚

I've been trying to write a simple echo service for Joomla 1.5, but with no success.
My code is this:

echo.php:

<?php

defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.plugin.plugin');


class plgXMLRPCEcho extends JPlugin{

    function plgXMLRPCEcho(&$subject, $config){
        parent::__construct($subject, $config);
    }


    function onGetWebServices(){
       global $xmlrpcString;

        $services = array();

        // Site search service
        $services['echo.echoService'] = array(
            'function' => 'plgXMLRPCEchoServices::echoService',
            'docstring' => 'Returns its parameter.',
            'signature' => array(array($xmlrpcString))
            );

        return $services;
    }

}


class plgXMLRPCEchoServices{    
    function echoService($key){
        return $key;    
    }
}

echo.xml:

   <?xml version="1.0" encoding="utf-8"?>
<install version="1.5" type="plugin" group="xmlrpc">
    <name>XML-RPC - Echo API</name>
    <author>G. N. Mueller</author>
    <creationDate>February 2010</creationDate>
    <copyright>
        Copyright (C) 2010 - 2013 G. Mueller. All rights reserved.
    </copyright>
    <license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
    <authorEmail>[email protected]</authorEmail>
    <authorUrl>www.joomla.org</authorUrl>
    <version>1.0</version>
    <description>Joomla! XML-RPC Echo API</description>
    <files>
        <filename plugin="echo">echo.php</filename>
    </files>
        <params>
        <param name="key" type="string" default=""
            label="hello" description="echo param" />
    </params>
</install>

My client, client.py:

import xmlrpclib


url = 'http://www.live-grammar.com/xmlrpc/index.php'
proxy = xmlrpclib.ServerProxy(url, verbose=True)
print proxy.system.listMethods()
print proxy.system.methodSignature('echo.echoService')
print proxy.echo.echoService([['hello']])

And the output is this:

['echo.echoService', 'system.listMethods', 'system.methodHelp', 'system.methodSignature', 'system.multicall', 'system.getCapabilities']

[['string']]

body: '<?xml version="1.0"?>\n<methodResponse>\n<fault>\n<value>\n<struct><member><name>faultCode</name>\n<value><int>3</int></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string>Incorrect parameters passed to method: No method signature matches number of parameters</string></value>\n</member>\n</struct>\n</value>\n</fault>\n</methodResponse>'
Traceback (most recent call last):
  File "jav/rpc_client.py", line 11, in <module>
    print proxy.echo.echoService([['hello']])
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line 1199, in __call__
    return self.__send(self.__name, args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line 1489, in __request
    verbose=self.__verbose
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line 1253, in request
    return self._parse_response(h.getfile(), sock)
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line 1392, in _parse_response
    return u.close()
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xmlrpclib.py", line 838, in close
    raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault 3: 'Incorrect parameters passed to method: No method signature matches number of parameters'>

Can anyone tell me what I'm doing wrong? I'm new to Joomla. Any help is much appreciated.
Thanks,
Gloria

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素食主义者 2024-08-30 20:21:47

您的 rpc 的签名是一组变体方法类型。每个方法类型的形式为:[返回类型,参数类型...]。

所以正确的签名是:array(array($xmlrpcString, $xmlrpcString))。这表示您有一个非重载的方法,它接受一个字符串并返回一个字符串。

The signature of your rpc is an array of variant method types. Each method type is of the form: [return type, arg types...].

So the correct signature is: array(array($xmlrpcString, $xmlrpcString)). This says you have a non-overloaded method which takes a string and returns a string.

软糖 2024-08-30 20:21:47

谢谢你解决了我的问题。我从 Blogger API 和 Joomla 附带的 XML RPC Joomla API 复制了代码,它们的签名都有相同的错误。
我不明白为什么他们分发不起作用的代码!这真是太烦人了。

Thank you that solved my problem. I had copied the code from the Blogger API and the XML RPC Joomla API that came with Joomla which both have the same mistake in the signatures.
I don't understand why they distribute code that doesn't work!! This is bloody annoying.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文