visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: Web services with PHP


By: omuyelijah Nigeria  Date: 18/02/2008 13:09:42  English  Points: 20 Status: Answered
Quality : Excellent
Hello All,

Pls take a look at this code below. Its a simple client-server web service example with PHP and NuSOAP (libraries from Dietrich Ayala | NuSOAP) but doesn't seem to work.

The line at client code (i.e. echo $result) should output -omuyelijah@yahoo.com-
but it doesn't. However, the last two lines of client1.php print well.

I had a similar problem with xmlrpc and php (will post the code later).
what might be the problem with this?


<?php #server1.php //sample NuSoap Web service #our nusoap library require('C:/php5/nusoap/lib/nusoap.php'); # define server $server=new soap_server(); #register our function with server object $server->register('hello'); function hello($par){ return "omuyelijah@yahoo.com"; } $server->service($HTTP_RAW_POST_DATA); ?>



<?php #client1.php //web service client # use our nusoap library require('c:/php5/nusoap/lib/nusoap.php'); #prepare server uri $wsdl='http://localhost/nusoap/server1.php'; #instantiate nusoap client $client=new soapclient($wsdl); #prepare input for web service $param= array('elijah'); #print our result $result= $client->call('hello',$param); //why does this line print nothing at all ... echo $result; // ... and these ones print request and response echo '<xmp>'.$client->request.'</xmp>'; echo '<xmp>'.$client->response.'</xmp>'; ?>

By: VGR Date: 19/02/2008 07:39:04 English  Type : Comment
are you sure http_raw_post_data is not deprecated in your PHP version ? have you checked that it is populated correctly ?
By: omuyelijah Date: 19/02/2008 10:07:28 English  Type : Comment
I am using PHP 5.2.5/Apache 2.0.63.

Now, 4 the check 4 variable population,

echo $HTTP_RAW_POST_DATA;

or even

echo $GLOBAL['HTTP_RAW_POST_DATA'];


prints blank.

Now, I set the always_populate_raw_post_data to on (cos it was turned off b4), and retried the above but no way.
By: omuyelijah Date: 19/02/2008 10:44:37 English  Type : Comment
Some minutes ago, I edited the client code to check for faults and errors ...

#print our result $result= $client->call('hello',$param); $fault=$client->fault; $err=$client->getError(); if($fault) echo 'Fault: '.$fault.'</br>'; if($err) echo 'Error: '.$err.'</br>'; else echo $result;



Output
Error:
XML error parsing SOAP payload on line 2: Reserved XML Name


Checked the net, got some related errors in other forums but no solution clues.
By: omuyelijah Date: 22/02/2008 13:30:40 English  Type : Answer
I have now been able to overcome this problem.

I joined the NuSOAP Mailing List and had Mr. Scott Nichol help out.

Cause of problem: service script (server1.php) had a blank line b4 the script tags

<?php //implementation of service script >?



Blank lines/spaces should also not be printed from within the service script, i.e.

print " ";



After playing around the code, it worked and I also saw that blank lines aren't necessary in client scripts.

Thanks 4 ur suggestions VGR.
By: VGR Date: 22/02/2008 17:57:06 English  Type : Comment
yes, blank lines in HTML output are a pain in the neck (see JSP generated pages :D :D :D), but you also incidentally learnt that the XML error message was way off the point ;-)

Do register to be able to answer

EContact
browser fav
page generated in 102.365970 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page