
In SAP NetWeaver Developer Studio, you have created a portal application and portal service with the Portal Application creation wizard.
For a portal service, the wizard creates a public interface (in the src.api folder) and private implementation class (in the src.core folder).
The following procedure assumes that you have created the following:
Portal Application: myApp
Portal Service:
Interface: ImyContextService
Implementation: myContextService
Generally, a portal service is not stateful, that is, it does not maintain information for the current page or user session. Each time an application asks for an instance of the service, the instance is not specific for the page or user session; the same instance may be used for many sessions and does not maintain information about the current session.
Regular vs. Contextual Portal Services
A regular portal service is defined by a portal application that contains the following:
Service Interface (public): Extends IService and defines custom methods.
Service Implementation (private): Implements the public service interface, which includes both IService and custom methods.
The portalapp.xml for the application defines the service by specifying a name for the service and the class to instantiate when the service is called, which is the service implementation.
An application asks for an instance of the service by providing a key, composed of the application name and the service name defined in the portalapp.xml . An instance of the service implementation is returned (exposed only as the interface), as shown below:

A contextual portal service maintains state information (or a context) for the life of the current portal user session.
A contextual portal service is defined by a portal application that contains the following:
Service Interface (public): Defines only custom methods (and does not extend IService ).
Service Implementation (private): Implements IService , as well as IServiceInstanceCreator .
Service Instance (private): Implements the public interface (and, therefore, the custom methods), as well as IServiceInstance .
Just like a regular service, the portalapp.xml for the application defines a service, a name for the service, and the class to instantiate for the service, which is the service implementation.
An application asks for an instance of the service by providing a key, composed of the application name and the service name defined in the portalapp.xml . An instance of the service instance is returned (exposed only as the interface), as shown below:

When a Web Dynpro application running in an iView in the portal calls for an instance of a contextual portal service, a new instance of the service is returned to the application. The next time the application requests an instance of the service, the same instance is returned.
A contextual portal service can only be called from a Web Dynpro application.