cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Run a local service from SDK

SOLVED
Highlighted
Level 1

Run a local service from SDK

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?

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Run a local service from SDK

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. )

11 REPLIES 11

Re: Run a local service from SDK

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

Re: Run a local service from SDK

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

Re: Run a local service from SDK

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. )

Re: Run a local service from SDK

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

Re: Run a local service from SDK

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 .

Re: Run a local service from SDK

I am using .Net SDK.

Thanks!

Re: Run a local service from SDK

Hi Ravi!

This is Liwei. Hope all is well!

I'm currently working in Java SDK too and I'm very interesting in the code documentation of Calling service from EMS, if it is not too much trouble, may I ask for this documentation?

Thank you very much!

Best

Liwei

Re: Run a local service from SDK

Re: Run a local service from SDK

Hi Sushant,

Thank you so much for such quick reply!

Actually I'm more looking for guide of using Java SDK, especially how to call a Thing service from java app(Java sdk guide didn't provide much info about this part), it is my bad that i misused  "EMS".

Still thank you for your help!

Best

Liwei