Working with SOAP Web Services
Lesson 3: Returning Structs
Building from the last lesson, this lesson will show how to use structs in a web service.
- Create a function from to retrieve a recipe from the “Recipe” table.
- From the ‘Table Explorer’ on the left, right click on the “Recipe” table, and select “View Table” to view the available table.
- Return to the WsCookbook.wo tab.
- Add a function to get the recipe
Function GetRecipe Integer iRecipeID Returns tRecipe
_Function
- Define tRecipe by adding the struct to the top of the code including variables used in the Recipe table.
Struct tRecipe
Integer iRecipeID
String sName
String sKitchen
String sHowToMake
Integer iPrepTime
Integer iRating
End_Struct
- Use the existing DDO to retrieve the actual recipe from the table.
- To add it to WsCookbook.wo open the ‘DDO Explorer’ by clicking on its tab located on the bottom of the right panel.
- Select the Add a New DDO icon.
- Highlight “cRecipeDataDictionary,” and choose ‘Select.’
- Update the tRecipe function to fetch recipes by ID, publish, and add a description.
{Published = True}
{Description = “Gets a recipe by its ID”}
Function GetRecipe Integer iRecipeID Returns tRecipe
tRecipe oRecipe
Send Clear of oRecipe_DD
Move iRecipeID to Recipe.RecipeID
Send Find of oRecipe_DD EQ 1
If (Found) Begin
Move Recipe.RecipeID to oRecipe.iRecipeID
Move Recipe.Name to oRecipe.sName
Move KitchenName to oRecipe.sKitchen
Move Recipe.Rating to oRecipe.iRating
Move Recipe.PreparationTime to oRecipe.iPrepTime
Move Recipe.HowToMake to oRecipe.sHowToMake
End_Function
- Select run icon from the top toolbar.
- The web browser page now shows all three functions.
- Selecting “GetRecipe” calls the new function.
- Entering a Recipe ID value, and clicking invoke will call the corresponding recipe variables translated in XML.