DataFlex allows the developer to consumer SOAP webservices. This tutorial will show how easy it is to do just that.

In order to consume a web service of course we need one first. For this example we chose a publicly available service that returns the weather for a given city.

A soap web service has an address, essentially a URL on the web or intranet that points to the web service

in our example the address for the web service is

http://www.webservicex.com/globalweather.asmx

a soap web service also has whats called a WSDL (Web Service Definition Language) which is an XML document that describes the web service interface.

Most web services allow you to query the WSDL by appending ?WSDL to the URL for example

http://www.webservicex.com/globalweather.asmx?WSDL

Now we can start with a new workspace in the DataFlex Studio. After setting up a new workspace we need to also create a new project. Make it a Windows project, give it a name and save.

In order to call a web service we need to create a client web service class in the Studio

select File->New->Class

newclass

select Client Web Service Class and click Ok

wsclass

enter the URL including the WSDL and click Parse. If the URL is correct and the web service is active the Studio will generate a class for the web service

Also in case you run into problems with a web service that used to be working before you may want to come back and regenerate the class to see if the web service has changed.

Whenever i regenerate web service classes i keep the old copy and compare them using Beyond Compare to see what has changed so i can determine if the changes will have any effect on my code

Once you click Generate Class you get more options and then the class package is generated

in our example you can see a function called wsGetWeather that accepts a city and country name and then returns the weather as a string

In order to test our web service we create a simple view

we need to use the package created earlier

simpleview

Then we add a form for the city and country and a button to call the service and a TextEdit control to show the result

in addition we need to create the web service object. We can either drag and drop the web service object from the web service palette or simply create it in code

wsobject

We add a method to call the service called RequestGetWeatherInfo

from the button we call the method

buttoncode

First we get the value of the city and country entered and then call the wsGetWeather function. After calling the web service we show the data returned in the textedit control

return

You can see the service returns XML data containing the location information, time and weather information

This shows how easy it is to call simple web services. It allows us to interface with a large variety of other systems out there

In addition DataFlex Webapp also allows us to create server side web services. This can be used for example to communicate between multiple offices.

We have used a large number of web services in our applications from banking, UPS, Fedex and USPS interfaces, and more and also our own custom web services with the server side either written in .NET or in DataFlex WebApp

We have also used DataFlex WebAPP server side services and then consumed them from native iOS applications and native Windows Universal apps allowing them all to talk to the same DataFlex middle tier.

Michael Salzlechner is the CEO of StarZen Technologies, Inc.

He was part of the Windows Team at Data Access Worldwide that created the DataFlex for Windows Product before joining StarZen Technologies. StarZen Technologies provides consulting services as well as custom Application development and third party products specifically for DataFlex developers