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

How to invoke Async service under thing in ThingWorx extension code.

SOLVED
Highlighted
Regular Member

How to invoke Async service under thing in ThingWorx extension code.

Hi,

 

I would like to understand how to make the Async call to ThingWorx Service under the Thing and get the results.
We are using the ThingWorx extension which contains the Thing which has the service.
Currently the service is sync service, we use the Thing API processServiceRequest to invoke the service using extension code and get the results which is working fine.


Sample code :

Thing thing = (Thing) ThingUtilities.findThing("ThingName");
InfoTable result = thing.processServiceRequest("serviceName", params);

 

As this service is called multiple time from extension code in loop and the service is sync service we need to wait till service execution to complete before making another call.
To improve the performance we are willing the make the Thing service Async which can be achieved by making the service Async feature.
Now as we have make the service async whenever we invoke the service using API "processServiceRequest" it is invoked Asynchronously and the control goes further. Hence, we do not get the any results.

Can anyone let us know how we can handle this scenario how to catch the response from Async thing service?

 

Thanks,
Suraj.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: How to invoke Async service under thing in ThingWorx extension code.

@suhase ,

 

At the end of your service code, call a custom event (in the custom event's datashape, make sure you include a place to put your result).  When the async code completes, it should fire off that event, and you'll be able to subscribe to it.  In the subscription, you'll have access to the result.  Hope that helps!

View solution in original post

2 REPLIES 2
Highlighted

Re: How to invoke Async service under thing in ThingWorx extension code.

@suhase ,

 

At the end of your service code, call a custom event (in the custom event's datashape, make sure you include a place to put your result).  When the async code completes, it should fire off that event, and you'll be able to subscribe to it.  In the subscription, you'll have access to the result.  Hope that helps!

View solution in original post

Highlighted

Re: How to invoke Async service under thing in ThingWorx extension code.

Hi @suhase.

 

If you found the previous response helpful, please mark it as the Accepted Solution for the benefit of others with the same question.

 

Regards.

 

--Sharon

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum!