Web Services Example: Creating the VTS Module

To fully understand the following block of code requires some knowledge of VTS's programming language.  However, the important points are easily described:

 

GetTagValue is the name of the subroutine which will do exactly that function: get the requested tag's value.

The ServiceActive line includes a call to the function SetWSDL.  This function requires four parameters:

     The location of the WSDL file,

     The name of the realm,

     The scope of the call (in this case, 'self' - the current module),

     The name of the service - which was pointed out in the preceding section on the WSDL file

An optional 5th parameter is pResponse:  a pointer to an error message to return should SetWSDL fail.

 

The MAIN section of the code is somewhat cryptic, but what it does is rather simple:  It takes any given tag name and attempts to find the current value associated with that tag.  If found, the value will be returned along with a "0" to indicate success.  Otherwise, a value of "-1" is return to indicate failure.

 

Text lines between braces {...} are comments.

{=========================== TagQueryServices =========================}

{ This module contains the code that implements the services provided.         }

{======================================================================}

[

  ServiceActive               { Return value from SetWSDL };

  GetTagValue    Module;

]

Init [

  If Watch(1);

  [

    ServiceActive = \System\WebService\SetWSDL(

       "file://C:/vts/StationExample/TagQueryServices.wsdl",

       "QueryServicesRealm",

       Self,

       "TagQueryServices");

  ]

]

{============================= GetTagValue ==========================}

{ Subroutine called through SOAP to request the value of a tag.                }

{====================================================================}

GetTagValue

(

  request;

  response;

)

[

  TagName;

  TagObj;

]

Main [

  If 1;

  [

     TagName = (*request)\TagName;

     TagObj = Scope(\Code, TagName);

     

     IfElse(Valid(TagObj), Execute(

       (*response)\TagValue = TagObj\Value; { get the tag's value }

       (*response)\ReturnCode = 0;     { success }

     );

     {Else}

       (*response)\ReturnCode = -1;    { error - tag doesn't exist }

     );

     Return (0);

  ]

]  

 

Next Step:  Telling your application where to find this module.