Solved

Why can't get the rows from my webservice? What am I doing wrong?

Posted on 2016-08-10
11
65 Views
Last Modified: 2016-09-25
Hello guys,

I wrote two parts: serve and client

My client doesn't display the rows from my server, I wonder if someone could point me what I am doing wrong.

this is my server:

<?php
  require_once('lib/nusoap.php');
  
  $servername = "mysql01.teachmenow1.hospedagemdesites.ws";
  $username   = "teachmenow1";
  $password   = "xxxxxxxx";
  $dbnome     = "teachmenow1";  

  $server = new soap_server();
  $server->configureWSDL("listadownloads","urn:Testing WSDL ");

  //register a function that works on server
  $server ->register('listadownloads', array('value' => 'xsd:string'), array('return' => 'xsd:string'), 'urn:server', 'urn:server#listadownloads');
  $server->register("gethelloworld",   array("name" => "xsd:string"),array("return" => "xsd:string"),"urn:helloworld","urn:helloworld#gethelloworld");

  // create the function to fetch Data’s from Database
  
	function gethelloworld($name) {
		$myname    =    "My Name Is <b>".$name . "</b>";
		return $myname;
	}

	function listadownloads ()
	{
        $conn   = $conn = new mysqli($servername, $username, $password, $dbnome);
        $result = $conn->query($sql);
		$sql    = "SELECT * FROM CADDOWNLOAD";
		  
		if ($result->num_rows > 0) {
			while($row = $result->fetch_assoc()) {
				$itens [] = array('id'=>$row['CADDOWNLOADS_ID'], 
				                  'nome'=>$row['NOME'], 
								  'cidade'=>$row['cidade']
								 );
			}				
		}  
		
		$conn->close();		
		return $itens;
	}	
  		  
		  
    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
	$server ->service($HTTP_RAW_POST_DATA);
  
	
?>

Open in new window



this is my client

<?php
//Call server function

  require_once('lib/nusoap.php');

  $url = "http://teachmenow.com.br/nusoap/server.php";
  $client = new nusoap_client($url);
  
  $response = $client ->call('listadownloads');

  if($client->fault)
  {
            echo "FAULT: <p>Code: (".$client ->faultcode.")</p>";
            echo "String: ".$client->faultstring;
  }
  else
  {
            $result = $response;
            $count = count($result);
            echo "inside";
			echo $result;
?>
<table >
<tr>
            <th>Nome</th>
            <th>Cidade</th>
</tr>
<?php

    for($i = 0;$i < $count-1;$i++) 
    {
              $rowtype = ($i % 2) ? "style='background:#88DAEB'": "style=background:#FFF";
?>
<tr <?php echo $rowtype; ?>>
            <td><?php echo $result[$i]['nome']?></td>
            <td><?php echo $result[$i]['cidade']?></td>
</tr>
<?php
      }
?>
</table>
<?php
}
?>

Open in new window


Thanks a lot
Alex
0
Comment
Question by:hidrau
  • 5
  • 2
  • 2
  • +1
11 Comments
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 41750423
Is the blank space in $response = $client ->call('listadownloads'); a typo? If not, it could be the cause of your issue. In this case, set error_reporting(E_ALL) to get error messages in development environment.
1
 
LVL 7

Expert Comment

by:Mukesh Yadav
ID: 41750430
Try this ;)

There is a problem on line no: 25 in function named "listadownloads ".

You used 4 variables here but you didn't defined in this scope I know you defined on the top of this file but you can access then inside this function without global keyword, so add do something like this:

function listadownloads ()
{
        global $servername;
        global $username;
        global $password;
        global $dbnome;
        $conn   = $conn = new mysqli($servername, $username, $password, $dbnome);

Open in new window


If you don't want to use global thing you can create constants and can directly use them no need to add global thing.

Thanks,
Mukesh Yadav
0
 
LVL 7

Expert Comment

by:Mukesh Yadav
ID: 41750434
@Marco a blank space in object method calling syntax can't be an issue.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 1

Author Comment

by:hidrau
ID: 41750447
Hello Marco,

There was blank space in that line and now I delete the blank space and I haven't got success yet. You told me to set error, how should I do?

Thanks
0
 
LVL 1

Author Comment

by:hidrau
ID: 41750457
Hello Mukesh,

I also fixed the lines and nothing:

here is the link:

http://www.teachmenow.com.br/nusoap/client.php
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 41750463
+1 for Marco's comment about error_reporting(E_ALL) -- always use the highest possible error_reporting() setting.  If you don't want to see the errors in the PHP output, you still have the option of using an error_log file.

The blank space in the method call is probably not the cause of the error.  But this problem is an object lesson in why we choose RESTful interfaces instead of SOAP.  With REST you can see the server-side script as it runs.  With SOAP there may be some guessing!

Here are some things to try in the client script.

  • Add var_dump($client) after line 7
  • Add var_dump($response) after line 9

Here are some things to try in the server script.

  • Add var_dump($server) after line 14
  • Add var_dump($HTTP_RAW_POST_DATA) after line 2
  • Inject $servername, $username, $password, $dbnome  into the function call on line 23
  • Change the order of these statements on line 26: $result = $conn->query($sql); $sql    = "SELECT * FROM CADDOWNLOAD";

Some references you may want to read:
http://php.net/manual/en/function.error-reporting.php
http://php.net/manual/en/reserved.variables.httprawpostdata.php (you probably don't want this)
http://php.net/manual/en/language.variables.scope.php

Good learning resources for those new to PHP:
https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html
0
 
LVL 31

Assisted Solution

by:Marco Gasi
Marco Gasi earned 250 total points
ID: 41750472
Even if my collegues have corrected me (the blank space can't be the cause of the error), you should anyway set error_reporting to E_ALL. It's quite simple: just put these lines at the very top of your php scripts:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'On');

Open in new window

1
 
LVL 1

Author Comment

by:hidrau
ID: 41751033
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 41751200
Great!  Are these the things you expected to find in the var_dump() output?  If not, which ones are unexpected values?
0
 
LVL 1

Author Comment

by:hidrau
ID: 41751341
I don't see the register that I can see and it should return me as this link :

http://www.teachmenow.com.br/nusoap/testedados.php

Now, I don't know where is the problem, in the serve side or cliente :(
0
 
LVL 1

Author Closing Comment

by:hidrau
ID: 41815222
Thanks a lot.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHPStorm debugging issues 1 45
php function to remove a file 31 39
maybe no no httpd.conf 6 47
I've got an interview this morning and I want to sound intelligent... 4 53
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question