C# 难以构建XML-RPC.NET客户端(与Moodle一起使用)

C# 难以构建XML-RPC.NET客户端(与Moodle一起使用),c#,client,xml-rpc,moodle,C#,Client,Xml Rpc,Moodle,我使用CookComputing XML-RPC库试图构建一个C#console客户端,以便在Moodle(一个开源学习管理系统)上执行API方法。服务器正在使用ZEND XML-RPC 当我运行代码时,我得到一个未处理的TypeLoadException,参考这一行: System.Object myResults = proxy.moodle_user_get_user_by_id(myUserIds); 重写成员时违反了继承安全规则:“CookComputing.XmlRpc.XmlRp

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

当我运行代码时,我得到一个未处理的TypeLoadException,参考这一行:

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());
    }
  }
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.

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

[assembly: SecurityRules(SecurityRuleSet.Level1)]

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

此问题似乎已通过使用较新的Visual Studio 2010支持的XML-RPC构建以及上面建议的适当安全调整得到解决

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

这似乎无法解决问题。我正在为.NET 4.0构建,并将其添加到AssemblyInfo.cs会导致相同的异常。这对我在.NET 4.6.2中的xmlrpc.NET v2.5.0或v3.0.0.270起到了作用——在我将
[assembly:SecurityRules(SecurityRuleSet.Level1)]
放入xmlrpc项目的AssemblyInfo.cs和我的主项目文件之后。