首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >难以构建XML-RPC.NET客户端(要与Moodle一起使用)

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

Stack Overflow用户
提问于 2011-08-30 21:19:58
回答 3查看 3.5K关注 0票数 4

我正在使用CookComputing XML来构建一个C#控制台客户端,以便在Moodle (一个开放源代码的学习管理系统)上执行C#方法。服务器正在使用。

当我运行代码时,我得到一个TypeLoadException是未处理的,它指的是以下一行:

代码语言:javascript
复制
System.Object myResults = proxy.moodle_user_get_user_by_id(myUserIds);

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

我的客户端代码是:

代码语言:javascript
复制
...
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文档是:

代码语言:javascript
复制
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
} 
)} 
)

有什么建议是有帮助的,包括如果我在正确的位置传递标记?

蒂娅。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-09-06 17:48:18

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

票数 0
EN

Stack Overflow用户

发布于 2011-08-31 18:34:35

TypeLoadException的一个可能原因是将XML-RPC.NET重新构建为.NET 4.0程序集。如果这样做,您需要包括以下代码:

代码语言:javascript
复制
[assembly: SecurityRules(SecurityRuleSet.Level1)]

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

票数 6
EN

Stack Overflow用户

发布于 2011-10-13 09:09:04

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7249951

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档