Solved

post http visual foxpro

Posted on 2011-09-11
7
2,093 Views
Last Modified: 2012-05-12
My web services interface between a SOAP server and my Visual Foxpro application is operated through a PHP script;
Data to be sent in a web service is writen in a Foxpro free table. Then I invoke the php script and the php reads data and formats the XML and sends it to the endpoint. The php script reads the XML answer and places the answer in a Foxpro Table. During this moment I wait for an answer from the PHP script. The PHP answer is wirten in an answer table which I monitor through requerig.
This workflow works but the behaviour in terms of response time is quite erroneous. sometimes I have time out situations (waiting for 20 seconds) by the PHP to send back the answer.
Is there any possibility to invoke directly some http, post or get) and enable a direct connection with the SOAP server.
Kind Regards
0
Comment
Question by:luciliacoelho
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 12

Expert Comment

by:jrbbldr
ID: 36520283
Is there any possibility to invoke directly some http, post or get) and enable a direct connection with the SOAP server.

If you mean can this data be sent to and received back from the Web Service in VFP-9 without using PHP, the answer is Yes.

If you want to do this all in PHP, then you would be better posting to another language-specific area of the forum.

Clarify what you are looking for and we'll try to point you in the right direction.

Good Luck

0
 

Author Comment

by:luciliacoelho
ID: 36520571

"If you mean can this data be sent to and received back from the Web Service in VFP-9 without using PHP, the answer is Yes." So how can I do it?
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 36521708
Who controls the SOAP server?  Is that your programming or a remote service?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:luciliacoelho
ID: 36521882
Hi Ray,

We are consuming web services from a remote server using in PHP a library named cURL. And as I said before we invoke php directly with a Shell command (Run or !)

If we change this request of the PHP to a http request within VFoxPro as the PHP integration runs ok, what we will probably do will be send a http request or post to a service published internally in an apache server that uses the actual PHP scripts to consume the remote web service.
Invoking directly the web service from VisualFox would be better but we need to recode this part of the system especially the XML coding and business logic.

We have posted this question because invoking php scripts from the Vfoxpro Run Command hasn't a very good performance and has some shortages, namely the size of the string Visual Fox can read and post to the run command (at least we understood this from a painfully malfunctioning we recently solved).

If there was some expedite way to improve I would bet very grateful
Best Regards
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 36522175
I think the first thing I would want to know is "Where does the delay come from?"  If it is the remote server, there is not much you can do except ask the owner of the remote service to speed things up.  But if there is something within your control that is constipated you may be able to find it with this little stopwatch script.  It lets you start and stop timers, and visualize how long parts of your script take to run.  Perhaps you could insert this into the PHP script that calls the remote server.  You could start the timer before the CURL and read the timer after the CURL.  If you write these times to a log file you will be able to see whether the remote server is the bottleneck.

The test case for the timer starts on line 146.  You can see it in action on my server, here:
http://www.laprbass.com/RAY_oop_stopwatch.php
<?php // RAY_oop_stopwatch.php
error_reporting(E_ALL);


// DEMONSTRATE A SCRIPT TIMER FOR ALL OR PART OF A SCRIPT PHP 5+
// MAN PAGE http://php.net/manual/en/function.microtime.php


class StopWatch
{
    protected $a; // START TIME
    protected $s; // STATUS - IF RUNNING
    protected $z; // STOP TIME

    public function __construct()
    {
        $this->a = array();
        $this->s = array();
        $this->z = array();
    }

    // A METHOD TO REMOVE A TIMER
    public function reset($name='TIMER')
    {
        // RESET ALL TIMERS
        if ($name == 'TIMER')
        {
            $this->__construct();
        }
        else
        {
            unset($this->a[$name]);
            unset($this->s[$name]);
            unset($this->z[$name]);
        }
    }

    // A METHOD TO CAPTURE THE START TIME
    public function start($name='TIMER')
    {
        $this->a[$name] = microtime(TRUE);
        $this->z[$name] = $this->a[$name];
        $this->s[$name] = 'RUNNING';
    }

    // A METHOD TO CAPTURE THE END TIME
    public function stop($name='TIMER')
    {
        $ret = NULL;

        // STOP ALL THE TIMERS
        if ($name == 'TIMER')
        {
            foreach ($this->a as $name => $start_time)
            {
                // IF THIS TIMER IS STILL RUNNING, STOP IT
                if ($this->s[$name])
                {
                    $this->s[$name] = FALSE;
                    $this->z[$name] = microtime(TRUE);
                }
            }
        }

        // STOP ONLY ONE OF THE TIMERS
        else
        {
            if ($this->s[$name])
            {
                $this->s[$name] = FALSE;
                $this->z[$name] = microtime(TRUE);
            }
            else
            {
                $ret .= "ERROR: CALL TO STOP() METHOD FOR '$name' IS NOT RUNNING";
            }
        }

        // RETURN AN ERROR MESSAGE, IF ANY
        return $ret;
    }

