Working with SOAP Web Services
Lesson 2: Creating a simple SOAP Web Service in DataFlex
In this lesson, creating a web service in DataFlex will be shown using a previously created workspace called “Cookbook.” This was created in the Data Dictionairies Course.
- Open DataFlex as an administrator
- From the Worspaces panel on the left select “Cookbook”
![](/ContentData/993-WebServicesL2_1_cookbookWS.png)
- To create a project, select FILE > NEW >PROJECT
![](/ContentData/994-WebServicesL2_2_newProj.png)
- Select ‘Mobile Web Project’ from the options and press ‘OK’
![](/ContentData/995-WebServicesL2_3_MobWP.png)
- Name the service, “CookbookWebService,” leave the remaining selections as they appear, and select OK.
![](/ContentData/996-WebServicesL2_4_webAppName.png)
- To create a new web service class, select FILE > NEW > WEB OBJECT
![](/ContentData/997-WebServicesL2_5_newWO.png)
- Select ‘Web Service Object’ from the options and press ‘OK’
![](/ContentData/998-WebServicesL2_6_webServO.png)
- Name the object “oWsCookbook,” and select OK thus creating the web service class.
![](/ContentData/999-WebServicesL2_7_webServOname.png)
- Shown is the psDocumentation that provides the opportunity to enter a description about what the web service does.
- For this example, “This is the cookbook webservice” is entered.
![](/ContentData/1000-WebServicesL2_8_description.png)
- Viewing the properties panel (CTRL+2) shows that several other properties that can be set.
- Set “psServiceTitle” to “CookbookWs.” This then added to the code.
![](/ContentData/1001-WebServicesL2_9_title.png)
- Next, create a simple method that will return a greeting, publish the function so that it can be called by the service, and add a description…
{Published = True}
{Description = “Returns a simple hello message”}
Function Hello Returns String
Function_Return “Hello from the other side!”
End_Function
![](/ContentData/1002-WebServicesL2_10_method.png)
- Select run icon from the top toolbar.
- A web browser page will open showing the generated page that shows the web service.
![](/ContentData/1003-WebServicesL2_11_browser.png)
- Selecting the “Hello” calls on the Hello function that was just created.
![](/ContentData/1004-WebServicesL2_12_browser2.png)
- Click on “Invoke,” and the specified string will appear; “Hello from the other side!”
![](/ContentData/1005-WebServicesL2_13_browser3.png)
- Another example of a function would be to add two numbers.
{Published = True}
{Description = “Adds 2 numbers and returns the result”}
Function AddNumbers Integer 1A Integer 1B Returns Integer
Function_Return (1A + 1B)
End_Function
![](/ContentData/1006-WebServicesL2_14_secondMethod.png)
- Select run icon from the top toolbar.
- The web browser page now shows both functions.
![](/ContentData/1007-WebServicesL2_15_browser1b.png)
- Selecting “AddNumbers” calls the new function.
![](/ContentData/1008-WebServicesL2_16_browser2b.png)
- Enter values in the 1A and 1B fields, select “invoke,” and the result will be shown.
![](/ContentData/1009-WebServicesL2_17_browser3b.png)