Integrating a C# app with Moodle using XML-RPC

We’ll make RPC calls to Moodle using MNet using a simple example. Our objective is to check if a user name / password combination is valid using the email auth plugin.

What we need

We’ll be using the following tools in this post:

  • A C# compiler, or the free Visual C# Express IDE

  • An XML-RPC library, the one we’ll use can be obtained at

  • SQL Server 2008 Express database

  • Moodle installation (using 1.9.9+) using an external database (we use SQL Server 2008 Express)

Enable MNet networking in Moodle

Use the admin page to enable MNet networking. Instructions to do so are provided in the Moodle Docs at

Add Trusted Hosts

Add the IP address from where you’ll make the calls, to the list of trusted hosts. You then don’t need to use encryption in XML-RPC calls, but don’t use this over a public network. On the site administration page navigate to Networking, XML-RPC hosts.

Publish methods through MNet

Modify the auth email plugin located at auth\email\auth.php, to publish its methods through MNet.

* Provides the allowed RPC services from this class as an array.
* @return array Allowed RPC services.
function mnet_publishes() {
  $servicelist = array();

  $service['name'] = 'auth';
  $service['apiversion'] = 1;
  $service['methods'] = array('user_login');
  $servicelist[] = $service;

  return $servicelist;

Add RPC calls to the Moodle database

Update MNet service database tables to allow RPC calls. Run the following SQL statements using SQL Server Management Studio. If you use any other database, you may need to tweak the SQL syntax a bit.

SET IDENTITY_INSERT [moodle].[dbo].[mdl_mnet_rpc] ON
INSERT INTO [moodle].[dbo].[mdl_mnet_rpc]
SET IDENTITY_INSERT [moodle].[dbo].[mdl_mnet_rpc] OFF
SET IDENTITY_INSERT [moodle].[dbo].[mdl_mnet_service] ON
INSERT INTO [moodle].[dbo].[mdl_mnet_service]
SET IDENTITY_INSERT [moodle].[dbo].[mdl_mnet_service] OFF
SET IDENTITY_INSERT [moodle].[dbo].[mdl_mnet_service2rpc] ON
INSERT INTO [moodle].[dbo].[mdl_mnet_service2rpc]
SET IDENTITY_INSERT [moodle].[dbo].[mdl_mnet_service2rpc] OFF
INSERT INTO [moodle].[dbo].[mdl_mnet_host2service]

Create C# app

The following code sample shows how you can use XML-RPC to call the method user_login. First, we need to create an interface that will be implemented by the framework.

public interface IMoodle : IXmlRpcProxy
  string [] ListMethods();
  bool Login(string user, string password);

Next, we create a proxy for the interface, set the service URL and call the method.

private IMoodle moodleProxy;
moodleProxy = XmlRpcProxyGen.Create<IMoodle>();
moodleProxy.Url = "";
bool result = moodleProxy.Login("dkt", "pwd"); // returns true if successful or else false

Add IIS Smooth Streaming support to Moodle’s Multimedia Plugins Filter

We use the Smooth Streaming Player provided by the Silverlight Media Framework project at

Download and unzip the contents of smooth streaming player binaries to the filter\mediaplugin folder of your Moodle installation.

Modify filter.php in the same folder. Add the following lines to the function called filter, at the appropriate location.

if ($CFG->filter_mediaplugin_enable_ism) {
  $search = '/<a.*?href="([^<]+\.ism\/Manifest)"[^>]*>.*?<\/a>/is';
  $newtext = preg_replace_callback($search, 'mediaplugin_filter_ism_callback', $newtext);
if ($CFG->filter_mediaplugin_enable_ism) {
  $search = '/<a.*?href="([^<]+\.isml\/Manifest)"[^>]*>.*?<\/a>/is';
  $newtext = preg_replace_callback($search, 'mediaplugin_filter_ism_callback', $newtext);

To the same file add the following function.

function mediaplugin_filter_ism_callback($link, $autostart=false) {
  global $CFG;
  $url = $link[1];
  if (empty($link[3]) or empty($link[4])) {
    $mpsize = '';
    $size = 'width="600" height="400"';
    $autosize = 'true';
  } else {
    $size = 'width="'.$link[3].'" height="'.$link[4].'"';
    $mpsize = $size;
    $autosize = 'false';
  $mimetype = mimeinfo('type', $url);
  $autostart = $autostart ? 'true' : 'false';
  return $link[0].
<!--object data="data:application/x-silverlight-2," type="application/x-silverlight-2" '.$size.'>
<param name="source" value="'.$CFG->wwwroot.'/filter/mediaplugin/SmoothStreamingPlayer.xap"/>
<param name="background" value="white" />
<param name="minRuntimeVersion" value="4.0.50401.0" />
<param name="autoUpgrade" value="true" />
<param name="InitParams" value="selectedcaptionstream=textstream_eng,mediaurl='.$url.'" />
<a href="" style="text-decoration:none">
<img src="" alt="Get Microsoft Silverlight" style="border-style:none"/>

Modify filtersettings.php in the same folder. Add the following line at the appropriate location.

$settings->add(new admin_setting_configcheckbox('filter_mediaplugin_enable_ism', get_string('mediapluginism','admin'), '', 1));

Finally, we need to add a string resource used by the settings page of the plugin. Edit lang\en_utf8\admin.php (or the appropriate language file) and add the following:

$string['mediapluginism'] = 'Enable .ism (IIS Smooth Streaming) filter';

Here’s a screenshot of the filter in action.

A URL to a smooth stream, live or on demand, does not just end with .isml or .ism, you have to add a /Manifest after that. Without this the filter will not recognize the URL as a smooth stream.

This has been tested with the latest Moodle weekly build 1.9.9+ but should be easy to adapt for version 2.

If you encounter any issue with the Smooth Streaming Player, try to get a newer version from the project site, or report the issue to them. If you have any other suggestion, please leave a comment.

Happy smooth streaming!