Skip to main content
1-Visitor
September 21, 2016
Solved

Run a local service from SDK

  • September 21, 2016
  • 2 replies
  • 6513 views

I am new to Thingworx and trying to understand how the services work through an SDK (.net for what it's worth).

Basically I want to know how to run a local service (local being relative to the platform) from my client code.  I see how we create a remote service, pick it up at the platform and can test it out at the platform which executes the code on the client.  How do I do the opposite where I reach up to the platform, execute a service and get the result back down to the client?

Best answer by rupadhyay

Hi Chris,

There are numerous ways to achieve this.

Firstly , Once a Virtual Object from Java SDK is binded with Remote Thing on Thingworx server , all the properties can be pushed from Virtual object to Remote Thing on Thingworx , and you can put an alert against any such properties to call a service once certain specified condition is met. I mean you can call service depending on value of any property.

Secondly , You can invoke a service on Thing from Client application.

I am sending you a small documentation wherein an example code is given for service invoked from from Java SDK .

(Please excuse the formatting , as I created just for single user , ie you. )

2 replies

1-Visitor
September 21, 2016

Hi @Chris

I have achiveved the similar functionality through Java SDK.

We have created a service on Things which when invoked from Java SDK running on Remote machine can create another thing from a specific template.

Please see the steps and code below:

Step 1 Create a new Template named as "TemplateForCreatingThingsRemotely" from Remote Template.

Step 2  Add Service with Name "CreateThing"  with one input which would be name of  new Thing which will be created

Example Script :

var params = {

  name: NameOfThing /* STRING */,

  description: me.description /* STRING */,

  thingTemplateName: me.thingTemplate /* THINGTEMPLATENAME */,

  tags: me.tags /* TAGS */

};

  // no return

Resources["EntityServices"].CreateThing(params);

 

Step 3 , Create a Thing Extending this newly created Template.

Step 4 Test the Service .

Now you need to call the service of first Thing which you have created from "TemplateForCreatingThingsRemotely"from Edge or Java SDK.

Please do let me know if you find this useful or if  you need further clarification or help on this

cjackson11-VisitorAuthor
1-Visitor
September 21, 2016

Hello Ravi,

Thanks for replying, let me specify more.  I think the part I'm not clear on is after step 4, you call the service from the SDK.  It's not clear from the SDK guide or Function calls in the VirtualThing class as to how to actually run a service which resides on the platform from code.  It seems I can only run remote services that I define in my client code.  Hope that makes sense.

-Chris

rupadhyay1-VisitorAnswer
1-Visitor
September 21, 2016

Hi Chris,

There are numerous ways to achieve this.

Firstly , Once a Virtual Object from Java SDK is binded with Remote Thing on Thingworx server , all the properties can be pushed from Virtual object to Remote Thing on Thingworx , and you can put an alert against any such properties to call a service once certain specified condition is met. I mean you can call service depending on value of any property.

Secondly , You can invoke a service on Thing from Client application.

I am sending you a small documentation wherein an example code is given for service invoked from from Java SDK .

(Please excuse the formatting , as I created just for single user , ie you. )

cjackson11-VisitorAuthor
1-Visitor
September 21, 2016

Thanks Ravi!  I was looking for a call in the VirtualThing class, but as your code points out there is an InvokeService method available from the BaseClient class which is what I actually was looking for.  Thanks for your help!

-Chris

1-Visitor
September 21, 2016

You are welcome Chris.

Just little curious to know if you are following Java SDK or .Net SDK ? as the code was for Java SDK .