1 Reply Latest reply on Jun 1, 2016 9:43 PM by hhsu RSS
    lukass Newbie

    Issues creating a service without annotations

    Hi all,


    i tried to create a Service following this example:



    but somehow it does not work for me.


    I am able to create Thing and Properties without annotations (Properties are also set correctly on the server), but when i try and copy the sxample code from the Documentation i encounter a problem.


    I am able to see the Service in the "Browse Remote Services" section and i can also enter the parameters, but everytime i try to execute the Service i get this error:


    Unable to Invoke Service Add on Simple1 : Service Handler For [Add] Does Not Exist On Thing [Simple1]

    i know this error occurs when i try to test a service without saving but i did save it.


    I created a simple thing which only sends a random int to my server.


    See my Code for the SimpleTing1 here:


    package com.tinkerforge;

    import java.util.Random;

    import com.thingworx.communications.client.ConnectedThingClient;

    import com.thingworx.communications.client.things.VirtualThing;

    import com.thingworx.metadata.FieldDefinition;

    import com.thingworx.metadata.PropertyDefinition;

    import com.thingworx.metadata.ServiceDefinition;

    import com.thingworx.metadata.annotations.ThingworxServiceDefinition;

    import com.thingworx.metadata.annotations.ThingworxServiceParameter;

    import com.thingworx.metadata.annotations.ThingworxServiceResult;

    import com.thingworx.metadata.collections.FieldDefinitionCollection;

    import com.thingworx.types.BaseTypes;

    import com.thingworx.types.collections.AspectCollection;

    import com.thingworx.types.constants.Aspects;

    import com.thingworx.types.constants.CommonPropertyNames;

    import com.thingworx.types.constants.DataChangeType;

    import com.thingworx.types.primitives.BooleanPrimitive;

    import com.thingworx.types.primitives.IntegerPrimitive;

    import com.thingworx.types.primitives.NumberPrimitive;

    import com.thingworx.types.primitives.StringPrimitive;



    public class SimpleThing extends VirtualThing implements Runnable  {



    private static final long serialVersionUID = 1L;

    public SimpleThing(String name, String description, ConnectedThingClient client) throws Exception {

        super(name, description, client);


      //Create the property definition with name, description, and baseType

      PropertyDefinition property1 = new PropertyDefinition(


         "Description for Property1",




      //Create an aspect collection to hold all of the different aspects

      AspectCollection aspects = new AspectCollection();



      //Add the dataChangeType aspect


      new StringPrimitive(DataChangeType.ALWAYS.name()));



      //Add the dataChangeThreshold aspect

      aspects.put(Aspects.ASPECT_DATACHANGETHRESHOLD, new NumberPrimitive(0.0));



      //Add the cacheTime aspect

      aspects.put(Aspects.ASPECT_CACHETIME, new IntegerPrimitive(-1));



      //Add the isPersistent aspect

      aspects.put(Aspects.ASPECT_ISPERSISTENT, new BooleanPrimitive(false));



      //Add the isReadOnly aspect

      aspects.put(Aspects.ASPECT_ISREADONLY, new BooleanPrimitive(false));



      //Add the pushType aspect

      aspects.put("pushType", new StringPrimitive(DataChangeType.ALWAYS.name()));



      //Add the defaultValue aspect

      aspects.put(Aspects.ASPECT_DEFAULTVALUE, new NumberPrimitive(2));



      //Set the aspects of the property definition




      //Add the property definition to the Virtual Thing







      //Put this code in the constructor (or a method called from the constructor)



      ServiceDefinition serviceDef = new ServiceDefinition(


      "Add two numbers");

      FieldDefinitionCollection parameterFields =

          new FieldDefinitionCollection();


      new FieldDefinition(




      "The first addend of the operation",




      new FieldDefinition(




      "The second addend of the operation",





      FieldDefinition resultField = new FieldDefinition(


      "The sum of the two parameters",














      public Double Add(Double p1, Double p2) throws Exception {



           return p1 + p2;





      public void set(){

      try {

      setProperty("Property1",  randInt(10,700));

      System.out.println("Property for Simple Thing sent to Server");


      } catch (Exception e) {




      public static int randInt(int min, int max) {



      Random rand = new Random();



      int randomNum = rand.nextInt((max - min) + 1) + min;



      return randomNum;



      public void processScanRequest() throws Exception {

      // Be sure to call the base classes scan request


      // Execute the code for this simulation every scan





      public void run() {

      try {


      } catch (Exception x) {









    Thanks for your help,