[英]Difficulty Building XML-RPC.NET Client (To use with Moodle)
我正在使用CookComputing XML-RPC庫來構建C#控制台客戶端,以便在Moodle(一個開源學習管理系統)上執行API方法。 服務器正在使用ZEND XML-RPC。
當我運行代碼時,我得到一個TypeLoadException是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。
TypeLoadException的一個可能原因是將XML-RPC.NET重建為.NET 4.0程序集。 如果這樣做,您需要包含以下代碼行:
[assembly: SecurityRules(SecurityRuleSet.Level1)]
這將.NET 2安全透明度規則應用於程序集。
如上所述,在以下情況下向AssemblyInfo.cs添加附加信息對我有用: - Visual Studio Express 2010 - XML-RPC.net的目標框架:4.0(完整,非客戶端) - XML-RPC版本:v2.5.0
通過使用較新的Visual Studio 2010支持的XML-RPC構建以及上面建議的相應安全性調整,似乎已解決了此問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.