Words:  

Re: SOAP Query to Export Data

Date: 09-02-10
From: David Dancy <david.dancy_at_gmail.com>

Gordon

[From your query it's not clear how much you already know about SOAP,
web services or 4D in general. I apologise if this isn't what you're
looking for, but I've aimed my reply at someone who's never tried a
web service in 4D.]

SOAP isn't a query system by itself; it's a message-passing system.
The thing you'll need to do is to define an interface for your
queries, build it as a web-services-enabled method, and then you'll be
able to call it from another program. In this context SOAP really has
nothing to do with the query - it just enables two different
applications to talk to one another by defining a common data-transfer
format (in XML).

That said, I'd suggest that unless you really need to be able to ask
"generic" queries via web services that you implement each one
specifically. That way, you can change the underlying format of the
data (e.g. normalise/denormalise, rearrange tables/fields) and the
caller need not even know you've done it. Let's say I need to get all
orders created today from my web service.

1. I define a web-service-enabled method (tick the box in method
properties), and give it a sensible name. We use "WS_" as a prefix for
all our web service methods; you can choose whatever you like. My
orders created method will be called "WS_GetOrderSummary".

2. I define in the WS_GetOrderSummary method an interface that says
what SOAP parameters the method accepts:

`Input parameters
SOAP DECLARATION(FromDate;Is date;SOAP Input;"FromDate")
SOAP DECLARATION(ToDate;Is date;SOAP Input;"ToDate")

`Output parameters (can be more than one)
SOAP DECLARATION(OrdersXML;Is BLOB;SOAP Output;"Data")
SOAP DECLARATION(ErrorCode;Is longint;SOAP Output;"ErrorCode")

3. Then I do the query:

QUERY([Orders];[Orders]OrderDate>=FromDate;*)
QUERY([Orders];&;[Orders]OrderDate
4. Then I build the XML BLOB containing my Orders data:

C_BLOB(OrdersXML)
SET BLOB SIZE(OrdersXML;0)

TEXT TO BLOB(XMLHeader;OrdersXML;*) `XMLHeader is preconfigured to say
something like "

For($Record;1;Records in selection([Orders]))
`Build XML of each Order into OrdersXML BLOB
NEXT RECORD([Orders])
End for

5. If there are no orders, or if something else goes wrong, set
ErrorCode to some meaningful value.


When you call this method from another application, 4D interprets the
call, unpacks the XML SOAP envelope and automatically fills the
variables FromDate & ToDate from the incoming data. It then runs the
rest of the code, and when the method has completed it packs the
designated output parameters into a SOAP envelope and sends them back
to the caller.

If you really must do "generic" queries on your database you can
easily define an interface using either table/field names (more
portable) or table/field numbers (may be faster, but specific to 4D).

HTH

David Dancy
Sydney, Australia



On 9 February 2010 12:28, Gordon Thompson wrote:
> Is there a simple example to use SOAP to query a 4D Server (2003) database and return the result set? We need to export time-series data on a daily basis. Thanks for your help!
**********************************************************************
The New 4D Partner Program - All the tools you need to be a successful 4D Developer.
Sign up Now: http://www.4d.com/community/partner/registration.html


4D Internet Users Group (4D iNUG)
FAQ: http://lists.4d.com/faqnug.html
Archive: http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:4D_Tech-Unsubscribe_at_lists.4D.com
**********************************************************************