4

Moodle(オープンソースの学習管理システム)でAPIメソッドを実行するためにC#コンソールクライアントを構築するために、CookComputingXML-RPCライブラリを使用しています。サーバーはZENDXML-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());
    }
  }

}

利用したいメソッドの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。

4

3 に答える 3

6

TypeLoadException の考えられる原因は、XML-RPC.NET を .NET 4.0 アセンブリとして再構築することです。これを行う場合は、次のコード行を含める必要があります。

[assembly: SecurityRules(SecurityRuleSet.Level1)]

これにより、.NET 2 セキュリティ透過性ルールがアセンブリに適用されます。

于 2011-08-31T18:34:35.400 に答える
1

上記のように AssemblyInfo.cs に追加情報を追加すると、次の状況でうまくいきました。

于 2011-10-13T09:09:04.967 に答える
0

この問題は、Visual Studio 2010 でサポートされている XML-RPC の新しいビルドを、上記で推奨されている適切なセキュリティ調整と組み合わせて使用​​することで解決されたようです。

于 2011-09-06T17:48:18.280 に答える