4

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.

Ray
  • 1,422
  • 2
  • 21
  • 39

3 Answers3

6

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.

Charles Cook
  • 1,989
  • 1
  • 16
  • 7
  • This doesn't appear to solve the problem. I am building for .NET 4.0, and adding this to AssemblyInfo.cs results in the same exception. – Ray Sep 05 '11 at 21:16
  • 1
    This worked for me for .NET 4.6.2 for either xmlrpc.net v2.5.0 or v3.0.0.270 -- after I put the ```[assembly: SecurityRules(SecurityRuleSet.Level1)]``` in the xmlrpc project's AssemblyInfo.cs and my main project's files. – gridtrak Jun 07 '17 at 18:22
1

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

Björn
  • 51
  • 2
0

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.

Ray
  • 1,422
  • 2
  • 21
  • 39