简体   繁体   English

为什么有状态的bean无法公开为Web服务?

[英]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: 我一直在阅读有关有状态和无状态会话Bean的信息,并遇到一句话:

Stateful session beans cannot be exposed as web services . 有状态会话Bean不能作为Web服务公开

Can anyone elaborate why ? 谁能详细说明为什么?

This is because, typically, state does not required to maintained across web service client calls. 这是因为通常不需要跨Web服务客户端调用维护状态。 Moreover, SOAP-based web services are inherently stateless in nature. 而且,基于SOAP的Web服务本质上本质上是无状态的。 If you need to maintain state across web service calls, stateless beans can be used to persist state (although this degrade application performance) 如果您需要在Web服务调用之间维护状态,则可以使用无状态Bean来保持状态(尽管这会降低应用程序性能)

Every Stateful bean instance located in the EJB Container has an unique object identity. 位于EJB容器中的每个有状态bean实例都有一个唯一的对象标识。

From spec.: 3.4.7.1 Stateful Session Beans 来自规范:3.4.7.1有状态会话Bean

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. 为了使用有状态bean,客户机代码需要从EJB容器获取有状态引用。 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. 由于引用对象知道与有状态Bean关联的身份,因此可以确保为同一实例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). SOAP协议没有提供一种允许在Web服务客户端中存储此身份的方法,因此,如果客户端不知道哪个有状态实例具有会话状态,则每个请求将由不同的ejb处理(例如无状态的情况下)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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