Using enrol_manual_enrol_users via XML-RPC.NET

Using enrol_manual_enrol_users via XML-RPC.NET

by Mike Z -
Number of replies: 2

Hello all,

I need your help with consuming the webservice:  enrol_manual_enrol_users

My client app is in ASP.NET, and I am using the XML-RPC.NET library to make XML-RPC calls to Moodle.  

I should note that I am able to successfully call the web service "core_user_get_users_by_id".  However that is a simple case. It takes an Int array as the parameter and returns an object array containing hashtables, one per user record, and with each key-value pair representing a field from the user table.

However for enrol_manual_enrol_users, I can't figure out how I should code the Method call or handle the return object.  Indeed, from the Moodle documentation, there is nothing listed under the "Response" heading for this method.

Here is what I currently have, but this is giving me a rather useless "[404] Unknown error" as the response from Moodle.  I expect the problem is because I don't really understand how to use the Struct in the method call, or how to obtain the result from Moodle's response.

 

Here is the interface definition

public interface IMoodle : IXmlRpcProxy {

[XmlRpcMethod("enrol_manual_enrol_users")]
object[] Enrol_Manual_Enrol_Users(Moodle_Enrolment[] input);      //Not sure if it should be delcared as object[] or not, as there is no Response described in the Moodle docs.

}

 

And the Struct that should represent the input parameter for the webservice

    public struct Moodle_Enrolment
    {
        public int roleid;
        public int userid;
        public int courseid;
        [XmlRpcMissingMapping(MappingAction.Ignore)]
        public int timestart;
        [XmlRpcMissingMapping(MappingAction.Ignore)]
        public int timeend;
        [XmlRpcMissingMapping(MappingAction.Ignore)]
        public int suspend;
    }

 

And here is the code that instantiates the struct, and calls the WebMethod.

           Moodle_Enrolment me = new Moodle_Enrolment();

            me.courseid = 2  //this defiinately exists in the Moodle database
            me.userid = 7;    //this defiinately exists in the Moodle database
            me.roleid = 1;   
            
            Moodle_Enrolment[] meArray = {me};       //Put the enrolment details into an array.

            try
            {
                object[] a = moodleServer.Enrol_Manual_Enrol_Users(meArray);    //not sure what the response datatype is
            }
            catch  (Exception ex)
            {

                   //Error handling code goes here

            }

When this code runs, an exception occurs on the call to Moodle, and the exception message is:

Server returned a fault exception: [404] Unknown error

 

So - can you offer any suggestions on how to fix this?  I am sure I am doing something wrong here - but the documentation on the webservice enrol_manual_enrol_users is really not helping me much.    

Unfortunately this web service is not available in the Moodle test client.  Any suggestions on how I can find out about this 404 Unknown Error?

 

Thanks for your help all,

Mike

 

 

Average of ratings: -
In reply to Mike Z

Re: Using enrol_manual_enrol_users via XML-RPC.NET

by Jordi Barajas Gines -

Hi Did you solve your problem?

In reply to Jordi Barajas Gines

Re: Using enrol_manual_enrol_users via XML-RPC.NET

by Supriya Seetharam -

HI ,

I am Novice to XML RPC Moodle integration. I am developing a c# application

Below is the code i am working with

public interface IMoodle : IXmlRpcProxy

    {

        [XmlRpcMethod("moodle_user_get_users_by_id")]

        object[] GetUserById(object[] id);

        [XmlRpcMethod("moodle_course_get_courses")]

        object[] GetCourses();

        //moodle_webservice_get_token

    }


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

          IMoodle moodleProxy;

            moodleProxy = XmlRpcProxyGen.Create<IMoodle>();

            moodleProxy.Url = "http://localhost/" + "webservice/xmlrpc/server.php?wstoken=" + "wsusertoken";

         object[] a = moodleProxy.GetCourses();


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

I am getting "Server returned a fault exception: [404] Unknown error" exception. I am not sure where am i missing. Any help will be commendable.


Thanks

Supriya