Q:
We are looking to write a simple data import webservice.
ie 3rd party submits an pre-defined xml stream to our server, webservice puts data in the relevant table fields. No interface required.
A:
1. Install Lianja Cloud Server alongside your App. This will access the same data as your desktop RDP App.
2. Write a small .rsp page that accepts the XML data, parses it and inserts/updates your tables.
A2:
There are examples once you have installed the Cloud Server. These demo the contents of these special arrays. Look in the examples directory then type http://localhost:8001/examples/example_xxx.rsp where xxx is the example name from the examples directory.
The arrays contain the same members as in PHP without the leading $, so the $_server PHP array is called _server in Lianja.
The _server["body"] contains whatever it was that was posted. You should use POST rather than GET which sends everything in the URL and has smaller size restrictions in the browser.
Lianja Cloud Server supports ActiveX so you should be able to use oledb to update your VFP tables.
Depending on the complexity of the XML you are sent you may be able to use xml_decode() or the xquery functions.
If you do not have the time or inclination to do any of this you can have us do it for you and give you back the .rsp web service.
A3:
You need to POST to your web service e.g. mywebservice.rsp?arg1=hello&arg2=world and include the XML/JSON as the data.
Code:
<%@ Language=VFP %>
<html>
<head>
</head>
<body>
<%
private p_arg1 = getParameter("arg1", "")
private p_arg2 = getParameter("arg2", "")
private p_data = _server["body"]
// p_data now contains your XML or JSON that was POSTed to the web service.
// Now use the xquery() function to extract the information you want and then write back a response if required
//
// Everything you output using e.g:
//
// ?
// echo
// text raw...endtext
//
// is sent back to the client
%>
</body>
</html>
There are no args in a HTTP POST. Everything is in the body.
You have a desktop app that is running on user desktops.
You want to somehow get information from the running app and return that information as JSON, XML or an HTML page.
There is an simple http server built into your Lianja Apps that run under the App Center. By default this server listens on port 8002 but this is configurable (in the App settings) and handles asynchronous service requests while your App is running.
So while an App is running, from another App you can query it e.g.:
Code:
result = getURL("http://localhost:8002/desktopwebservice/dws_getinfo?customerid=ALFI")
The web service name follows /desktopwebservice/ in the URL and is a normal program or proc. In this case we have a script named dws_getinfo. It is good practice to name these consistently and place them in the library directory. I would recommend prefixing your desktop web services with dws_.
Code:
// In this example, the URL will contain "/desktopwebservice/dws_getinfo" and args will contain "customerid=ALFI"
// dws_getInfo.prg in the library
private p_url
private p_arg
private p_args = explode("&", p_arg)
private p_customerid = getMember("p_args", "customerid", "")
return "{'url': '&p_url, 'customerid': '&p_customerid'}"
Your service may return a JSON encoded object (as shown above), an XML string, an HTML string or plain text.
If the result returned starts with "file:" then the file specified e.g. "file:mytempfile.txt" is read and the result is sent back to the client. This provides the ability to query large amounts of information not limited by internal string length.
If the result returned starts with "tempfile:" then the file specified e.g. "tempfile:mytempfile.txt" is read and the result is sent back to the client. The file mytempfile.txt is then deleted.
Notice that in the example above no file extension was given to dws_getinfo so ".prg" (Lianja/VFP script) is assumed. You could also specify:
Code:
result = getUrl("http://localhost:8002/desktopwebservice/dws_getinfo.js?customerid=ALFI")
or
Code:
result = getUrl("http://localhost:8002/desktopwebservice/dws_getinfo.php?customerid=ALFI")
or
Code:
result = getUrl("http://localhost:8002/desktopwebservice/dws_getinfo.py?customerid=ALFI")
or
Code:
result = getUrl("http://localhost:8002/desktopwebservice/dws_getinfo.rsp?customerid=ALFI")
or
Code:
result = getUrl("http://localhost:8002/desktopwebservice/dws_getinfo.jssp?customerid=ALFI")
This is not designed to replace the Cloud Server which handles multiple concurrent requests but rather to provide a means of introspecting running apps and consolidating information from them.
It is not difficult to see how you could use this to great effect with desktop LAN apps in a Web App that uses a .rsp page that queries information from the various clients running Lianja Apps.
Tip: remember to use SAVE/RESTORE DATASESSION as these web service requests are handled asynchronously while your App is running.
Tip: you could specify an apikey=value on the URI and the authenticity of the apikey will be verified when the desktop web service request is received. The API key is an attribute in the App settings. There is a default key generated for you. Look in the App settings for it.
Q:
We have been asked for a webservice that does the full .NET thing ie (HTTPS/WSDL/Schema/SOAP etc) but if we can get them to just do a simple POST (credentials are in the xml)
A:
The desktop web service API does not currently handle POST operations. It is purely for HTTP GET operations.
It should not be used for heavy usage as it does interfere with the event dispatching in the main GUI thread and will slow user response down if requests are made continually. In that case you should be using the Lianja Cloud Server which is much more functional and handles HTTPS through the IIS/Apache extension.
If you have been asked for the whole kitchen sink of ways to call a web service, better to formalize an API that they should use to interact with your application and let them know the format that requests would be made.
POSTing requests and parsing the XML _server["body"] is all you really need to do. You can authenticate using an API key and/or a session cookie. Any cookie created on the server and sent back to the client (just set _cookie["name"] = value) cannot be altered or deleted on the client. These are known as session cookies and are protected by the browser.
All topics in [Answers] alphabetically:http://www.lianja.com/community/show...ll=1#post12352
Bookmarks