Quantcast
Channel: Web services
Viewing all articles
Browse latest Browse all 2361

Using enrol_manual_enrol_users via XML-RPC.NET

$
0
0
by Mike Z.  

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

 

 


Viewing all articles
Browse latest Browse all 2361

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>