简体   繁体   English

无状态企业Bean中的Web服务客户端

[英]Web Service Client in a Stateless Enterprise Bean

What is the correct way to implement a stateless EJB 3.1 for invoking a web service. 实现无状态EJB 3.1来调用Web服务的正确方法是什么? My client works as a Servlet, but I want to move the invocation into a EEJ bean. 我的客户端充当Servlet,但是我想将调用移到EEJ bean中。 I have to add username and password in the SOAP header envelop to access the WS, which is working fine. 我必须在SOAP标头信封中添加用户名和密码才能访问WS,但工作正常。

The service the the servlet is using looks like this; servlet使用的服务如下所示;

@WebServiceClient(name = "MessageService", targetNamespace = "http://...", wsdlLocation = "...wsdl")
public class MessageService
    extends Service

Can I wrap MessageService in a Stateless EJB or should the bean itself use @WebServiceRef (as in the tutorial) without wrapping the MessageService ? 我可以将MessageService包装在无状态EJB中,还是bean本身应该使用@WebServiceRef (如本教程中所述)而不包装MessageService?

Tutorial 教程

Local Service 本地服务

If the client and the provider lives in same EAR or WAR on the application server, can be invoked like a ordinal EJB. 如果客户端提供者都位于应用程序服务器上的EAR或WAR中,则可以像顺序 EJB一样被调用。 eg 例如

@WebService
@Stateless
public class CalculatorBean implements Calculator {
    public int add(int a, int b) {
        return a + b;
    }
}

The CalculatorBean is threadsafe. CalculatorBean是线程安全的。 All business logic that occurs within the add method is part of a container-managed transaction and not participate in any global transaction. add方法内发生的所有业务逻辑都是容器管理的事务的一部分,并且不参与任何全局事务。

Alternatively, the client code can look up in the JNDI namespace. 另外,客户端代码可以在JNDI名称空间中查找。

Remote Service 远程服务

The runtime can inject a service object or a port object into a member variable annotated with javax.xml.ws.WebServiceRef . 运行时可以将服务对象或端口对象注入以javax.xml.ws.WebServiceRef注释的成员变量。

@WebServiceRef(CalculatorService.class)
private Calculator port;

The CalculatorService class is annotated with the javax.xml.ws.WebServiceClient annotation (the client of the service), which has a wsdlLocation attribute. CalculatorService类用javax.xml.ws.WebServiceClient注释(服务的客户端)注释,该注释具有wsdlLocation属性。


If you want to wrap the WebService into the EJB, see this answer . 如果要将WebService包装到EJB中,请参见此答案 For read a discussion about this, see EJB and Web Services: getting the best of both worlds . 要阅读有关此内容的讨论,请参阅EJB和Web服务:充分利用两者

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

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