Show TOC

Configuring Stateful CommunicationLocate this document in the navigation structure

Use

A Web service which supports stateful communication (a stateful Web service) preserves its state across multiple calls from the same Web service client made in the same HTTP session.

By default, all Web services you create are stateless. If you want to enable stateful communication for a Web service, you have to explicitly set this in the implementation bean. You can also specify the method for session handling which enables this stateful communication. Currently, only HTTP cookies are used as the mechanism for stateful session handling.

Note

You can use a both stateful and stateless session Enterprise Java Bean endpoints to provide a stateful Web service.

Prerequisites

The Web service implementation bean is available.

Procedure

You enable stateful communication for a Web service by using the class level design time annotation @SessionHandlingDT(enableSession=true) as shown in the code sample below.

            package com.sap.example;

import javax.ejb.Stateless;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import com.sap.engine.services.webservices.espbase.configuration.ann.dt.SessionHandlingDT

@WebService(name="MyStatefulImplementationClass", serviceName="MyStatefulImplementationClassService",
         targetNamespace="http://sap.com/example/", portName="MyStatefulImplementationClassPort")
@Stateless
//Enable session handling for the whole class
@SessionHandlingDT(enableSession=true)

public class MyStatefulImplementationClass {
                @WebMethod(operationName="MyMethod1", exclude=false)
                public void MyMethod1 (@WebParam(name="newValue1")
                int newValue1)
                {
                        //MyMethod1 implementation      
                }
                @WebMethod(exclude=false, operationName="MyMethod2")
                public int MyMethod2 (@WebParam(name="arg")
                int arg)
                {
                        return arg;
                }
}

         

When you have enabled a Web service as stateful, you can set the method of session handling in the SAP NetWeaver Administrator. Currently, only HTTP cookies are supported.

More information about configuration from the SAP NetWeaver Administrator: Configuring Web Services and Web Service Clients in the SAP NetWeaver Administrator . More information about configuring individual Web services (single configuration): Configuring Individual Web Services . More information about configuring groups of Web services (mass configuration): Configuring Groups of Web Services .