Show TOC Start of Content Area

Procedure documentation Consuming TU&C/C Web Services  Locate the document in its SAP Library structure

Use

You want to create a Web service client that interacts reliably with a Web service over the TU&C/C protocol (Tentative Update & Compensate/Confirm).

If you want to consume a TU&C/C Web service, you have to generate a Web service proxy based on a WSDL document and then implement a client application which uses this proxy to call the TU&C/C Web service.

You can generate the proxy based on the WSDL document of a TU&C/C Web service. You can use the WSDL document of a Service Interface modeled in the ESR with the interface pattern TUCC. More information about interface patterns: Enterprise Services Repository for SAP NetWeaver CE Developer's Guide Enterprise Services Repository Defining Design Objects for Specifying Applications Defining the Service Structure with Interface Objects Developing Service Interfaces Interface Pattern.

Caution

This option requires the Enterprise Services Repository for SAP NetWeaver Composition Environment to be installed in your system landscape.

More information about providing TU&C/C Web services: Providing TU&C/C Web Services.

When you create a Web service client application, you have to use methods of the WS-RM API provided by the application server in conjunction with the compensate and confirm methods in the client application.

Procedure

       1.      Generate a Web service proxy. More information: Creating Web Service Proxies.

       2.      Create a client application. More information: Creating Web Service Client Applications.

The code sample below shows the implementation of a client application which uses the WS-RM API to make TU&C/C calls to a Web service.

You import the TU&C/C class from the WS-RM API on the application server by using the import clause import com.sap.engine.services.wsrm.api.interfaces.common.TUCC.

You have to use the TUCC.markNextCallAsCompensate() method from the WS-RM API to mark that the next call to the Web service is made by the compensate method. Next, you have to use the TUCC.markNextCallAsConfirm() method to mark that the next call to the Web service is the CONFIRM method.

Syntax

package com.sap.tucc;

 

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.xml.ws.WebServiceRef;

 

import com.sap.engine.services.wsrm.api.interfaces.common.TUCC;

 

/**

 * Servlet implementation class for Servlet: TuccExampleServ

 *

 */

 public class TuccExampleServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {

   static final long serialVersionUID = 1L;

   @WebServiceRef(name="TUCC_example_client")

   TuccExampleService client;

 

   public TuccExampleServlet() {

      super();

   }    

  

   protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

      try {

           TuccExample tucc = client.getTuccExampleBeanPort();

          

           //Mark that the next method is the COMPENSATE method

           TUCC.markNextCallAsCompensate(tucc);

           tucc.compensate();

          

           tucc.update(3);

           tucc.update(6);

          

           tucc.getState();

           //Mark that the next method is the confirm method.

           //If confirm method is called, all updates are submitted

           //by the Web service.

           TUCC.markNextCallAsConfirm(tucc);

           tucc.confirm();

               

         Thread.sleep(10000);

         tucc.getState();

      } catch (Exception e) {

         e.printStackTrace(response.getWriter());

      }

   }    

  

   protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

   }            

}

When the Compensate method is called, the call is stored temporarily, it is not sent to the Web service. Then, each of the UPDATE methods is called. In the event of a system crash, for example, the call from the COMPENSATE method is sent to the provider, and the provider rolls back the changes made by the UPDATE methods. If the calls of all the UPDATE methods go through successfully, the CONFIRM method is called and the Web service submits all the changes by the UPDATE methods.

       3.      In the application-j2ee-engine.xml file of the EAR containing the Web service client, add a runtime reference to the WS-RM application on the application server as shown in the code sample below:

Syntax

<?xml version="1.0" encoding="UTF-8"?>

<application-j2ee-engine xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="application-j2ee-engine.xsd">

  <reference reference-type="hard">

    <reference-target target-type="application" provider-name="sap.com">tc~esi~esp~wsrm~app</reference-target>

  </reference>

</application-j2ee-engine>

 

 

End of Content Area