Languages :: PHP :: Web services with PHP |
|||
| By: omuyelijah |
Date: 18/02/2008 13:09:42 |
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 | 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 | 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 evenecho $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 | 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 | 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 | 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 |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








