File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Architect Certification (SCEA/OCMJEA) and the fly likes Stateful Session Beans CAN be used as web services Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Architect Certification (SCEA/OCMJEA)
Bookmark "Stateful Session Beans CAN be used as web services" Watch "Stateful Session Beans CAN be used as web services" New topic

Stateful Session Beans CAN be used as web services

Allexicus Kernikus
Ranch Hand

Joined: Oct 07, 2009
Posts: 42
As much as I know stateful session beans CAN be exposed as web services (just add the @WebService annotationand you are ready to go).

Why does the SCEA literature suggest otherwise?
Tirumal Reddy Moolamalla

Joined: Apr 07, 2009
Posts: 8
I think we can expose EJB3 Stateless Session Bean as WS otherwise we can simply expose POJO as WS. This depends on the requirements. If our requirements demands using of EJB's then exposing EJB3 Stateless Session Bean as WS is fine. otherwise we will be misusing EJB, where we can acheive it using simple POJO based WS.

correct me if i am wrong.
Rishi Shehrawat
Ranch Hand

Joined: Aug 11, 2010
Posts: 218

Typically state is not required to be maintained across two web service calls, so it does not make sense to use stateful session bean.
P Das
Ranch Hand

Joined: Jun 30, 2008
Posts: 123
Looks like stateless EJBs (and POJOs) only can be made into web services. However, sometimes, you might need to maintain conversational states between multiple calls to the web service by more than one client, when the "flyweight" that stateless EJBs are falls short. Are you faced with such dilemma?

The choice between POJOs and stateless EJBs may depend on cross-cutting concerns such as performance (pooling), security, etc. and how much leverage you might gain through the inbuilt plumbing of EJB servers.

However, if you need stateless EJBs and conversational state, together, you might consider designing a custom state machine.

Pranab Das, PMP, SCEA
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

I think, stateful session beans cannot be used in web services. [A stateful session bean cannot have a web service endpoint interface. This is because SOAP-based web services are inherently stateless in nature.]

|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
I agree. Here's the link:
subject: Stateful Session Beans CAN be used as web services
It's not a secret anymore!