Consuming A Stateful Web Service
Use
The interface patterns stateless (XI 3.0 compatible), stateless, stateful, and TU&C/C assign the type of communication to be performed for each service interface. Stateful communication means that the messaging runtime supports the saving of a status at the provider once the messaging runtime has completed the message exchange successfully.
This interface pattern is only needed for a few special technical scenarios. It does not guarantee a common update of data at the receiver.
You cannot use this interface pattern for enhanced communication using the Integration Server. Only synchronous stateful communication is supported.
Prerequisites
-
You have generated a proxy. Refer also to Generating a Consumer Proxy
-
You have configured the consumer proxy.
For more information, refer to the section Configuring a Consumer Proxy.
-
The role SAP_BC_WEBSERVICE_CONSUMER was assigned to the user master data of the user that processes the call at the provider(refer to Authorizations). The user at the provider depends on the logon settings of the provider endpoint and/or of the configuration of the consumer proxy. Either the user at the consumer is passed to the provider, a generic user as specified in the consumer proxy configuration is used, or a generic user as specified at the provider endpoint is used.
Calling a Synchronous Service from an Application
Proceed as follows. In this example, the service has two stateful operations.
-
Instantiate the proxy class.
DATA: lv_<client proxy name> TYPE REF TO <client proxy name>.
CREATE OBJECT lv_<client proxy name>
EXPORTING
LOGICAL_PORT_NAME =
The logical port must be specified if no standard port has been agreed upon.
-
Fill in the query data structure.
DATA: lv_<request data> TYPE <request data1>,
lv_<response data> TYPE <response data1>,
lv_<request data2> TYPE <request data2>,
lv_<response data2> TYPE <response data2>.
-
Call the stateful service operations.
CALL METHOD lv_<client proxy name>-><name of method1 / operation1>
EXPORTING
INPUT = lv_<request data1>
IMPORTING
OUTPUT = lv_<response data1>
CALL METHOD lv_<client proxy name>-><name of method2 / operation2>EXPORTING
INPUT = lv_<request data2>
IMPORTING
OUTPUT = lv_<response data2>
-
Wrap the proxy instantiation and the web service call into a TRY – CATCH block and perform error handling.
TRY.
... CATCH cx_ai_system_fault INTO DATA(lx_ai_system_fault).
<process error>
CATCH <application error> INTO DATA(lx_<application_error>)
<process error>
ENDTRY
-
Evaluate the received data.
<process the data>
-
Free the session at the provider (this is important to allow the provider to release the resources that are bound to the session):
DATA lo_session_protocol TYPE REF TO if_wsprotocol_session. lo_session_protocol ?= lv_<client proxy name>->get_protocol( if_wsprotocol=>session ).lo_session_protocol->disable_session( ).
The runtime supports protocols for more specialised services. For more information, see Protocols.