Skip to content


Subversion checkout URL

You can clone with
Download ZIP
This is a collection of Java classes that allow easy access to OK Tech Moodle Web Service in SOAP protocol from Java clients using KSoap2 library such as Android but also regular java programs . It also contains a KSoap2 generating stub tool (wsdl2ksoap) based on Apache Axis 1.4 tool wsdl2java.
Branch: master
Pull request Compare This branch is even with patrickpollet:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


This is a collection of Java classes that allow easy access to OK Tech Moodle Web Service from Java clients using KSoap2 library such as Android but also regular java programs It also contains a KSoap2 generating stub tool (wsdl2ksoap2) based on Appacha Axis 1.4 tool wsdl2java. 

1) Usage :
Copy the dist/moodlews_ksoap2_x.x.x.jar in the classpath of your project and call its methods
See classes in net.patrickpollet.moodlews and net.patrickpollet.moodlewsold for examples

2) Running the test classes against your Moodle server :
The tests classes require the URL of a Moodle server and a login/password for an user with sufficient capabilities.
These data are expected to be in a file named

- rename the provided file to
- edit it to provide the actual informations  

package net.patrickpollet.moodlews;
public class Constantes {
	// TESTING adjust to your site
	public static final String MOODLE_URL = "http://localhost/moodle.195/";
	public  static final String LOGIN = "somemoodleuserwithgood capabilities";
	public static final String PWD = "itspassword";
	public static final boolean WS_DEBUG = false;

- rebuild your project

3) What version of OK Tech WSDL to use ? 
Historically the OK Tech WS used a manually edited WSDL file (wspp/moodlewsdl.xml) that was sent to clients (and also used by server) by a call to  http://yourmoodle/wspp/wsdl_pp.php.

The address of the service script for SOAP clients was sent at the bottom of the WSDL as http://yourmoodle/wspp/service_pp.php

In this WSDL returned data as arrays where placed in an XML attribute named courses, users ... and were extracted by an extraneous call
to a method getXXX() such as :

old java code when importing net.patrickpollet.moodlewsold.core.*  (see

			MoodleWSBindingStub moodle=new MoodleWSBindingStub(MOODLE_SERVICE,MOODLE_NAMESPACE,Constantes.WS_DEBUG);
			LoginReturn lr = moodle.login(Constantes.LOGIN, Constantes.PWD);
			int me =moodle.get_my_id(lr.getClient(),lr.getSessionkey());
			System.out.println ("me "+me);
			CourseRecord []ret = moodle.get_my_courses(lr.getClient(),lr.getSessionkey(), me,null).getCourses();

Starting at revision 1.8, another simpler wsdl file is provided (wspp/moodlewsdl2.xml) that is automatically generated by the
wshelper utility from the PHP docs comments in the class mdl_soapserver.class.php file. by the script wspp/genwsdl.php :

The new address of the wsdl is  http://yourmoodle/wspp/wsdl_pp2.php and the service script is at http://yourmoodle/wspp/service_pp2.php

In this new WSDL, returned arrays are directly available :  

new java code when importing net.patrickpollet.moodlews.core.* (see

 			Mdl_soapserverBindingStub moodle = new Mdl_soapserverBindingStub(MOODLE_SERVICE,MOODLE_NAMESPACE, Constantes.WS_DEBUG);
			LoginReturn lr = moodle.login(Constantes.LOGIN, Constantes.PWD);
 			int me = moodle.get_my_id(lr.getClient(),lr.getSessionkey());
			System.out.println("me " + me);
			// NO NEED TO CALL 	getCourses() to fetch the returned array , but parameter userid is now a String 
			CourseRecord[] ret = moodle.get_my_courses(lr.getClient(), lr.getSessionkey(), "" + me, null);

Usage of the new version i.e. classes in net.patrickpollet.moodlews is now recommended.

4) Where is the list of available operations ?
javadoc for the supported operations is online for the olwd WSDL here :

and for the new one here :
5) Updating the helper classes :
In case of evolution of the WSDL emitted by OK Tech WS, you must regenerate the stub and the helper classes using the provided 

WSDL2koap program (see org.ksoap2.wsdl package) which is a modified version of Apache's axis 1.4 WSDL2Java utility modified for KSoap2

to get a revised version with the old WSDL use 

java org.ksoap2.wsdl.WSDL2ksoap -p net.patrickpollet.moodlewsold.core -o /tmp http://yourmoodle/wspp/wsdl_pp.php

to get a revised version with the new WSDL use 

java  org.ksoap2.wsdl.WSDL2ksoap -p net.patrickpollet.moodlews.core -o /tmp http://yourmoodle/wspp/wsdl_pp2.php

in both cases you MUST have the content of lib/ directory in your classpath so from the directory where your Java IDE is placing the compiled classes (bin in Eclipse)
you should type 

java -cp '.:../lib/*' org.ksoap2.wsdl.WSDL2ksoap -p net.patrickpollet.moodlewsold.core -o /tmp http://localhost/moodle.195/wspp/wsdl_pp.php


java -cp '.:../lib/*' org.ksoap2.wsdl.WSDL2ksoap -p net.patrickpollet.moodlews.core -o /tmp http://yourmoodle/wspp/wsdl_pp2.php


PP 23/03/2011
Something went wrong with that request. Please try again.