You are here: Web Services > Consuming Web Services > Tutorial 1 - Google Translate API > Creating a Webpage to Test Your Server Module

Creating a Webpage to Test Your Server Module

Create a new webpage called GoogleTranslateTestWebPage.

Add an Initialize event if it's not there already:

Evtroutine Handling(#Com_owner.Initialize)

 

Endroutine

Add the following code in the Initialize event:

* Create the server module object

Define_Com Class(#GoogleTranslateServerModule.Translate) Name(#Translator)

* Variables to hold translated text, error message, and status

Define_Com Class(#PRIM_DC.UnicodeString) Name(#TranslatedText)

Define_Com Class(#PRIM_DC.UnicodeString) Name(#ErrorMessage)

Define_Com Class(#PRIM_BOLN) Name(#OK)

* Invoke the server module

#Translator.Execute Sourcetext('This is so cool!') Sourcelanguage('en') Targetlanguage('fr') Translatedtext(#TranslatedText) Ok(#OK) Errormessage(#ErrorMessage)

* Display the result (if OK), or error message (if failed)

If (#OK)

   #SYS_WEB.Alert Caption('The translated text in French: ' + #TranslatedText)

Else

   #SYS_WEB.Alert Caption('An error has occurred: ' + #ErrorMessage)

Endif

If you have the right API key setup, you should see the following when you run the webpage:

Next: Wrapping Your Translate Code in a Reusable Part