Web Services and WSDL creation

Web Services and WSDL creation

by Federico Ghigini -
Number of replies: 19

is someone working on this task: http://tracker.moodle.org/browse/MDL-28989?

The main reason I am using only the ws OkTech (btw great job!) is that moodle does not generate a WSDL from which you can automatically generate the classes in Eclipse or Nebeans for the soap protocol.

If more services become available this function will be very useful!

Average of ratings: Useful (1)
In reply to Federico Ghigini

Re: Web Services and WSDL creation

by Bill Antonia -

The information I got from Jerome was no.

I'm gradually working on my own solution in a round about way. I wrote a Java REST library to connect to the Moodle webservices. However I'm using the library to create JavaEE 6 webservices to run on a GlassFish server. The JavaEE 6 webservices does automatically create a WSDL file which conforms to the standard.

You can get the sources from http://www.beaconhillcott.net/. They are zipped NetBeans projects. Obviously they are subject to change as these are pre-release versions. Note I'm working towards Moodle 2.3 so some of the calls in the library and GlassFish webservices will not work until then.

If you go to the above site and look at the "READ MORE..." link for the MoodleServices there is a list of the currently accessible services I have coded to connect through the library, there are more calls in the library yet to expose which will be available in due course.

Although I'm not a C# programmer, I have managed to use the WSDL file to create a connection through to a Moodle server and get data back!

Obviously the better solution would be a WSDL file generated by the Moodle server but I expect that will come sometime in the future.

Average of ratings: Useful (1)
In reply to Federico Ghigini

Re: Web Services and WSDL creation

by Jérôme Mouneyrac -
Hi Federico, no one is working on this task, neither on MDL-28988. I don't see them implemented anytime soon by HQ so if anyone wants/needs to tackle the tasks, I'll be happy to peer-review. Cheers, Jerome
In reply to Jérôme Mouneyrac

Re: Web Services and WSDL creation

by Federico Ghigini -

Hi Jerome,

i have solved this issue. How I can commit my code?

I have edite:
/webservice/lib.php
/webservice/soap/locallib.php

Fede

Average of ratings: Useful (1)
In reply to Federico Ghigini

Re: Web Services and WSDL creation

by Jérôme Mouneyrac -
Thanks for working on it Federico. The easiest way is to use Git:
1) create a github account and fork the moodle rep (https://github.com/moodle/moodle).
2) clone your (fork) github repository on your local machine
3) on your local repository, create a branch, commit your fix in this branch, and push the branch into your github repository
4) give the link to your branch in the tracker issue. Someone (most likely me) will review your git commit.

If all that is new to you, you can read: http://docs.moodle.org/dev/Git_for_developers

Cheers,
Jerome
In reply to Jérôme Mouneyrac

Re: Web Services and WSDL creation

by Bill Antonia -

Excellent!!!!!!!!

How soon will this become available????????

In reply to Bill Antonia

Re: Web Services and WSDL creation

by Federico Ghigini -

hi,

this is my repo on github:

https://github.com/ghigio/moodle/tree/MDL-28988

Now i have this problem: i have tested my patch with che core ws and the OkTech ws integrated in moodle.

I can send the correct request but i can't cast the response.

Explain: i build the wsdl by reading the structure declared in name_of_function_parameter and all works fine.

If I do the same operation with the return type i get a mismatch because moodle return an array of <KEY> <VALUE> instead a real object.

Moodle get the request, but the user can't see the response.

In reply to Federico Ghigini

Re: Web Services and WSDL creation

by Federico Ghigini -

I have corrected the type returned from the web services.

Now all the ws returning a multiple data structure returns an Object[ ].

This isn't the best option, i know. But this solution let the client collect the response without error. Moreover, if the client cast every element of the array to HashMap, all works (I'm using java axis 1.4 for the automatic class generation).

Average of ratings: Useful (1)
In reply to Federico Ghigini

Re: Web Services and WSDL creation

by Luis de Vasconcelos -

Federico,

Does this mean that with your code Moodle now generates a valid WSDL?

Thanks.

In reply to Luis de Vasconcelos

Re: Web Services and WSDL creation

by Federico Ghigini -

My code generate a valid WSDL for the input type of all function. The returned type instead is not correct.

The moodle soap server return an HashMap (kay, value) or an array of HashMap instead of objects. I could not generate a WSDL who describe this structure.

If you wanna test my patch, you can view it on github.

In reply to Federico Ghigini

Re: Web Services and WSDL creation

by Luis de Vasconcelos -

Thanks. I installed your branch from Git (2.3dev (Build: 20120504)) on my test machine. When I run the WS Test Client I get an error:

