cancel
Showing results for 
Search instead for 
Did you mean: 

Issue reading file from webservice

Former Member
0 Kudos

Support has hit a lull recently, so I've gotten back to an issue that has me stumped.

I've created a webservice in PB 12.5.2 Classic that has two methods:  readFile and writeFile.

The writeFile method just creates a text file with some test text in it.  It works fine, the file created in the folder I would expect (namely: C:\inetpub\wwwroot\testwebservice_root\file\session\__webservice__\c )

My issue comes from trying to read from a file in the readFile method.  I've put a test INI file in the \file\common\c folder, and when the webservice starts, it is copied to \file\session__webservice__\c as I would expect (so file exists).  However, when I try either a ProfileString, or even just a fileOpen, I cannot access the file (fileOpen returns -1).   Below is my code, basically following Chris' STD framework in reading from an ini file:

#if defined PBWEBSERVICE then                   // Web Service?
ls_virtual_path  = MapVirtualPath (ls_filename )            // YES=Get its Path
#end if
li_pos = POS  (ls_virtual_path, ls_filename)             // Got a path?
IF  li_pos  > 0 THEN                        // YES=>Get file name
ls_virtual_path  = MID (ls_virtual_path, 1, li_pos - 1)            // Remove file name
END IF

ls_ini_file   =  ls_virtual_path
ls_ini_file   +=  ls_filename

// test read here
//ls_result = ProfileString (ls_ini_file, "WebService", "Language", "X")
li_filenum = fileOpen(ls_ini_file)
IF li_filenum < 0 THEN
ls_result = "file open fail"
ELSE
li_len = fileRead(li_filenum, ls_text)
ls_result = "read " + string(li_len) + " bytes."
END IF

fileClose(li_filenum)

The variable ls_ini_file has the correct full path and ini file name as I am expecting.   Any suggestions is greatly welcome!

Jim

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Jim;

  Yes, this is a little trickier that one first thinks. I finally solved it in my latest STD Foundation Classes for IIs Web Service framework for PB Classic. In fact, I will be publishing this new release (v2.0) up on to the SourceForge website later today. My PB frameworks are all free BTW. 

  Even though this is v2.0 - the WS framework was actually initially written for EAServer in 1998 and then enhanced from there. I only ported the EAS code into an IIs version just over 1 year ago (IIs v1.0). This is the first major upgrade to the WS framework for IIs since the "port" - however, its jam packed with new features. 

  FYI: The way I resolved the INI file deployment folder to session folder at run-time was to use the MS-Windows Shell API to get the job done. The WS framework in v1.0 supported the WShell feature - so that made the task easier when I got to code the INI file issue in v2.0.

STD Foundation Classes | Free Development software downloads at SourceForge.net

Regards ... Chris

PS: I demonstrated the WS framework at the Charlotte NC PB Conference this past March. I hear Matt is just in the planning stages for next years conference. 

       PowerBuilder Conference 2014

Former Member
0 Kudos

Thanks - I'll check out the update.

Former Member
0 Kudos
Former Member
0 Kudos

li_pos = POS  (ls_virtual_path, ls_filename)             // Got a path?
IF  li_pos  > 0 THEN                        // YES=>Get file name
ls_virtual_path  = MID (ls_virtual_path, 1, li_pos - 1)            // Remove file name
END IF

ls_ini_file   =  ls_virtual_path
ls_ini_file   +=  ls_filename

// test read here
//ls_result = ProfileString (ls_ini_file, "WebService", "Language", "X")
li_filenum = fileOpen(ls_ini_file)

At first glance, it looks like you are reconstructing the file name from path and name without the '/' or '\'...

Former Member
0 Kudos

The path name is ok - I can take the string value in the debugger, paste it into windows file explorer and it opens fine.  The code is a bit ugly as I did a real quick and dirty copy some lines from the STD framework and see how it worked in our test code.

Former Member
0 Kudos

Sorry my point was not the path name. The ls_ini_file variable will contain 'c:\tempmyini.ini' not 'c:\temp\myini.ini'