logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: NuSoap & Binary Attachments: msg#00146

Subject: Re: NuSoap & Binary Attachments
So, got it working finally - at least partly.

http://geodata.grid.unep.ch/webservices/graph_example2.php

But still, as soon as my included file calls any function, no value  
is being returned. That's why there are the error messages for  
PostgreSQL etc.... Very strange.

http://geodata.grid.unep.ch/webservices/graph_example3.php

> http://geodata.grid.unep.ch/webservices/graphexe_webservice.php  
> makes postgresql calls, does something with the results, then uses  
> header, print, echo, etc., to create an HTTP response containing a  
> PNG image. It works fine and returns the image to my browser with  
> no error.
>
> You now include that exact PHP source file from your other PHP  
> source file that implements the web service.  The web service code  
> presumably calls the graphexe_webservice.php functions that make  
> postgresql calls and process the result into a PNG image, then the  
> service returns the contents of the PNG image as an attachment or  
> base64Binary result. However, when the web service PHP source calls  
> the functions in graphexe_webservice.php, you get warnings:
>
> Warning:  pg_num_rows(): supplied argument is not a valid  
> PostgreSQL result resource in /www/geodataportal/htdocs/etc/inc/ 
> database.inc on line 223
>
> Warning:  pg_num_fields(): supplied argument is not a valid  
> PostgreSQL result resource in /www/geodataportal/htdocs/webservices/ 
> graphexe_webservice.php on line 201
>
> Warning:  pg_num_rows(): supplied argument is not a valid  
> PostgreSQL result resource in /www/geodataportal/htdocs/etc/inc/ 
> database.inc on line 223
>
> Warning:  pg_fetch_array(): supplied argument is not a valid  
> PostgreSQL result resource in www/geodataportal/htdocs/webservices/ 
> graphexe_webservice.php on line 316
>
> These warnings mean the pg_query() call did not return a result  
> resource.  Could your code check the return value for FALSE and  
> display or log the value from pg_last_error()?  Perhaps your code  
> could also display or log the value of the query string that gets  
> passed.
>
> Scott Nichol
> ----- Original Message ----- From: "Stefan Schwarzer"  
> <stefan.schwarzer@xxxxxxxxxxxx>
> To: "Scott Nichol" <snicholnews@xxxxxxxxxxxxxxx>
> Cc: <nusoap-general@xxxxxxxxxxxxxxxxxxxxx>
> Sent: Tuesday, April 24, 2007 9:10 AM
> Subject: Re: [Nusoap-general] NuSoap & Binary Attachments
>
>
>>
>>
>>> When I go to http://geodata.grid.unep.ch/webservices/  
>>> graph_example2.php, I see all the PostgreSQL warnings that are  
>>> causing the problem.  Your web service code cannot allow  
>>> warnings  to be sent in the HTTP response.
>>
>> Yep, but the Warnings are due to the fact that, as described  
>> below, the functions used within the PHP file which I include in  
>> the webservice-file, don't return anymore any values. However, if  
>> I call the the included file directly ( http:// 
>> geodata.grid.unep.ch/ webservices/graphexe_webservice.php ), than  
>> there is no error.
>>
>> So, how comes that an
>>
>> include("graphexe_webservice.php");
>>
>> within the webservice file eliminates the possibility of returning  
>> values from functions within that file?
>>
>>
>>
>>>
>>> Scott Nichol
>>>
>>> ----- Original Message ----- From: "Stefan Schwarzer"  
>>> <stefan.schwarzer@xxxxxxxxxxxx>
>>> To: "Scott Nichol" <snicholnews@xxxxxxxxxxxxxxx>
>>> Sent: Tuesday, April 24, 2007 12:57 AM
>>> Subject: Re: [Nusoap-general] NuSoap & Binary Attachments
>>>
>>>
>>>> Oh, sorry, when you tried, I was just trying to place my  
>>>> "include ('graph.php')" somewhere else (outside the function)  
>>>> which  resulted in that error. Normally it's really the problem  
>>>> that it  seems no values are being returned from any of the  
>>>> functions which  can be found in my included file.
>>>>
>>>>
>>>>
>>>>> I see the text for the constructor error.  My advice is to also  
>>>>> display debug in that case
>>>>>
>>>>> if ($err) {
>>>>> echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
>>>>> echo '<h2>Debug</h2><pre>' . htmlspecialchars($client- 
>>>>> >debug_str, ENT_QUOTES) . '</pre>';
>>>>> exit();
>>>>> }
>>>>>
>>>>> Given the error "...on line 1: not well-formed (invalid  
>>>>> token)", one possible problem is that the PHP file containing  
>>>>> the service has text in it outside the <? and ?>.  PHP will  
>>>>> send that text  to its output, which means it will be included  
>>>>> in the WSDL.
>>>>>
>>>>> Scott Nichol
>>>>>
>>>>> ----- Original Message ----- From: "Stefan Schwarzer"  
>>>>> <stefan.schwarzer@xxxxxxxxxxxx>
>>>>> To: "Scott Nichol" <snicholnews@xxxxxxxxxxxxxxx>
>>>>> Cc: <nusoap-general@xxxxxxxxxxxxxxxxxxxxx>
>>>>> Sent: Friday, April 20, 2007 3:44 AM
>>>>> Subject: Re: [Nusoap-general] NuSoap & Binary Attachments
>>>>>
>>>>>
>>>>>> This one (  http://geodata.grid.unep.ch/webservices/
>>>>>> graph_example.php  ) works well now.  Although I am happy that
>>>>>> finally the thing is working, it only deals with a static  
>>>>>> image. But
>>>>>> when including another file within the getFile() function, it   
>>>>>> led to
>>>>>> the error message that you've seen.
>>>>>>
>>>>>> So, I tried to run my normal PHP files (which are used on the  
>>>>>> website
>>>>>> to produce dynamically a graph), but - puhhhh - suddenly, my
>>>>>> functions do not return any values anymore. So, for example I  
>>>>>> call a
>>>>>> function which queries the database and than sends back the  
>>>>>> $result.
>>>>>> But now, this is empty. Is this something related to the nusoap /
>>>>>> Soap libs? Not allowed to return values from other functions?
>>>>>>
>>>>>> This is the new test file:
>>>>>> http://geodata.grid.unep.ch/webservices/graph_example2.php
>>>>>>
>>>>>> And here is the file which is being included into the getFile()
>>>>>> function, which shows that the file itself is working correctly:
>>>>>> http://geodata.grid.unep.ch/webservices/graphexe_webservice.php
>>>>>>
>>>>>>
>>>>>>
>>>>>>> It looks like you've made these changes.  When I go to http://
>>>>>>> geodata.grid.unep.ch/webservices/graph_example.php, I get the  
>>>>>>> Error
>>>>>>> with Response is not of type text/xml.  That means the SOAP   
>>>>>>> call to
>>>>>>> getFile is failing.  You could get some additional  
>>>>>>> information by
>>>>>>> doing the following:
>>>>>>>
>>>>>>> <?php
>>>>>>> // includes nusoap classes
>>>>>>> include('nusoap.php');
>>>>>>> // creates an instance of the SOAP client object
>>>>>>> $wsdl = 'http://my-url/graph_ws.php?wsdl&debug=1'; // ask for  
>>>>>>> debug
>>>>>>> $client = new soapclient($wsdl, 'wsdl');
>>>>>>> $err = $client->getError();
>>>>>>> if ($err) {
>>>>>>> echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
>>>>>>> exit();
>>>>>>> }
>>>>>>> $result = $client->call('getFile', array('filename' =>
>>>>>>> 'graphexe.gif'));
>>>>>>> if ($client->fault) {
>>>>>>> echo '<h2>Fault</h2><pre>'; print_r($result); echo '</pre>';
>>>>>>> exit();
>>>>>>> } else {
>>>>>>> $err = $client->getError();
>>>>>>> if ($err) {
>>>>>>> echo '<h2>Error</h2><pre>' . $err . '</pre>';
>>>>>>> // print all the key debugging information
>>>>>>> echo '<h2>Request</h2><pre>' . htmlspecialchars($client- 
>>>>>>> >request,
>>>>>>> ENT_QUOTES) . '</pre>';
>>>>>>> echo '<h2>Response</h2><pre>' . htmlspecialchars($client-
>>>>>>> >response,
>>>>>>> ENT_QUOTES) . '</pre>';
>>>>>>> echo '<h2>Debug</h2><pre>' . htmlspecialchars($client- 
>>>>>>> >debug_str,
>>>>>>> ENT_QUOTES) . '</pre>';
>>>>>>> exit();
>>>>>>> }
>>>>>>> header("Content-Type: image/gif");
>>>>>>> header("Content-Length: " . strlen($result));
>>>>>>> echo $result;
>>>>>>> ?>
>>>>>>>
>>>>>>> Scott Nichol
>>>>>>> ----- Original Message ----- From: "Scott Nichol"
>>>>>>> <snicholnews@xxxxxxxxxxxxxxx>
>>>>>>> To: "Stefan Schwarzer" <stefan.schwarzer@xxxxxxxxxxxx>
>>>>>>> Cc: <nusoap-general@xxxxxxxxxxxxxxxxxxxxx>
>>>>>>> Sent: Wednesday, April 18, 2007 11:32 AM
>>>>>>> Subject: Re: [Nusoap-general] NuSoap & Binary Attachments
>>>>>>>
>>>>>>>
>>>>>>>> I would start by adding error handling to your code, such as
>>>>>>>>
>>>>>>>> <?php
>>>>>>>> // includes nusoap classes
>>>>>>>> include('nusoap.php');
>>>>>>>> // creates an instance of the SOAP client object
>>>>>>>> $wsdl = 'http://my-url/graph_ws.php?wsdl';
>>>>>>>> $client = new soapclient($wsdl, 'wsdl');
>>>>>>>> $err = $client->getError();
>>>>>>>> if ($err) {
>>>>>>>> echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
>>>>>>>> exit();
>>>>>>>> }
>>>>>>>> $result = $client->call('getFile', array('filename' =>
>>>>>>>> 'graphexe.gif'));
>>>>>>>> if ($client->fault) {
>>>>>>>> echo '<h2>Fault</h2><pre>'; print_r($result); echo '</pre>';
>>>>>>>> exit();
>>>>>>>> } else {
>>>>>>>> $err = $client->getError();
>>>>>>>> if ($err) {
>>>>>>>>  echo '<h2>Error</h2><pre>' . $err . '</pre>';
>>>>>>>>  exit();
>>>>>>>> }
>>>>>>>> header("Content-Type: image/gif");
>>>>>>>> header("Content-Length: " . strlen($result));
>>>>>>>> echo $result;
>>>>>>>> ?>
>>>>>>>>
>>>>>>>> Scott Nichol
>>>>>>>> ----- Original Message ----- From: "Stefan Schwarzer"
>>>>>>>> <stefan.schwarzer@xxxxxxxxxxxx>
>>>>>>>> To: "Scott Nichol" <snicholnews@xxxxxxxxxxxxxxx>
>>>>>>>> Cc: <nusoap-general@xxxxxxxxxxxxxxxxxxxxx>
>>>>>>>> Sent: Wednesday, April 18, 2007 2:15 AM
>>>>>>>> Subject: Re: [Nusoap-general] NuSoap & Binary Attachments
>>>>>>>>
>>>>>>>>
>>>>>>>>>
>>>>>>>>>> The service code you pasted below shows
>>>>>>>>>>
>>>>>>>>>> // Use the request to (try to) invoke the service
>>>>>>>>>> //$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ?
>>>>>>>>>> $HTTP_RAW_POST_DATA : '';
>>>>>>>>>> //$server->service($HTTP_RAW_POST_DATA);
>>>>>>>>>>
>>>>>>>>>> If you really have those lines commented, your service  
>>>>>>>>>> will not do
>>>>>>>>>> anything.  The $server->service call is where the SOAP  
>>>>>>>>>> call gets
>>>>>>>>>> handled.
>>>>>>>>>
>>>>>>>>> Ah, ok. But I tried it before with and without these lines,  
>>>>>>>>> and it's
>>>>>>>>> not working either way.
>>>>>>>>>
>>>>>>>>> Here is the URL: http://geodata.grid.unep.ch/webservices/
>>>>>>>>> graph_example.php
>>>>>>>>>
>>>>>>>>> Gush, I had/have the impression that it's so close to get it
>>>>>>>>> working.... Where lays the problem, dam....
>>>>>>>>>
>>>>>>>>> Stef
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>> Hmmm.... in principal it should be clear by now. But it  
>>>>>>>>>>> still
>>>>>>>>>>> doesn't work. I did as you indicated (see code below),  
>>>>>>>>>>> but it
>>>>>>>>>>> returns an empty page/image. Do you have any idea why  
>>>>>>>>>>> this would
>>>>>>>>>>> be so?
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> CLIENT:
>>>>>>>>>>>
>>>>>>>>>>> <?php
>>>>>>>>>>> // includes nusoap classes
>>>>>>>>>>> include('nusoap.php');
>>>>>>>>>>>
>>>>>>>>>>> // creates an instance of the SOAP client object
>>>>>>>>>>> $wsdl = 'http://my-url/graph_ws.php?wsdl';
>>>>>>>>>>>
>>>>>>>>>>> $client = new soapclient($wsdl, 'wsdl');
>>>>>>>>>>>
>>>>>>>>>>> $result = $client->call('getFile', array('filename' =>
>>>>>>>>>>> 'graphexe.gif'));
>>>>>>>>>>>
>>>>>>>>>>> header("Content-Type: image/gif");
>>>>>>>>>>> header("Content-Length: " . strlen($result));
>>>>>>>>>>> echo $result;
>>>>>>>>>>> ?>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> SERVER:
>>>>>>>>>>>
>>>>>>>>>>> // Define the method as a PHP function
>>>>>>>>>>> function getFile($filename) {
>>>>>>>>>>> global $HTTP_SERVER_VARS;
>>>>>>>>>>> if ($filename != 'php.gif' && $filename != 'getfile1.php') {
>>>>>>>>>>> return new soap_fault('SOAP-ENV:Client', 'getfile1',  
>>>>>>>>>>> 'Unsupported
>>>>>>>>>>> file name', array('filename' => $filename));
>>>>>>>>>>> }
>>>>>>>>>>> $path = '/www/geodataportal/htdocs/webservices/' .  
>>>>>>>>>>> $filename;
>>>>>>>>>>> $handle = fopen($path, "rb");
>>>>>>>>>>> $contents = fread($handle, filesize($path));
>>>>>>>>>>> fclose($handle);
>>>>>>>>>>> return base64_encode($contents);
>>>>>>>>>>> }
>>>>>>>>>>> // Use the request to (try to) invoke the service
>>>>>>>>>>> //$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ?
>>>>>>>>>>> $HTTP_RAW_POST_DATA : '';
>>>>>>>>>>> //$server->service($HTTP_RAW_POST_DATA);
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Apr 16, 2007, at 4:55 PM, Scott Nichol wrote:
>>>>>>>>>>>
>>>>>>>>>>>> filesize() is not going to find your file, so nothing  
>>>>>>>>>>>> gets read.
>>>>>>>>>>>> You need to do
>>>>>>>>>>>>
>>>>>>>>>>>> $path = '/www/geodataportal/htdocs/webservices/' .  
>>>>>>>>>>>> $filename;
>>>>>>>>>>>> $handle = fopen($path, "rb");
>>>>>>>>>>>> $contents = fread($handle, filesize($path));
>>>>>>>>>>>> fclose($handle);
>>>>>>>>>>>> return base64_encode($contents);
>>>>>>>>>>>>
>>>>>>>>>>>> Scott Nichol
>>>>>>>>>>>>
>>>>>>>>>>>> ----- Original Message ----- From: "Stefan Schwarzer"
>>>>>>>>>>>> <stefan.schwarzer@xxxxxxxxxxxx>
>>>>>>>>>>>> To: "Scott Nichol" <snicholnews@xxxxxxxxxxxxxxx>
>>>>>>>>>>>> Cc: <nusoap-general@xxxxxxxxxxxxxxxxxxxxx>
>>>>>>>>>>>> Sent: Monday, April 16, 2007 10:45 AM
>>>>>>>>>>>> Subject: Re: [Nusoap-general] NuSoap & Binary Attachments
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> // base64_decode here ????
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> $fp = fopen("/www/geodataportal/temp/graph_test.gif",
>>>>>>>>>>>>>>> "w");  // do I need to write the content of $result   
>>>>>>>>>>>>>>> into an
>>>>>>>>>>>>>>> image?
>>>>>>>>>>>>>>> fwrite($fp, $result);
>>>>>>>>>>>>>>> fclose($fp);
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> echo '<img src="http://geodata.grid.unep.ch/temp/
>>>>>>>>>>>>>>> graph_test.gif" alt="" />'; // ... and then load it as
>>>>>>>>>>>>>>> graphic?
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> You do not need to base64_decode; NuSOAP will do that   
>>>>>>>>>>>>>> for you.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> The method you specify will work if you want to have a  
>>>>>>>>>>>>>> script
>>>>>>>>>>>>>> that returns a page that has the img.  You can also, of
>>>>>>>>>>>>>> course,  have a PHP script that returns the GIF it  
>>>>>>>>>>>>>> gets from
>>>>>>>>>>>>>> the web  service. After $result = $client->call(...), the
>>>>>>>>>>>>>> script would  set the Content-Type header it returns  
>>>>>>>>>>>>>> to image/
>>>>>>>>>>>>>> gif and return  the result, something like
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> header("Content-Type: image/gif");
>>>>>>>>>>>>>> header("Content-Length: " . strlen($result));
>>>>>>>>>>>>>> echo $result;
>>>>>>>>>>>>>
>>>>>>>>>>>>> Scott, thanks for that clarification.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Do I have to change something within the servers' code  
>>>>>>>>>>>>> to get it
>>>>>>>>>>>>> working? In the moment I get a blank image as result....
>>>>>>>>>>>>>
>>>>>>>>>>>>> $handle = fopen('/www/geodataportal/htdocs/webservices/' .
>>>>>>>>>>>>> $filename, "rb");
>>>>>>>>>>>>> $contents = fread($handle, filesize($filename));
>>>>>>>>>>>>> fclose($handle);
>>>>>>>>>>>>> return base64_encode($contents);
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> -------------------------------------------------------------- 
>>>>>>>>> --
>>>>>>>>> --
>>>>>>>>> --
>>>>>>>>> -----
>>>>>>>>> This SF.net email is sponsored by DB2 Express
>>>>>>>>> Download DB2 Express C - the FREE version of DB2 express  
>>>>>>>>> and take
>>>>>>>>> control of your XML. No limits. Just data. Click to get it  
>>>>>>>>> now.
>>>>>>>>> http://sourceforge.net/powerbar/db2/
>>>>>>>>> _______________________________________________
>>>>>>>>> Nusoap-general mailing list
>>>>>>>>> Nusoap-general@xxxxxxxxxxxxxxxxxxxxx
>>>>>>>>> https://lists.sourceforge.net/lists/listinfo/nusoap-general
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --------------------------------------------------------------- 
>>>>>>>> --
>>>>>>>> --
>>>>>>>> --
>>>>>>>> ----
>>>>>>>> This SF.net email is sponsored by DB2 Express
>>>>>>>> Download DB2 Express C - the FREE version of DB2 express and  
>>>>>>>> take
>>>>>>>> control of your XML. No limits. Just data. Click to get it now.
>>>>>>>> http://sourceforge.net/powerbar/db2/
>>>>>>>> _______________________________________________
>>>>>>>> Nusoap-general mailing list
>>>>>>>> Nusoap-general@xxxxxxxxxxxxxxxxxxxxx
>>>>>>>> https://lists.sourceforge.net/lists/listinfo/nusoap-general
>>>>>>
>>>>>>
>>>>>> ----------------------------------------------------------------- 
>>>>>> --
>>>>>> --
>>>>>> ----
>>>>>> This SF.net email is sponsored by DB2 Express
>>>>>> Download DB2 Express C - the FREE version of DB2 express and take
>>>>>> control of your XML. No limits. Just data. Click to get it now.
>>>>>> http://sourceforge.net/powerbar/db2/
>>>>>> _______________________________________________
>>>>>> Nusoap-general mailing list
>>>>>> Nusoap-general@xxxxxxxxxxxxxxxxxxxxx
>>>>>> https://lists.sourceforge.net/lists/listinfo/nusoap-general
>>>>
>>


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/


<Prev in Thread] Current Thread [Next in Thread>