Invoking Services
In addition to properties and property values, all Things have services that perform specific tasks. To manipulate property values, you can use generic services, such as GetPropertyValues(), GetStringPropertyValue(), and SetPropertyValues(). These services are provided automatically on all Things. They provide the basic functionality needed for managing and manipulating properties.There are two kinds of services:
• "Local" services that execute on the Thing
• "Remote" services that are sent to and then executed on your device
Both types of services are invoked the same way, but only custom remote services need to be registered on the edge.
Here are two examples of calling a service, the first one using the C SDK and the second using the Java SDK:
Example 3. Calling a Service from C
#define DONT_FORCE_CONNECTION FALSE
#define SERVICE_CALL_TIMEOUT 5000
#define NO_PARAMETERS NULL
twInfoTable *resultInfoTable = NULL;
twPrimitive *resultPrimitive = NULL;
char *namePropertyValue;
/* Invoke a Service */v
twApi_InvokeService(TW_THING, "DeliveryTruck_1", "GetPropertyValues", NO_PARAMETERS, &resultInfoTable,
SERVICE_CALL_TIMEOUT, DONT_FORCE_CONNECTION);
/* Get name property from result InfoTable */
twInfoTable_GetPrimitive(resultInfoTable, "result", 0, &resultPrimitive);
twInfoTable_GetString(resultInfoTable, "name", 0, &namePropertyValue);
TW_LOG(TW_FORCE,namePropertyValue);
Example 4. Example 4. Calling a Service from Java
ValueCollection paramValues = new ValueCollection();
int remoteTimeout = 5000;
String thingName = "DeliveryTruck_1";
String serviceName = "GetPropertyValues";
InfoTable resultInfoTable = client.invokeService(RelationshipTypes.ThingworxEntityTypes.Things,
thingName, serviceName, paramValues, remoteTimeout);
InfoTable propertyValue = (InfoTable)resultInfoTable.getRow(0).getValue("result");
String thingNamePropertyValue = propertyValue.getFirstRow().getStringValue("name");
System.out.println("Name property is :"+thingNamePropertyValue);