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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

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

suhase
5-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
nmilleson
17-Peridot
(To:suhase)

@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
nmilleson
17-Peridot
(To:suhase)

@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!

slangley
23-Emerald II
(To:suhase)

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

Top Tags