Building .NET Client for XML-RPC

Building .NET Client for XML-RPC

by Tony Hatfield -
Number of replies: 3

Hello,

I'm trying to build a console application under C#.NET using XML-RPC to connect to Moodle. 

Right now this is what I have, but I'm obviously missing some things here:

[code]

using CookComputing.XmlRpc;


[XmlRpcUrl("http://subdomain.ourorganization.com/webservice/xmlrpc/server.php?wstoken=nicelongstringtoken")]
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);
 
        }
    }
}

[/code]

Average of ratings: -
In reply to Tony Hatfield

Re: Building .NET Client for XML-RPC

by oneil clacken -

I am trying to do the same thing too... but I'm having problems with getting the http://mymoodle/webservice/xmlrpc/server.php?wstoken=$token to work on the moodle side... I keep getting faultcode630. Any idea how to solve that?

In reply to oneil clacken

Re: Building .NET Client for XML-RPC

by Tony Hatfield -

I have been able to successfully build a .NET client which retrieves data as expected.

The issues I encountered were versioning and security level ones. My recommendation would be to use the XML-RPC (http://www.xml-rpc.net) build that supports YOUR version of visual studio and .NET. In my case, this was .NET 4.0 + Studio 2010 (which is currently a development build).

With regards to security, you may need to add the following code to your AssemblyInfo.cs file so the project compiles with the correct settings:

using System.Security;

[assembly: SecurityRules(SecurityRuleSet.Level1)]

 

Keep in mind that changing this setting is CHANGING security rules, so weigh the implications carefully.

 

ONeil,

could you be more specific about where you are encountering the error?

In reply to Tony Hatfield

Re: Building .NET Client for XML-RPC

by Supriya Seetharam -

Hi Tony


I am calling the interface method 

  public interface IMoodle : IXmlRpcProxy

    {

 [XmlRpcMethod("moodle_file_upload")]

        CoreFilesUpload_Response CoreFilesUpload(int contextid, string component, string filearea, int itemid, string filepath, string filename, string filecontent);

}

--------------------Main Program---------------------------------------------------------------------------------------------

            int contextid = 1;

            string component = "user";

            string filearea = "private";

            int itemid = 5;

            string filepath = @"/";

            string filename = "file.txt";

            string filecontent = "this is file content";

            CoreFilesUpload_Response fileUpldResp = moodleProxy.CoreFilesUpload(contextid, component, filearea, itemid, filepath, filename, filecontent);

-------------------------------------------------------------------------------------------------------------------------

return following Exception  :

Server returned a fault exception: [12107072] File not specified | ERRORCODE: nofile 

if i specifiy file path eg : D:/filepath/ I am getting exception

 [29039061] Invalid parameter value detected | DEBUG INFO: filepath => Invalid parameter value detected: Invalid external api parameter: the server was expecting "path" type | ERRORCODE: invalidparameter


Please let me know where am i missing.thanks in advance