SOAP protocol: moodle_user_create_users

SoapFault exception: [Sender] Function ("moodle_user_create_users") is not a valid method for this service in C:\Moodle\AppWS\lib\zend\Zend\Soap\Client.php:1113
Stack trace:
#0 C:\Moodle\AppWS\lib\zend\Zend\Soap\Client.php(1113): SoapClient->__soapCall('moodle_user_cre...', Array, NULL, NULL, Array)
#1 C:\Moodle\AppWS\webservice\soap\locallib.php(261): Zend_Soap_Client->__call('moodle_user_cre...', Array)
#2 C:\Moodle\AppWS\admin\webservice\testclient.php(154): webservice_soap_test_client->simpletest('http://localhos...', 'moodle_user_cre...', Array)
#3 {main}
 
I checked my Web Service settings and all "seems" ok - but I am a total newbie at this so...
 
I created a custom service and called it wsuser.  I added only two functions: core_user_create_users and core_user_update_users. "No required capability" is set for wsuser and it is enabled.
 
The SOAP protocol is enabled under Site admin/ Plugins/ Web services/ Manage protocols
 
When I run the URL generated by the test client: http://localhost/moodlews/webservice/soap/server.php?wstoken=24a99fcd781c2a7b2a493c1a80343ab8 I get an invalid XML error:
 
  <?xml version="1.0" encoding="UTF-8" ?>
- <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
- <SOAP-ENV:Body>
- <SOAP-ENV:Fault>
  <faultcode>Sender</faultcode>
  <faultstring>Invalid XML</faultstring>
  </SOAP-ENV:Fault>
  </SOAP-ENV:Body>
  </SOAP-ENV:Envelope>
 

In reply to Luis de Vasconcelos

Re: Web Services and WSDL creation

by Luis de Vasconcelos -

I just noticed that the Web service test client only contains the moodle_* functions for the SOAP protocol, e.g. moodle_user_create_users. The core_user_create_users and core_user_update_users functions that I selected in the setup aren't available. It's probably MDL-31609 come to haunt me again...

In reply to Luis de Vasconcelos

Re: Web Services and WSDL creation

by Federico Ghigini -

Hi, i've just update my repo with a new patch.

I have test it with a java client: in eclipse I have created a new Web Service Client

(right click on an existing project -> new -> other and then select Web Services -> Web services Client)

Then i have imported the moodle wsdl from http://localhost/webservice/soap/server.php?wstoken=your_token&wsdl=1

Then i have created a new class and used the server locator autogenerated by axis 1.4
 (see the attached file)

Let me know if this work. Sorry for the late reply

 

In reply to Federico Ghigini

Re: Web Services and WSDL creation

by Julian Dehne -

Hi Frederico,

Your project looks promising.

we need the wsdl urgently at our university. We also have a team that could support you!

If you are interested, please feel free to contact me any time.

If you are very interested, my github name ist uzuzjmd.

Julian

In reply to Julian Dehne

Re: Web Services and WSDL creation

by Federico Ghigini -

I have added a new branch on git://github.com/ghigio/moodle.git: MDL-28988-v2.

In this branch the current soap server is untached and a new soap server called soapfda has been added in the webservice folder. This way i do not broke any existing client.

Give it a try!

In reply to Federico Ghigini

Re: Web Services and WSDL creation

by Suraj Kumar -
Hi Federico Ghigini, I am new to the WSDL implementation in Moodle. Please let me know How can I get wsdl of an existing webservice suppose "core_course_create_courses". I am running a client on PHP & using this webservice through the valid token. Thanks in advance.
In reply to Suraj Kumar

Re: Web Services and WSDL creation

by Federico Ghigini -

Hi!

I suppose that you have installed my patch and activated it. To obtain the wsdl of all the available services (and so the one you are looking for) you have to call this url

http://your-moodle/webservice/soapfda/server.php?wsdl=1&wstoken=yourtoken

I've tested the wsdl with axis and soapui, not with a php client. Please, let me know if you have trouble.

Average of ratings: Useful (2)
In reply to Federico Ghigini

Re: Web Services and WSDL creation

by Suraj Kumar -
Hi Federico, Yup!! This works well. Thanks for your quick response.
In reply to Federico Ghigini

Re: Web Services and WSDL creation

by Hajer ABDERRAHIM -

Hi,

where could I found your patch and how it could be installed?

Thanks

In reply to Federico Ghigini

Re: Web Services and WSDL creation

by neili gmar -

hi,

je créer  des services web dans un annuaire uddi  et je veux faire l'invocation des ses services ,

s'il vais plait, si vous avez une réponse aide moi et merci