简体   繁体   中英

Why can't stateful beans be exposed as webservices?

I have been reading about Stateful and Stateless session beans and came across a sentence that states that:

Stateful session beans cannot be exposed as web services .

Can anyone elaborate why ?

This is because, typically, state does not required to maintained across web service client calls. Moreover, SOAP-based web services are inherently stateless in nature. If you need to maintain state across web service calls, stateless beans can be used to persist state (although this degrade application performance)

Every Stateful bean instance located in the EJB Container has an unique object identity.

From spec.: 3.4.7.1 Stateful Session Beans

A stateful session object has a unique identity that is assigned by the container at the time the object is created.

In order to use a Stateful bean, the client code needs to get a Stateful reference from the EJB Container. This reference has to be used to make every future request. Due to the reference object knows the identity associated to the stateful bean, you can be sure that all requests that participate in the "conversation" will be resolved for the same instance bean. This means that the Client has an important role in achieving the stateful behavior.

The SOAP protocol doesn't provide a way that allow to store in a web service client this identity, therefore, if the client doesn't know which stateful instance has the conversational state, every request will be processed by different ejb (such as the case of stateless).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM