Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a HTTP Web Service in VFP

Status
Not open for further replies.

gkratnam

Programmer
Aug 9, 2007
37
US
I would like to create a Webservice in VFP that can do HTTP GET/POST/PUT. We are not allowed to use any third party tools. We need to connect with another modern app to export/import data.

I am fairly new to this concept and learned from this forum while ago about how to consume data using HTTP service as a proof of concept. I have not learned to create any HTTP Webservices. How do I create an API in VFP, so other apps can connect and consume? Please assist me with this.

Thanks!
 
Really creating a service or using a service?

VFP9 offers both, because it came with the Soap Toolkit and a walkthrough for generating soap web seervices. It's just not a usual standard anymore. Not only ba XML or Soap version but by the rest of the world having moved to restful services. Nevertheless to point it out:
But just like this is based on IIS any webservice framework I know of doesn't start from scratch, you use a webserver as basis for a web service. And then if you'd need to provide services, it's easier to do that in PHP or Python or some other web language than in VFP.

Needing to connect to another app looks like you're needing to do a client to use their defined API for import/export. Services are offering both read and write access. Usually only via an account, but it's not that you have to provide a service for export, if they offer an export function (or import from their point of view) that's still done with their service, not yours.

Chriss
 
Thanks for opening up another avenue for this Chriss!

My understanding is for someone else to use our service, we need to create and host a service. Please correct me if I am wrong.

We have a VFP application and a client app needs to export some data from it and our VFP app need to import some data from the client app and write back to our tables. It seems creating a HTTP service from scratch in VFP is not an easy task and not in practice anymore. This client app does not support Soap, they only have HTTP service.

If the client can request a export function in their service, that would be great. Could you please explain how this can be done, like what HTTP method, what kind of response VFP need to send back to the client app, etc... Eg: VFP need to send client_id, item_id and item_description to the client app, then get back the client_id(same), item_id(same) and item_description(updated).

Another dumb question. Can a service be created and provided in PHP or Python from our end with our VFP data for our client app to use?

Please suggest is there any other better way to do this task. Thanks!
 
Okay, so now my view shifted, do you program both a desktop application that is the major tool for your VFP data and the app now is an add on to use that same data on smartphones?

Or is this a third party app? Are you doing a cooperation with an app developer/ISV?

PHP and Python for Windows can use OLEDB, so you can use the OLEDB provider for VFP in both languages.

Soap is HTTP based, too, so that would not be the problem, whole databases work via http instead of providing an ODBC driver they work via http, so of course you can do anything you also can do with a database, ie queries that down- or upload batches of data.


Chriss
 
Can a service be created and provided in PHP or Python from our end with our VFP data for our client app to use?

That's the way I would go. A PHP program can natively access a MySQL database, or any other database via OLE DB or ODBC. Your VFP app could then access the same database. Depending on the volume of data and other issues, the PHP app might also be able to share the data via a simple text file; it would create the file on the server from where the VFP app could download it.

There would be security issues to consider, but those would apply whatever solution you adopt.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hello,

on VFEST2021 Rick had a session on creating / consuming Web services with vfp, as always with many explanations and source code.

or see here

and I remember a sample in solutions
maybe here :
regards
tom
 
Thanks for all your inputs.

Just to clarify, we have major desktop application that was built in VFP. We are doing some co-operation with a third party tool (About 10 fields get imported and exported back). There are many business reasons to do this. From the end user point of view, we can use the bells and whistles of the third party tool.

We would prefer going down the HTTP path and avoid ODBC/OLEDB. Going back to my previous question. Could import/export data can be done via the third party application service? Is there any place with some examples using VFP? We like to keep things simple since we don't have enough resources to do tedious tasks.

Soap is HTTP based, too, so that would not be the problem, whole databases work via http instead of providing an ODBC driver they work via http, so of course you can do anything you also can do with a database, ie queries that down- or upload batches of data.

Do we have any examples on this? Please assist. Thanks!
 
Hello,

just to clarify

a) You want to get (fetch) data from another app / webservice / "website" : that means you consume and act as a client.
This can be as easy as the following (or see samples), taken from a little tool of us, add errorhandling / logging as needed.

Code:
oxmlhttp = Createobject("Msxml2.ServerXMLHTTP.6.0") && enter in commandwindow, use intellisense
*oxmlhttp.setoption(3)=name of certificate, optional
oxmlhttp.Open("POST", m.lcyourtargeturl, 'false')
*oxmlhttp.setRequestHeader('yourheader' 		, yourvalue) && optional
oxmlhttp.Send("yourparameters")
If oxmlhttp.Status <> 200
      cmeldung  = Str(oxmlhttp.Status,4,0)
Endif
If Not Isnull( oxmlhttp.responseBody )
      cbody = Strconv( oxmlhttp.responseBody,12)
Endif
If Not Isnull( Oapp.oxmlhttp.responsetext )
      cresult = oxmlhttp.responsetext
Endif

b) you want to send / transfer / offer data to others : create a webservice and act as a server
(for samples see my last post)

Regards
tom


 
gkratnam said:
Do we have any examples on this?

Well, as posted above: (Walkthrough: Creating XML Web Services with Visual FoxPro)
The term Web in Web service already tells you this works through http. XML is the data format, transport protocoll is http.


gkratnam said:
We would prefer going down the HTTP path and avoid ODBC/OLEDB.
You'd do both, ie the app or other client would make http requests to you webserver, that runs a php or python script that uses ODBC or OLEDB to access DBFs with VFP SL or xbase commands (as much as ODBC or OLEDB support, OLEDB knows all VFP9 data types, so it would be preferrable). The PHP or Python then sends the data back as http response, usually in an XML or JSON format the app can use.

You should talk to the app developer to decide about that interface to your data.

gkratnam said:
Could import/export data can be done via the third party application service? I
How should we know without knowing what app you're talking about and what API it offers.

If you're talkoing of something like WhatsApp, that can't be pointed to an API you program, you can only use what WhatsApp offers to developers as API and make posts, read answers.

Further help really depends on what you're talking about, here. You make me wonder since you say:
gkratnam said:
we can use the bells and whistles of the third party tool

That sounds like some already finished app you want to use. At the same time you say:
gkratnam said:
We are doing some co-operation with a third party tool

What does that mean? With a tool? Not with their develoeprs? If you can't decide what their app will use, you can make up whatever you like, but it won't be used. So is the tool in developement or do you want to offer an interface the app can use with slight modifications or what are you talking about?

Chriss
 
Let's talk about it from the other perspective.

As an app developer I would develop an API that can be used to customize the app in some way, but regarding the backend, I'd use my own. Your desktop app also needs a specific set of dbfs, doesn't it? You can't simply replace that with any other database. So there is an application database, and if it's about the same topic/business you might have overlaps, but that doesn't mean you can bind the app to your data, even if you'd know the structure it needs. It will only use it's data and it may allow to post something to it.

Say I programmed an appointment planning app, I'd not only offer an interface for users to directly input possible dates but also an API that allows to use that app function via requests, but I wouldn't let anyone access the whole database, that's too much vulnerability in that, I would guide the data with the functions I provide, that's why it's called a web service (Soap or REST doesn't matter) it's not a database interface. It serves functionalities/features. And of course that way you can add appointments or read them, which is about the same functionality as SQL insert and select, but it won't be ever done directly to the database but to a web service endpoint that decides after authentication and with your permissions what you're able to post or get.

Chriss
 
Apologies, if I am confusing everyone. First, let me go through the reference materials posted by Tom. Then I will have good understanding and hopefully can ask better questions.

Thanks!

 
Like Tom already said, it's a big difference if you only want to act as a client or as a server.

Being a client is very easy in VFP and you don't need any third party tools for simple requests, you only make use of MSXML which is already built into Windows.

As I REST client you can do both, send data with a POST command and receive data with a GET command. Tom gave you an example, if you need more, I can give you other examples.

So if the other application already has a REST API and you can get the desired fields with a GET command and post your data to it with a POST command, you don't have to create a Rest Server yourself. However, if the other application has to initiate calls on your software that's a different story and you need to create your own api which is more difficult. There are ways to do it in VFP i.e. with Rick Strahl's/West Wind tools (links were already posted above).

Another solution to create a simple REST API (Server) is using Googles Go language ("Golang"), which is free, and using vfpoledb.dll to connect to the dbf-database. It's about one page of code and how to do it was show by Cetin Basoz on Foxite. Check out this thread With Go you can create an exe and when you run it, your have the whole REST Server running. If you only need to import/export 10 fields, that should be sufficient.

If you are initiating all the data exchange and the other app has a REST API to import/export data, then you probably don't need to create a REST service yourself, but only act as a client.

Manni
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top