ThingWorx Edge Java SDK > Working with Things > Services
  
Services
In the ThingWorx environment, all things have services (functions) and property values. Property values are manipulated through service calls. There are generic services for all things, such as GetPropertyValues(), GetStringPropertyValue(), and SetPropertyValues(). These services are provided automatically on all things and provide the basic functionality needed to manage and manipulate properties.
There are two kinds of services:
"Local" services that execute on the thing (on the platform)
"Remote" services that execute on your device
Both types of services are invoked in the same way, but only custom remove services need to be registered on the edge (within your application).
A virtual thing can define services and make those services available to be executed from the ThingWorx platform. Since the AlwaysOn connection enables bi-directional communication, the ThingWorx platform can invoke these services on demand.
Defining a Service on a VirtualThing
A service on a VirtualThing is simply a method with the proper ThingWorx annotation applied to it. For example, take a simple method that adds two numbers:
public Double Add(Double p1, Double p2) throws Exception {
return p1 + p2;
}
Using annotations, you can expose this method as a remote service. The annotation includes the name of the ThingWorx platform, the name and base types for the parameters of the service, and the base type of the result.:
// The following annotation allows you to make a method available to the
// ThingWorx platform for remote invocation. The annotation incluides the
// name of the server, the name and base types for its parameters, and
// the base type of its result.

@ThingworxServiceDefinition(name="Add", description="Add two numbers")
@ThingworxServiceResult(name="result", description="The sum", baseType="NUMBER")
public Double Add(
@ThingworxServiceParameter(name="p1", description="First param", baseType="NUMBER" ) Double p1,
@ThingworxServiceParameter(name="p2", description="Second param", baseType="NUMBER" ) Double p2) throws Exception {

return p1 + p2;
}
* 
If your VirtualThing uses annotations to define properties, services, or events, call this.initializeFromAnnotations() (shown below). If you do not call this method, the annotations are NOT applied to your thing.
public SimpleThing(String name, String description, ConnectedThingClient client) {
super(name, description, client);
this.initializeFromAnnotations();
}
Now, run the application:
1. Log in to ThingWorx Composer. If you have imported the ExampleExport.xml file, browse to Simple1.
2. Select the Properties tab. Here, you should see the isConnected property set to true, indicating that the connection was successful.
3. Browse to the Services tab.
4. At the top, select Browse Remote Services. Under Available Services, you should see the Add service..
5. Click the arrow to the right of the service name to place it in the list of services to be added to Simple1
6. Select Create Services. The new Add service now appears in the list of services for Simple1.
7. At the top of the screen, click Save to save the change.
You can now test the Add service.
8. Click Test
9. When prompted for the p1 and p2 parameters, type in the values you want to add for this test
10. Click Execute Service. This action causes the ThingWorx platform to send a message, over the AlwaysOn connection, to the VirtualThing in the client application. The SDK then invokes the Add method and returns a result.
* 
If the service fails, make sure you saved Simple1 after adding the new service.
Using this mechanism, the remote application can expose complex functionality to the ThingWorx platform. In addition, the ThingWorx platform can invoke these services based on user input, system events, property changes, or calls from its other services.