Moodle and C# - Web Service Configuration

General Tech Learning Aids/Tools 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Learning Aids/Tools related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I'm currently stuck with quite a significant issue that i'm hoping someone may be able to shed some light on, regarding configuring an XML-RPC based web service to talk between my game based learning virtual world and a dedicated Moodle site

To the best of my knowledge, from following some sparse information on how to configure a Moodle web service, i've done the following steps:

  • Enabled Web Services
  • Enabled the XML-RPC protocol
  • Edited my admin role to allow use of the protocol and creation of a token for logging in
  • Creation of a service for authenticated users which my admin has been added to

The moodle documentation sends you in a bit of a loop but from what I can see i've the check list covered

I'm now trying to plug this into the backend of my virtual world to populate my dynamic terrain engine with sets of topics,assignments etc based on what the user would have access to etc

My issue comes from the simple HttpWebRequest for retrieving the token for the user I'm using the following method to return a string containing the token

    public string GetToken(string uname,string pword)
    {
        byte[] buffer = Encoding.ASCII.GetBytes("username="+uname+"&password="+pword+"&service=reflex");

        HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url + "login/token.php?username=" + uname + "&password=" + pword + "&service=myservice");
        WebReq.Method = WebRequestMethods.Http.Post;
        WebReq.ContentType = "application/x-www-form-urlencoded";

        WebReq.ContentLength = buffer.Length;
        using(Stream PostData = WebReq.GetRequestStream())
            PostData.Write(buffer, 0, buffer.Length);

        HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
        using(StreamReader reader = new StreamReader(WebResp.GetResponseStream()))
            return token = reader.ReadToEnd();
    }

When I debug this to validate the token is generated, it throws an error saying the web service is down, but to the best of my knowledge the web service isnt called here, this uses a built in primitive php file to return a string and no more. I have checked the PostData.Write and its throwing a .Length NotSupportedException which i'm unsure as to if its having an impact upon the second using statement

I'm hoping if someone can aid regarding configuration settings that the next steps should fall into place easily as the XML-RPC dll seems quite robust and easy to use

Any help would be greatly appreciated

Many thanks Barry

profilepic.png
manpreet 2 years ago

Now resolved

Worked around to retrieve the token manually through a sql call and have the web service functioning now


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.