    // A METHOD TO READ OUT THE TIMER(S)
    public function readout($name='TIMER', $dec=3, $m=1000, $eol=PHP_EOL)
    {
        $str = NULL;

        // GET READOUTS FOR ALL THE TIMERS
        if ($name == 'TIMER')
        {
            foreach ($this->a as $name => $start_time)
            {
                $str .= $name;

                // IF THIS TIMER IS STILL RUNNING UPDATE THE END TIME
                if ($this->s[$name])
                {
                    $this->z[$name] = microtime(TRUE);
                    $str .= " RUNNING ";
                }
                else
                {
                    $str .= " STOPPED ";
                }

                // RETURN A DISPLAY STRING
                $lapse_time = $this->z[$name] - $start_time;
                $lapse_msec = $lapse_time * $m;
                $lapse_echo = number_format($lapse_msec, $dec);
                $str .= " $lapse_echo";
                $str .= $eol;
            }
            return $str;
        }

        // GET A READOUT FOR ONLY ONE TIMER
        else
        {
            $str .= $name;

            // IF THIS TIME IS STILL RUNNING, UPDATE THE END TIME
            if ($this->s[$name])
            {
                $this->z[$name] = microtime(TRUE);
                $str .= " RUNNING ";
            }
            else
            {
                $str .= " STOPPED ";
            }


            // RETURN A DISPLAY STRING
            $lapse_time = $this->z[$name] - $this->a[$name];
            $lapse_msec = $lapse_time * $m;
            $lapse_echo = number_format($lapse_msec, $dec);
            $str .= " $lapse_echo";
            $str .= $eol;
            return $str;
        }
    }
}



// DEMONSTRATE THE USE -- INSTANTIATE THE STOPWATCH OBJECT
$sw  = new Stopwatch;

// SET A STOPWATCH NAME THAT REFLECTS THE PARTS OF THE SCRIPT WE WANT TO TIME
$g_timer = 'GOOGLE TIMER';

// START A TIMER TO GET ELAPSED TIME FOR A CALL TO GOOGLE
$sw->start($g_timer);

// PERFORM SOME ACTIVITY THAT YOU WANT TO TIME (READS GOOGLE WEB PAGE)
$page = 'http://google.com';
$html = file_get_contents($page);

// GET A READOUT OF THE TIMER WHILE IT IS STILL RUNNING
echo nl2br($sw->readout($g_timer));
echo "<br/>" . PHP_EOL;

// PERFORM SOME OTHER ACTIVITY (READS GOOGLE WEB PAGE AGAIN)
$page = 'http://google.com';
$html = file_get_contents($page);

// STOP THE TIMER AND GET A READOUT WITH SHORT DECIMALS
$x = $sw->stop($g_timer);
echo nl2br($sw->readout($g_timer, 1));
echo "<br/>" . PHP_EOL;




// START A SECOND TIMER
$y_timer = 'YAHOO TIMER';
$sw->start($y_timer);

// PERFORM SOME OTHER ACTIVITY THAT YOU WANT TO TIME
$page = 'http://yahoo.com/';
$html = file_get_contents($page);

// REPORT THE STOPWATCHES CONTENT (ONE IS STOPPED AND ONE IS STILL RUNNING)
echo nl2br($sw->readout());
echo "<br/>" . PHP_EOL;

// SHOW THE OBJECT
echo "<pre>";
var_dump($sw);
echo "</pre>";

// STOP ALL OF THE STOPWATCHES
$sw->stop();

// REPORT THE STOPWATCHES CONTENT AGAIN
echo nl2br($sw->readout());
echo "<br/>" . PHP_EOL;

// SHOW THE OBJECT
echo "<pre>";
var_dump($sw);
echo "</pre>";



// TRY TO STOP A TIMER THAT IS NOT RUNNING
$x = $sw->stop($g_timer);
var_dump($x);
echo "<br/>" . PHP_EOL;
echo "<br/>" . PHP_EOL;



// START THIS TIMER OVER AGAIN
$sw->start($y_timer);

// PERFORM SOME OTHER ACTIVITY THAT YOU WANT TO TIME
$page = 'http://weather.yahoo.com/';
$html = file_get_contents($page);

