构建 XML-RPC.NET 客户端的困难(与 Moodle 一起使用)

发布于 2024-12-02 08:01:08 字数 2941 浏览 1 评论 0原文

我正在使用 CookComputing XML-RPC 库尝试构建 C# 控制台客户端,以便在 Moodle(一个开源学习管理系统)上执行 API 方法。服务器使用 ZEND XML-RPC。

当我运行代码时,我收到 TypeLoadException was Unhandled,指的是这一行:

System.Object myResults = proxy.moodle_user_get_user_by_id(myUserIds);

“重写成员时违反了继承安全规则:'CookComputing.XmlRpc.XmlRpcFaultException.GetObjectData(System.Runtime. Serialization.SerializationInfo、System.Runtime.Serialization.StreamingContext)'。重写方法的安全可访问性必须与被覆盖的方法。”

我的客户端代码是:

...
using CookComputing.XmlRpc;


[XmlRpcUrl("http://moodle.ourcompany.com/webservice/xmlrpc/server.php?wstoken=somereallylongtokenstring")]
public interface IMoodleUserGetUsersById : IXmlRpcProxy
{
    [XmlRpcMethod("moodle_user_get_users_by_id")]
    System.Object moodle_user_get_user_by_id(int[] userIds);
}

namespace Moodle_test_api1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Testing XML-RPC Services for Moodle!");

            IMoodleUserGetUsersById proxy = XmlRpcProxyGen.Create<IMoodleUserGetUsersById>();

        int[] myUserIds = {11, 12};
        System.Object myResults = proxy.moodle_user_get_user_by_id(myUserIds);

        //Console.WriteLine("Trying Function: {0}:{1}", proxy.ToString());
    }
  }

}

我想要使用的方法的 API 文档是:

moodle_user_get_users_by_id: Get users by id.


Arguments
---------
userids (Required)

General structure

list of ( 
int   //user ID
)

XML-RPC (PHP structure)

[userids] =>
    Array 
        (
        [0] => int
        )

Response:

  General structure
  -----------------
list of ( 
object {
id double   //ID of the user
username string   //Username policy is defined in Moodle security config
firstname string   //The first name(s) of the user
lastname string   //The family name of the user
email string   //An email address - allow email as root@localhost
auth string   //Auth plugins include manual, ldap, imap, etc
confirmed double   //Active user: 1 if confirmed, 0 otherwise
idnumber string   //An arbitrary ID code number perhaps from the institution
lang string   //Language code such as "en", must exist on server
theme string   //Theme name such as "standard", must exist on server
timezone string   //Timezone code such as Australia/Perth, or 99 for default
mailformat int   //Mail format code is 0 for plain text, 1 for HTML etc
description string   //User profile description
descriptionformat int   //User profile description format
city string   //Home city of the user
country string   //Home country code of the user, such as AU or CZ
customfields  Optional //User custom fields (also known as user profil fields)
list of ( 
object {
type string   //The name of the custom field
value string   //The value of the custom field
} 
)} 
)

任何建议都会有帮助,包括如果我正在将令牌传递到正确的位置吗?

TIA。

I am using the CookComputing XML-RPC Library in an attempt to build a C# console client in order to execute API methods on Moodle (an open-source Learning management system). The server is using ZEND XML-RPC.

When I run the code, I get a TypeLoadException was Unhandled, referring to this line:

System.Object myResults = proxy.moodle_user_get_user_by_id(myUserIds);

"Inheritance security rules violated while overriding member: 'CookComputing.XmlRpc.XmlRpcFaultException.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden."

My Client code is:

...
using CookComputing.XmlRpc;


[XmlRpcUrl("http://moodle.ourcompany.com/webservice/xmlrpc/server.php?wstoken=somereallylongtokenstring")]
public interface IMoodleUserGetUsersById : IXmlRpcProxy
{
    [XmlRpcMethod("moodle_user_get_users_by_id")]
    System.Object moodle_user_get_user_by_id(int[] userIds);
}

namespace Moodle_test_api1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Testing XML-RPC Services for Moodle!");

            IMoodleUserGetUsersById proxy = XmlRpcProxyGen.Create<IMoodleUserGetUsersById>();

        int[] myUserIds = {11, 12};
        System.Object myResults = proxy.moodle_user_get_user_by_id(myUserIds);

        //Console.WriteLine("Trying Function: {0}:{1}", proxy.ToString());
    }
  }

}

The API documentation for the method I want to utilize is:

moodle_user_get_users_by_id: Get users by id.


Arguments
---------
userids (Required)

General structure

list of ( 
int   //user ID
)

XML-RPC (PHP structure)

[userids] =>
    Array 
        (
        [0] => int
        )

Response:

  General structure
  -----------------
list of ( 
object {
id double   //ID of the user
username string   //Username policy is defined in Moodle security config
firstname string   //The first name(s) of the user
lastname string   //The family name of the user
email string   //An email address - allow email as root@localhost
auth string   //Auth plugins include manual, ldap, imap, etc
confirmed double   //Active user: 1 if confirmed, 0 otherwise
idnumber string   //An arbitrary ID code number perhaps from the institution
lang string   //Language code such as "en", must exist on server
theme string   //Theme name such as "standard", must exist on server
timezone string   //Timezone code such as Australia/Perth, or 99 for default
mailformat int   //Mail format code is 0 for plain text, 1 for HTML etc
description string   //User profile description
descriptionformat int   //User profile description format
city string   //Home city of the user
country string   //Home country code of the user, such as AU or CZ
customfields  Optional //User custom fields (also known as user profil fields)
list of ( 
object {
type string   //The name of the custom field
value string   //The value of the custom field
} 
)} 
)

Any suggestions would be helpful, including if I am passing in the token in the right spot?

TIA.

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

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

发布评论

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

评论(3

穿透光 2024-12-09 08:01:08

TypeLoadException 的一个可能原因是将 XML-RPC.NET 重建为 .NET 4.0 程序集。如果执行此操作,则需要包含以下代码行:

[assembly: SecurityRules(SecurityRuleSet.Level1)]

这会将 .NET 2 安全透明度规则应用于程序集。

A possible cause of the TypeLoadException is rebuilding XML-RPC.NET as .NET 4.0 assembly. If you do this you need to include the following line of code:

[assembly: SecurityRules(SecurityRuleSet.Level1)]

This applies the .NET 2 security transparency rules to the assembly.

鹤仙姿 2024-12-09 08:01:08

在以下情况下,如上所述将附加信息添加到 AssemblyInfo.cs 对我有用:
- Visual Studio Express 2010
- XML-RPC.net 的目标框架:4.0(完整,非客户端)
- XML-RPC版本:v2.5.0

Adding the additional information to AssemblyInfo.cs as described above worked for me in the following situation:
- Visual Studio Express 2010
- Target framework for XML-RPC.net: 4.0 (full, not client)
- XML-RPC version: v2.5.0

饮湿 2024-12-09 08:01:08

这个问题似乎已经通过使用较新的 Visual Studio 2010 支持的 XML-RPC 版本并结合上面建议的适当安全调整来解决。

This problem seems to have been solved by using the newer Visual Studio 2010 supported build of XML-RPC, combined with the appropriate security adjustments recommended above.

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