Service bindings

If the purpose of a resource binding is service access, the definition is called a service binding. The main detail is in one of three categories:

Defining a service binding in the EGL deployment descriptor

At this writing, you can bind to a REST or EGL REST-RPC service. The distinctions among the service types are explained here: Service-oriented architecture (SOA) for EGL developers (http://www.eclipse.org/edt/papers/topics/egl_soa_overview.html).

For details on defining a service binding in the EGL deployment descriptor, see Adding a REST binding to the EGL deployment descriptor.

If you are defining a workspace binding, you must also deploy the Service type. For details, see Adding web-service deployment details to the EGL deployment descriptor.

Retrieving a service binding and changing it in your code

Here is an example of preparing a binding variable and then using it to access a third-party REST service:
myBindingVar HttpRest{@Resource{uri="binding:myEntry"}};        
myBindingVar.request.encoding = encoding.json;
myBindingVar.request.headers = new dictionary;
myBindingVar.request.headers["edt.proxy.invocation.timeout"] = 6;
call MyInterfaceType.myFunction() 
   using myBindingVar
   returning to myCallBackFunction
   onException myExceptionHandler;
The code acts as follows:
  1. Declares a binding variable that refers to the myEntry entry in the deployment descriptor that is used by default. In this way, the code is accessing a new instance of an HttpRest object.

    For details on the HttpRest object, see eglx.http package.

  2. Adds detail to the binding variable, in this example, the detail has the following purpose:
    • To ensure that data is transferred to and from the service in JSON format; and
    • To establish a timeout value of 6 seconds.
  3. Includes the binding variable in the call statement using clause.

Creating a service binding in your code

You can create a service binding in your code, in which case the EGL deployment descriptor is not involved. For example, you might declare the binding variable as shown in the next example:
myBindingVar HttpRest = new HttpRest{
   restType = eglx.rest.ServiceType.TrueRest, 
   uri = "www.example.com/myproject/restservices/weather_service"};
myBindingVar.request.encoding = Encoding.json;
call MyInterfaceType.myFunction() 
   using myBindingVar
   returning to myCallBackFunction
   onException myExceptionHandler;

For details on the HttpRest object, see eglx.http package.