Solved

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

Posted on 2016-08-10
11
69 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 8

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 8

Expert Comment

by:Mukesh Yadav
ID: 41750434
@Marco a blank space in object method calling syntax can't be an issue.
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

838 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