xml-rpc problems

xml-rpc problems

by Bill Hoag -
Number of replies: 18

I've got an xml-rpc module that can that can be used by an external client to make a course announcement.

In Moodle 1.9.5, set up was:

  1. Copy my rpclilb.php to .../htdocs/moodle/mod/forum
  2. Add name and description entries to .../htdocs/moodle/lang/en_utf8/forum.php
  3. Enable networking and add the client's IP address to the XML-RPC trusted hosts.

I recently tried my module with 1.9.9 and initially it did not work. After tracing error codes to the source and backtracking, I found that mnet/lib.php:mnet_permit_rpc_call() needs some entries in tables mnet_host2service, mnet_service, mnet_service2rpc, and mnet_rpc. I put these in and my module works. With 1.9.9, is there a UI or automated way of making these table entries?

I also tried 2.0 RC1 and have had no success getting my module working. I followed the above steps and also tried to follow this thinking the various mnet_ table entries would be created automatically. I end up with Fault 7021: 'The transport method you are trying to use is not permitted.' The snag seems to be with mnet/remote_client.php:plaintext_is_ok() which does not recognize my box as a trusted host. If I hack plaintext_is_ok() to return true, I get Fault 711: 'The signature verification failed.' Do all XML-RPC client calls need to be signed now, and if so, how?

Are there any XML-RCP server and client samples for 2.0?

Thanks in advance for any help!

-Bill

Average of ratings: -
In reply to Bill Hoag

Re: xml-rpc problems

by Jérôme Mouneyrac -

Hi Bill,
it seems to be a Mnet related question, try to repost there: http://moodle.org/mod/forum/view.php?id=6976
cheers,
Jerome

In reply to Jérôme Mouneyrac

Re: xml-rpc problems

by juan marin -

Jerome,

I don't get why this is an Mnet related question.  Why would we ask for xml-rpc server and client examples for 2.0 somewhere else?

I don't think that the WebServices subject in general for 2.0 is documented in a logical way.  We need some answers.

In reply to juan marin

Re: xml-rpc problems

by Jérôme Mouneyrac -

Hi Juan,
most of the Bill post is Mnet code related. I agree I should have at least answer the last question. I got carried away by all the Mnet thing. Anyway Bill was right to post Mnet web service question here, I forgot that Mnet was also a collection of web service.

To answer the last question, are there any XML-RCP server and client samples for 2.0: the new Moodle 2.0 xmlrpc server is in /webservice/xmlrpc/server.php and you can also find a PHP xml-rpc client for this server in /webservice/xmlrpc/lib.php. Finally you can have look at /webservice/xmlrpc/testwebservice.php to know how to use it. The main documentation about web service is there: http://docs.moodle.org/en/Web_Services.

A PHP Client for Moodle 2.0 web service could be something like:

require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
$xmlrpcclient = new webservice_xmlrpc_client(HTTP_REMOTE_MOODLE  . '/webservice/xmlrpc/server.php', $token);
$function = 'moodle_group_get_groups';

$groupids = array(1, 2, 3); 
$params = array('groupids' => $groupids); 
$groups = $xmlrpcclient->call($function, $params);

I hope it helps,
Cheers.

In reply to Jérôme Mouneyrac

Re: xml-rpc problems

by juan marin -

Hi Jerome,

I appreciate your explanation.  I guess we don't mean to ask for you guys to explain xmlrpc from scratch here and I guess this would not be the place since we can get this elsewhere.

I appreciate the links you sent, the most important ones get to a dead-end pointing to some issue tracking link.

I like the client sample that you sent with your answer; I also appreciate that you seem to be the only active participant on fixing these issues.  I hope that by now, you guys have noticed that everyone is starving for methods to integrate Moodle to other applications and that we are looking to web-services to help us do that.

Thanks,

JC

 

 

 

 

 

 

In reply to juan marin

Re: xml-rpc problems

by juan marin -

Hi,

I used your client code to try using the lib.php file outside of Moodle and it did not work.  When I looked at it, it requires resources from Moodle itself and I modified those to the external application I am trying to integrate with Moodle.

After fixing that, I get the following error:

Strict Standards: Declaration of webservice_xmlrpc_client::call() should be compatible with that of Zend_XmlRpc_Client::call() in C:\apache2\htdocs\xmlrpc\lib.php on line 23

It appears to be that the override function being used on lib.php is not the same signature as the Zend one.  Perhaps it is having issues with having to send the authentication token in the URI instead of it being part of the $params.



In reply to juan marin

Re: xml-rpc problems

by Jérôme Mouneyrac -

Hi Juan,

the Moodle xmlrpc client is just for Moodle. Don't bother with it, use the Zend client in an external application.

In reply to Jérôme Mouneyrac

Re: xml-rpc problems

by juan marin -

I did that with your code and that function doesn't work.  I get an error stating an exeption with the access module.

I think you created an issue for that particular problem in the Moodle Issue Tracking DB.

Is there any function that works from the server.php?  Could I add a user?

What would adding a moodle user code look like?

 

In reply to juan marin

Re: xml-rpc problems

by Jérôme Mouneyrac -

Hi Juan,

sorry I don't understand your problem. Which issue number are you talking about?

All core web service servers should work with all core web service functions, otherwise it's a bug. If you find a bug please fill an issue in the tracker.

You can add an user with the web service function moodle_user_create_users, there is some example of usage in the webservice/simpletest/testwebservice.php file.

Cheers

In reply to Jérôme Mouneyrac

