Invoking a service synchronously from outside of Rich UI

Service invocation outside of Rich UI is always synchronous, which means that the requester waits for a response from the service.

Here is the syntax of the service-access statement:
returnValueVariable = serviceName.operationName(argumentList) {timeout = milliseconds};
returnValueVariable
The name of a variable that receives the return value
serviceName
The name of a variable that is based on an Interface or Service part
operationName
The name of the Interface part function prototype.
argumentList
A list of arguments, each of which is separated from the next by a comma

For restrictions on arguments, see “Restrictions in the prototypes used for service access.”

milliseconds
The maximum valid number of milliseconds that elapse between when the EGL runtime code invokes a web service and when the EGL runtime code receives a response. If more time elapses, the EGL runtime code throws a ServiceInvocationException. However, this setting has no effect in EGL-generated COBOL code.
To set a timeout:
  • Consider various factors, such as local network traffic, internet traffic, and server response time. Those factors mean that two invocations of the same service are likely to take a different amount of time under different conditions.
  • Consider the nature of your application. If your code is waiting for a credit approval, you might set a high timeout value to avoid charging the user twice. If your code is making a bid in an online auction, you might set a low timeout value so that the user can make another bid quickly.
  • Use timeout values that vary from one another by one or more seconds.

You can set a default value for milliseconds in the defaultServiceTimeout build descriptor option. The defaultServiceTimeout build descriptor option has no default value set. If you do not specify a value for either defaultServiceTimeout or for milliseconds, the service call will not time out. For more information, see “defaultServiceTimeout.”

try blocks

Use a try block to test for an Exception record of type AnyException:

try 
   myString = myService.myOperation(1);
   onException (except AnyException)
   case 
      when (exp isa ServiceBindingException)
         ;
      when (exp isa ServiceInvocationException)
         ;
      otherwise
         ; 
   end
end
Errors might occur in these places:
  • In a service binding; that is, in how the service access is specified in your code. This error might involve a problem in the deployment descriptor.
  • In the communication of the requester with the service
  • In the service

A problem in a service binding results in a ServiceBindingException. Other problems result in a ServiceInvocationException or a RuntimeException, which is less likely.