Web Service WSDL dont work Moodle 3.1

Web Service WSDL dont work Moodle 3.1

by Victor Vera -
Number of replies: 13

When I check the url of WSDL: http://mymoodle/webservice/soap/server.php?wstoken=tokengenerated&wsdl=1 


I have the next error:


This page contains the following errors:

error on line 1 at column 1: Extra content at the end of the document

Below is a rendering of the page up to the first error.


My moodle version is 3.1. I upgraded from 2.9.1+. Before upgrade this token and webservice was working perfectly.


Average of ratings: -
In reply to Victor Vera

Re: Web Service WSDL dont work Moodle 3.1

by Marina Glancy -
Picture of Core developers Picture of Moodle HQ Picture of Moodle Workplace team Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Similar error may happen if there are php files with the closing php tag ?> and a space or newline after it. Or when <?php is not the first characters in file. There are no such files in vanilla moodle but you need to check your additional plugins.

Average of ratings: Useful (1)
In reply to Marina Glancy

Re: Web Service WSDL dont work Moodle 3.1

by David Nasralla -

Hi Marina,

What do you mean by "vanilla" moodle. If I do a clean install of moodle 3.1 and enable the SOAP protocol under webservices, I should be able to get a WSDL file.  (ie. the file he is referencing in his url is part of the standard install - http://mymoodle/webservice/soap/server.php)

I am having the same issue. It looks like 3.1 broke the WSDL file generation. (I have a valid token, and have functions exposed.)

dave nasralla

In reply to David Nasralla

Re: Web Service WSDL dont work Moodle 3.1

by Marina Glancy -
Picture of Core developers Picture of Moodle HQ Picture of Moodle Workplace team Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

By "vanilla" I meant moodle from download.moodle.org without any additional plugins. 

There were big changes to WSDL implementation in 3.1 but they were carefully tested so it may have something to do with your environment. We will try to reproduce it here at HQ but we might need to have more details on what you are trying to do, and what is your environment


Can you look at the source of the generated WSDL and try to locate this extra content?

Average of ratings: Useful (1)
In reply to Marina Glancy

Re: Web Service WSDL dont work Moodle 3.1

by David Nasralla -

Hi Marina,

Thanks for you reply (and patients!). I am running MAMP 3.4 on Mac OS 10.11.5. This is a vanilla install. I simply downloaded MAMP 3.4 and ran it. I logged in as the Admin, enabled the SOAP protocol, and created a token.

I've written and in-house application that uses Web Services to communicate with other systems. Unfortunately, I am not a web developer. 

I was able to do some raw commands and get a few things, like the raw source code and headers. I took the returned WSDL file (quite large) and ran it against an online WSDL Tester. It seems the WSDL file may be malformed with sections in the wrong order. 

I have attached the returned wsdl file, and the screen capture of the analysis of the wsdl file from the online tester at https://www.wsdl-analyzer.com. I'll do my best to help you help me! 

Thanks,

dave

Attachment WSDL Error Analysis.jpg
In reply to David Nasralla

Re: Web Service WSDL dont work Moodle 3.1

by Marina Glancy -
Picture of Core developers Picture of Moodle HQ Picture of Moodle Workplace team Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

David, you have attached a proper WSDL generated by moodle, with the same order as it was in 3.0. Your parser complains about the order but it has nothing to do with what Victor described in his post. If you want to discuss the order of elements in WSDL please open a new discussion because this thread becomes confusing now.

In reply to Marina Glancy

Re: Web Service WSDL dont work Moodle 3.1

by David Nasralla -

Hi Marina,

This is actually still the same issue that Victor is having. Let me explain.  My results were even confusing me at first, but I think have a better grasp of what is happening.

It turns out the Client matters. The WSDL file response is very different depending on how I acquire it. The WSDL File I posted was obtained by initiating a RAW TCP Connection with the moodle server where I control the receiving of the data. I get a very different response (even with the same URL) if I use a browser. If I use a browser (ie. Safari, Chrome, or Firefox on Mac, and Firefox on Windows 7 Pro) the response.xml file has  single right bracket character.  That's all. 

If you look at one of the Return headers (like the one I posted) you'll notice that the moodle server says:

Content Length: 1

Even though it is sending an entire WSDL xml file. I am not a web expert, but I am guessing that the browsers can't handle that.  I did it with RAW TCP command and had more control of handling the response. 

Return header:

HTTP/1.1 200 OK

Server: nginx/1.8.0

Date: Fri, 24 Jun 2016 21:15:47 GMT

Content-Type: application/xml; charset=utf-8

Content-Length: 1

Connection: keep-alive

Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0

Expires: Thu, 01 Jan 1970 00:00:00 GMT

Pragma: no-cache

Accept-Ranges: none

Content-Disposition: inline; filename="response.xml"

Cache-Control: public


<?xml version="1.0"?>

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:t..... (I left out the rest of the response...)

Let me know if you think this makes sense.

dave

In reply to Marina Glancy

Re: Web Service WSDL dont work Moodle 3.1

by David Nasralla -

One other thing I wanted to mention is that if I put the URL http://localhost:8888/moodle31/webservice/soap/server.php?wstoken=e417c071da33422c61c92ec5e0a7777c&wsdl=1

Into firefox and look at the source, I only get a single < character. I'm sure I understand that.

If I save the page as text from FireFox I get

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml"><head><title>http://localhost:8888/moodle31/webservice/soap/server.php?wstoken=e417c071da33422c61c92ec5e0a7777c&amp;wsdl=1</title><link href="http_localhost_8888_moodle31_webservice_soap_server.php%3Fwstoken=e417c071da33422c61c92ec5e0a7777c&amp;wsdl=1_files/viewsource.css" type="text/css" rel="stylesheet" /></head><body style="-moz-tab-size: 4" class="highlight" id="viewsource" contextmenu="actions"><pre id="line1"><span></span><span class="error" title="End of file after “&lt;”.">&lt;</span></pre><menu type="context" id="actions"><menuitem id="goToLine" label="Go to Line…" accesskey="L"></menuitem><menuitem id="wrapLongLines" label="Wrap Long Lines" type="checkbox"></menuitem><menuitem id="highlightSyntax" label="Syntax Highlighting" type="checkbox" checked="true"></menuitem></menu></body></html>

In reply to David Nasralla

Re: Web Service WSDL dont work Moodle 3.1

by Victor Vera -

I was looking for where is the possible problem, maybe in /moodle/webservice/soap/classes/wsdl.php that generate the source WSDL.

I tried to generate a new token with a external service with the  moodle own functions and the problem persists.


With firefox the error change to:

Error de lectura XML: token no cerrado

Ubicación: http://moodle/webservice/soap/server.php?wstoken=76b47403fe5b57182d64df95a8830e70&wsdl=1

Número de línea 1, columna 1:

<




In reply to Victor Vera

Re: Web Service WSDL dont work Moodle 3.1

by Marina Glancy -
Picture of Core developers Picture of Moodle HQ Picture of Moodle Workplace team Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hello Victor,

can you please answer my questions above:

- do you have any third party plugins (including custom theme)? If yes, did you analyze them for the extra characters in the php files? Can you reproduce the problem on "vanilla" moodle - installation without any additional plugins?

- when you request the wsdl page can you please save the generated page? If it is not localhost, do not share it here because it will contain your URL and token. Open the file in the text editor and look for extra symbols, tokens/tags that are not closed, etc. You can find&Replace your token in this file with 12345 and attach file here if you want us to look at it.

In reply to Marina Glancy

Re: Web Service WSDL dont work Moodle 3.1

by Victor Vera -

Hello Marina thanks for answer.


I reproduced the problem on "vanilla" moodle. Which phps files do you recomend to check?.


I attached the errors in firefox and chrome and the generated pages.




Attachment Error WSDL in Chrome.png
Attachment Error WSDL in Firefox.png
In reply to Victor Vera

Re: Web Service WSDL dont work Moodle 3.1

by Marina Glancy -
Picture of Core developers Picture of Moodle HQ Picture of Moodle Workplace team Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Thank you very much for additional details.

I was able to reproduce using command-line curl. Looks like firefox/chrome are just smart enough to ignore the content-length header.

I created MDL-55028, we will look at it ASAP

In reply to Marina Glancy

Re: Web Service WSDL dont work Moodle 3.1

by David Nasralla -

Hi Marina,

Just a quick thank you on several levels:

 - for your patience and reading through what can be confusing posts and doing the work to understand the issue

 - for the response speed of your team (I love being able to watch the bug work it's way through resolution with your link!)

Take care,

dave


In reply to Marina Glancy

Re: Web Service WSDL dont work Moodle 3.1

by Victor Vera -

If I enter two or more  times to the link WSDL, that show the code xml. I discover that missing the caracter '<' in the first line:

XML Code


Do you know where moodle generates that code?