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:
Calling SOAP Web Services Using Structs
Cancel

Working with SOAP Web Services

Lesson 5: Calling SOAP Web Services - The basics

This lesson will show how to create a DataFlex program that will call on the web service that created in the previous lessons in this series.

  1. From the DataFlex Studio select FILE > NEW > PROJECT > WINDOWS PROJECT. Select OK.
  2. Add “TestWebservice” as the file name. Select OK.
  3. Select FILE > NEW > VIEW/REPORT > DATA ENTRY VIEW. Select OK.

  4. Add “oVwTestWs” as the ‘Object Name.’ Select OK.
  5. Starting with the simplest function that was previously created, the Hello function…
  6. Open the ‘Class Palette’ by selecting its tab from the bottom of the left panel.
  7. Click on “Button” and drag and drop it on the view.
  8. Double click on the VwTestWs.vw [Design] view to open the code for VwTestWs.vw
  9. Before adding code to specify the buttons onclick behavior, an implementation class of the existing web service needs to be created.
  10. Select FILE > NEW > CLASS
  11. Select CLIENT WEB SERVICE CLASS, and select OK.
  12. Fetch the URL that the web service is running on, add “?wsdl” to the end of it.
  13. Paste it into the WSDL URL field, and select PARSE. The web service class will then be generated.
  14. Select GENERATE CLASS, enter “cWSCookbookWebService” into the ‘Class Name’ field, and select OK.
  15. The Cookbook webservice class has now been created, so that it can used in an application. It contains all the functions and information required to call on the web service.
  16. To view the available functions, open the ‘Code Explorer’ by selecting its tab from the bottom of the left panel.
  17. To create the button’s onclick behavior that will return a string…
  18. Select the view, ‘VwTestWs.vw’
  19. Create an implantation of the generated web service client class.
  20. First import it: Use cWSCookbookWebService.pkg
  21. Create a new CookBook webservice:
    Object oCookbookWS is a cWSCookbookWebService

    End_Object



  22. That web service line object can now be used in the onclick procedure.
    // fires when the button is clickedProcedure OnClick
         String sRet

    Get wsHello of oCookbookWS to sRet

    Showln sRet
    End_Procedure

  23. Select the RUN icon from the top toolbar.
  24. The new program is loaded in a separate view.
  25. Select VIEW > VwTestWs from its menu to open the view that shows the button that was just created.

  26. Clicking the button opens an output window that reads as it should, “Hello from the other side!”
  27. Next, preparing the program to call upon the ‘AddNumbers’ function...
  28. Return to the DataFlex Studio, and open VwTestWs.vw [Design]
  29. Add two forms to the design of the program by clicking on ‘Form’ from the ‘Class Palette,’ and dragging and dropping the fields onto the view.
  30. Add a new button onto the form by clicking on ‘Button’ from the ‘Class Palette,’ and dragging and dropping the button onto the view.
  31. In the code change the names of the form fields and the button and add onclick functionality to the button.
  32. Field 1:                Object oFormNr1 is a Form

    Field 2:                Object oFormNr2 is a Form

  33. Button:              

    Object oBtnAddnumbers is a Button

                 Set Location to 53 202

                 Set Label to ‘Add numbers’

                 //fires when the button is clicked

                 Procedure OnClick

                        Integer iA iB iRet

                        Get Value of oFormNr1 to iA

                        Get Value of oFormNr2 to iB

                        Get wsAddNumbers of oCookbookWS iA iB to iRet

                        ShownIn (iRet)

    End_Procedure



  34. Select the RUN icon from the top toolbar.
  35. The program is loaded in a separate view.
  36. Select VIEW > VwTestWs from its menu to open the view that shows the button that was just created.
  37. Add numbers to both form fields and select ‘Add numbers.’
  38. The web service will be called, and the output will be the sum of the numbers.