// REPORT THE STOPWATCHES CONTENT
echo nl2br($sw->readout());
echo "<br/>" . PHP_EOL;

// SHOW THE OBJECT
echo "<pre>";
var_dump($sw);
echo "</pre>";



// REMOVE ONE OF THE STOPWATCHES
$sw->reset($g_timer);

// REPORT THE STOPWATCHES CONTENT
echo nl2br($sw->readout());
echo "<br/>" . PHP_EOL;

// SHOW THE OBJECT
echo "<pre>";
var_dump($sw);
echo "</pre>";



// REMOVE ALL OF THE STOPWATCHES
$sw->reset();
echo "ALL STOPWATCHES HAVE BEEN REMOVED";

// REPORT THE STOPWATCHES CONTENT (SHOWS NOTHING)
echo nl2br($sw->readout());

// SHOW THE OBJECT
echo "<pre>";
var_dump($sw);
echo "</pre>";

Open in new window

0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 36522534
You can also use curl from within VFP, see http://curl.haxx.se/libcurl/, on the right side implementations for different languages are listed, and foxpro is in that list:
http://curl.haxx.se/libcurl/foxpro/

So if you mainly use php to be able to use curl, then there is no need for that.

Bye, Olaf.
0
 
LVL 12

Accepted Solution

by:
jrbbldr earned 500 total points
ID: 36523782
Here is a SOAP Post routine that we are using from a VFP9 application

Note - the specifics of the Web Service at the 'other end' may likely dictate modifications to the code.




* ---------------------------------------------------------------------------
*
*  Enter here with cXML (XML String) & cWSDL (Web Service URL) defined ---
*  Also Pre-defined:  cSecurityKey, cAuthHash   Web Service-specific connect parameters
*
FUNCTION SendSOAP
PARAMETERS cXMLString, cWSDL
PRIVATE mcWaitMsg

mcWaitMsg = " POSTING SOAP " + ALLTRIM(UPPER(cOperation)) + " Data...";
   + CHR(13);
   + " At URL: " + cWSDL + " ... "
WAIT WINDOW mcWaitMsg TIMEOUT 1
WAIT WINDOW mcWaitMsg NOWAIT

* --- Using MS SOAP Toolkit 3.0 ---
RELEASE loWSHandler, loWS, loException

LOCAL loWS AS "XML Web Service"
* LOCAL loWS AS "MSSOAP.SoapClient30"
* Do not remove or alter following line. It is used to support IntelliSense for your XML Web service.
*__VFPWSDef__: loWS = https://www.virtualacd.biz/intelliqueue/admin/api/agentgateway.cfc?wsdl , ListLoader , listloader.cfc

LOCAL loException, lcErrorMsg, loWSHandler
TRY
   loWSHandler = NEWOBJECT("WSHandler",IIF(VERSION(2)=0,"",ADDBS(mcDefaultDir) + "_ws3client.vcx"))
   loWS = loWSHandler.SetupClient(cWSDL)

   DIMENSION aryXML(1)
   aryXML(1) = cXMLString

* --- 'Send Data To Specific Web Service Method (in this case SaveAgent) ---
   aryWSResp(1) = loWS.SaveAgent(cSecurityKey, cAuthHash, aryXML(1))

CATCH TO loException
   lcErrorMsg = loException.MESSAGE
   IF !("USERNAME" $ UPPER(lcErrorMsg));
         AND !("CURRENTLY IN-USE" $ UPPER(lcErrorMsg))
      lcErrorMsg = "Error: " + TRANSFORM(loException.ERRORNO) + " - " + lcErrorMsg
      DO CASE
         CASE VARTYPE(loWS) # "O"
            * Handle SOAP error connecting to web service

         CASE !EMPTY(loWS.FaultCode)
            * Handle SOAP error calling method
            lcErrorMsg = lcErrorMsg + CHR(13) + loWS.DETAIL

         CASE !EMPTY(loWS.SoapErrorString)
            lcErrorMsg = lcErrorMsg + CHR(13) + loWS.SoapErrorString

         CASE !EMPTY(loWS.DETAIL)
            lcErrorMsg = lcErrorMsg + CHR(13) + loWS.DETAIL

         OTHERWISE
            * Handle other error
      ENDCASE

      * In Development Mode - Use for debugging purposes
      IF _VFP.STARTMODE = 0
         MESSAGEBOX(lcErrorMsg)
      ENDIF
   ENDIF  && IF !("USERNAME" $ UPPER(lcErrorMsg)) AND !("CURRENTLY IN-USE" $ UPPER(lcErrorMsg))
FINALLY
ENDTRY

RETURN .T.

Open in new window

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now