Re: xml-rpc problems

by juan marin -

Hi Jerome,
I have used a couple of XML-RPC frameworks (Zend and IXR).  I created sample clients with both of them attempting to get a course list by following the code on your sample.  I tried both, simple and token authentication for a webservice user that has been configured as per the documentation you point to. The result of my tests is that they all fail because of the same reason.  I get an error back from the Moodle webservice stating that there was an "access control exception".  This seems to reveal that the xml-rpc interface is working but something deeper in the stack is not on the Moodle side.

I looked at the entire return xml to see if there was a clearer explanation than that and there is nothing else being returned.  I get the same error when I use the test client on Moodle.

If this is a legitimate authentication error, shouldn't it be clearer as to the origin of the problem?  Is there a log file or some debug parameter I can use to troubleshoot webservice issues?

 

In reply to juan marin

Re: xml-rpc problems

by Jérôme Mouneyrac -

Hi Juan,

it's a legitimate authentication error. There is an issue about the log not being well displayed, I've just written an issue for that: MDL-25943

If you use the token authentication method, check the following:
1- the user associated to the token has a the capability matching the web service procotol ( in your case 'webservice/xmlrpc:use') 
2- the token is correct, not expired, not ip restricted (check in the admin panel)
3- the token is associated to a service containing the called web service function

Your problem should come from one of these three things.

In reply to Jérôme Mouneyrac

Re: xml-rpc problems

by juan marin -

Hi Jerome,

Thanks for your response.

Here is what I do know:

1.  The token is allowed access to xml-rpc.

2.  The token is correct.

Here is what I don't know:

The service I am using doesn't show-up anywhere to be associated with a token.  I am using the "sample" webservice that comes with Moodle.  Do I have to register the "sample" somewhere to start with?  If so, how do I go about this?

Thanks again for your help.

 

JC

In reply to juan marin

Re: xml-rpc problems

by Jérôme Mouneyrac -

There is two tutorials explaining how to setup web service:

http://docs.moodle.org/en/How_to_enable_web_services_for_ordinary_users

http://docs.moodle.org/en/How_to_enable_web_services_for_an_external_system

From what I remember there is no "sample" service created by default, the Moodle administrator has to do it.

Good luck.

In reply to Jérôme Mouneyrac

Re: xml-rpc problems

by juan marin -

Jerome,

This is very confusing from my side.  What comes with moodle at moodleroot/webservice/xmlrpc/server.php, isn't that a sample webservice for which there is a "UnitTest" and a "Sample Client" coded for as part of Moodle?  That is what I thought was the target for the client code you previously suggested.

Both those tutorials finish without ever stating HOW to access what they just created in the previous steps.  This is why we are growing increasingly frustrated, just how many layers does this onion have?  Enable users, enable roles, enable funcions, enable authentication tokens and serve them from where exactly?

I have created one of those "services" using the "tutorial";  it is called "mainservice",  how do I go about accessing it?

Sorry if I seem frustrated but I am.

Kind regards,

JC

 

 

In reply to juan marin

Re: xml-rpc problems

by Jérôme Mouneyrac -

Yes at the moment the whole web service thing is complicated. Because it's all new, for security reasons, mainly only experienced Moodle administrator and experienced web service php coder can manage their way into it. So we limit the damage of bad usage.

Moodle SOAP and XMLRPC servers are basically just Zend server so if you follow Zend documentation you should be able to write a client http://framework.zend.com/manual/en/zend.xmlrpc.client.html.

There are some Moodle web service function documentation available if you go into a user (non admin) Settings > Profile > security keys. You need to enable it into Admin > Plugins > Webservice > Manage protocols

I guess all the admin part will end to be hidden behind few quick and easy wizards for common web service use cases. So don't worrry it will come smile

I really suggest you to use the Moodle Tracker. A tracker issue has so much more weight into decision to assign a developer to a bug/improvement task.

I will write a tutorial with full steps (admin + code) on how to create a client. I'll come back to you to let you know.

In reply to Jérôme Mouneyrac

Re: xml-rpc problems

by juan marin -

Jerome,

I have made webservices before in Java, PHP and .NET.  The regular webservice stuff has not been the difficult part; the true daunting thing has been that the documentation in the Moodle site has been inaccurate, incomplete or missing (not to mention all the stuff that is either buggy or incomplete).

If regular people (ie. developers with basic xml-rpc experience) can't integrate Moodle to the rest of their institutional processes, it will start becoming less of a player in the LMS arena.  If I understand you correctly what you are saying is that webservices in Moodle are being made difficult (either by omission or craft) so that "people" don't get into "bad usage?".  Webservices have been around for 6 or 7 years now; that hardly counts as "new".  Why build something you don't intend people to use?  The evil of this is misleading people with a feature-set that is meant to function for a fortunate few; instead of giving out sample instructions for something we NOW all now know doesn't work as documented unless you happen to be an insider.

I appreciate your help so far.  Whenever you get the complete tutorial please let us know.

Cheers,

Juan Carlos

In reply to juan marin

Re: xml-rpc problems

by Jérôme Mouneyrac -

Hi,

I updated some web service documentations. You can see the list in the issue I created in the tracker: MDLSITE-1200. It will be review by QA.

cheers

In reply to Jérôme Mouneyrac

Re: xml-rpc problems

by Antonio Lepore -

Hi Jerome, 

I'm trying to make active the field php_extension. I follow the guide but nothing. 


How can I solve this problem? The xmlrpc is necessary for vpl plugin. 

Thanks so much!