To continue with this content, please log in with your Data Access ID or create a new account.
Cancel Data Access ID
You may not be authorized to see this content. Please contact Data Access Europe for more information.
Cancel Data Access Europe
You are not authorized to see this content.
Cancel Data Access Europe
Next lesson:
Cancel

Working with Web Services

Lesson 6, Calling SOAP Web Services - Using structs

In lesson 5 of this course, Calling SOAP WebServices – the basics, two examples were shown for calling simple functions of the web service. In this lesson, two complex examples will be shown using structs.


They will show that structs in a DataFlex program can be used to return values and extract the information to be displayed on screen. They can also be used as a parameter to be passed along to functions, and then the web service can be called on.


  1. Returning to the DataFlex Studio, select the ‘cWSCookbookWebService.pkg’ tab.
  2. The top shows that the two structs that will be used for the calls have already been created. They will be used in the application’s logic.
  3. To create logic that calls on the service that fetches a recipe’s information by its recipe ID (return value)…
  4. From VwTestWs.vw [Design] add one form field to the design of the program by clicking on ‘Form’ from the ‘Class Palette,’ and dragging and dropping the fields onto the view. 
  5. Add a new button onto the form by clicking on ‘Button’ from the ‘Class Palette,’ and dragging and dropping the button onto the view.
  6. In the code (VwTestWs.vw), change the name, label, and the label’s justification of the first field…
  7. Field 1 name:   Object oFormRecipeID
  8. Field 1 label:  Set Label to “Recipe ID”
  9. From the ‘Properties’ section in the right panel:
  10. Change ‘Label_Justification_Mode’ to “JMode_Top”
  11. Change ‘Label_Col_Offset’ to “0”
  12. For the button…
    Object oBtnGetRecipe is a Button

          Set Location to 14 51

          Set Label to ‘Get Recipe’


          //fires when the button is clicked

          Procedure OnClick

                tWStRecipe oRecipe

                Integer iRecipeID


                Get Value of oFormRecipeID to iRecipeID


                Get wsGetRecipe of oCookbookWS iRecipeID to oRecipe


                Showln oRecipe.iRecipeID

                Showln oRecipe.sName

                Showln oRecipe.sKitchen

                Showln oRecipe.sHowToMake

                Showln oRecipe.iPrepTime

                Showln oRecipe.iRating


          End_Procedure



  13. Select the RUN icon from the top toolbar.
  14. The program is loaded in a separate view.
  15. Select VIEW > VwTestWs from its menu to open the view that shows the button that was just created.
  16. Entering a Recipe ID, and selecting the ‘Get Recipe’ button results in all of the recipe information being called.
  17. To create a logic that will call on the add recipe function to add a recipe through the program…
  18. Stop the Debugger by pressing on the icon on the top toolbar.
  19. From VwTestWs.vw [Design] add a group to the design of the program by expanding ‘Base Containers’ in the Class_Palette panel, clicking on ‘Group’ and dragging and dropping the group onto the view. 
  20. Resize the width of the group to nearly the full width of the view.
  21. Add three form fields to the design of the program by clicking on ‘Form’ from the ‘Class Palette,’ and dragging and dropping the fields onto the view.
  22. Add a large form to the design of the program by clicking on ‘cTextEdit’ from the ‘Class Palette,’ and dragging and dropping it onto the view. Resize as needed.
  23. Add a new button onto the form by clicking on ‘Button’ from the ‘Class Palette,’ and dragging and dropping the button onto the view.
  24. In the code (VwTestWs.vw), change the name and label of the first form and adjust its position:
    Object oFormRecipeName is a Form      Set Size to 13 100
    Set Location to 19 13
          Set Label to ‘Name’
          Set Label_Justification_Mode to JMode_Top
          Set Label_Col_Offset to 0

  25. For the second form…
    Object oFormPrepTime is a Form      Set Size to 13 100
    Set Location to 46 11
          Set Label to ‘Preparation Time”
          Set Label_Justification_Mode to JMode_Top
          Set Label_Col_Offset to 0

  26. For the third form…
    Object oFormRecipeKitchen is a Form      Set Size to 13 100
    Set Location to 46 161
          Set Label to ‘Kitchen’
          Set Label_Justification_Mode to JMode_Top
          Set Label_Col_Offset to 0

  27. For the fourth (large field) form…
    Object oFormRecipeHowToMake is a cTextField      Set Size to 38 242
    Set Location to 71 11
          Set Label to ‘How to make
          Set Label_Justification_Mode to JMode_Top
          Set Label_Col_Offset to 0

  28. For the button…
    Object oBtnAddRecipe is a Button      Set Location to 17 196
          Set Label to ‘Add Recipe’

          //fires when the button is clicked
          Procedure OnClick
                tWStRecipeIn oRecipe
                Boolean bOk
               
                Get Value of oFormRecipeName to oRecipe.sName
                Get Value of oFormRecipeKitchen to oRecipe.iKitchenID
                Get Value of oFormRecipePrepTime to oRecipe.iPrepTime
                Get Value of oFormRecipeHowToMake to oRecipe.sHowToMake

                Get wsAddNewRecipe of oCookbookWS oRecipe to bOk

                If (bOk) Begin
                     Send Info_Box “Recipe added!” “”

                     Set Value of oFormRecipeName to “”
    Set Value of oFormRecipeKitchen to “”
    Set Value of oFormPrepTime to “”
    Set Value of oFormRecipeHowToMake to “”  
    End
                End_Procedure

  29. Select the RUN icon from the top toolbar.
  30. The program is loaded in a separate view.
  31. Select VIEW > VwTestWs from its menu to open the view that shows the button that was just created.
  32. Entering a text info into all of the fields and selecting the ‘Add’ button results in pop up showing “Recipe added!”
  33. The new recipe will also be added to the Recipe table.