You are here: Web Services > Consuming Web Services > Tutorial 1 - Google Translate API > Wrapping Your Translate Code in a Reusable Part

Wrapping Your Translate Code in a Reusable Part

To promote reuse and to hide the complexity of the web service invocation, move your translate code to a self-contained reusable part.

Create a new reusable part called GoogleTranslateWebService.

Set the Target Platform to Windows/IBM i/Linux.

Move your code from the previous section to the reusable part.

Begin_Com Role(*EXTENDS #PRIM_OBJT)

 

Mthroutine Name(Translate)

   Define_Map For(*RESULT) Class(#PRIM_DC.UnicodeString) Name(#TranslatedText)

   Define_Map For(*INPUT) Class(#PRIM_DC.UnicodeString) Name(#SourceLanguage)

   Define_Map For(*INPUT) Class(#PRIM_DC.UnicodeString) Name(#TargetLanguage)

   Define_Map For(*INPUT) Class(#PRIM_DC.UnicodeString) Name(#SourceText)

   Define_Map For(*OUTPUT) Class(#PRIM_BOLN)            Name(#OK)

   Define_Map For(*OUTPUT) Class(#PRIM_DC.UnicodeString) Name(#ErrorCode)

   Define_Map For(*OUTPUT) Class(#PRIM_DC.UnicodeString) Name(#ErrorMessage)

 

 

   * Insert your code from the previous section here

   * . . .

   * . . .

 

Endroutine

Other developers can now easily use your GoogleTranslateWebService component without having to understand the details of the Google Translate web service invocation.

Next: Tutorial 2 - Executing Java Code via Web Services