Skip to Content
author's profile photo Former Member
Former Member

Issue reading file from webservice

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jun 05, 2014 at 12:00 AM

    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 '\'...

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 05, 2014 at 11:35 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.