18

From the client side, if I want to access a web service, I would simply generate a proxy for it using wsimport. That is my web service reference.

Where then does the annotation @WebServiceRef come into play? Is it meant to be used at the server side only, to obtain injected references to web services hosted in the same environment?

4

2 回答 2

20

不一定,但它确实取决于服务器实现。例如,要访问远程服务,它需要能够访问生成的客户端以及可选的 WSDL 文档和方案文件(按照惯例应该在 中WEB-INF/wsdl),这样

public class HelloServlet extends HttpServlet {

    @WebServiceRef(HelloMessengerService.class) // class with @WebServiceClient
    private HelloMessenger port; // the SEI

    ...
}

该类HelloMessengerService是存根并具有具有属性的@WebServiceClient注释 wsdlLocation(指向本地或远程 WSDL 文档)。

但你可以有类似的东西

@WebServiceRef(wsdlLocation = "META-INF/wsdl/AnyService/Any.wsdl")
private HelloMessengerService service;

或者

@WebServiceRef
public HelloMessengerService service;

如果您使用处理程序链来更改传入和传出的 SOAP 消息:

@WebServiceRef(HelloMessengerService.class)
@HandlerChain(file="handler-chain.xml")
private HelloMessenger port;

注释的使用@WebServiceRef必须应用于 JAX-WS 管理的客户端,如 Servlet、EJB 或其他 Web 服务。

于 2013-03-27T17:41:15.107 回答
5

只是为了补充 Paul Vargas 的回答,@WebServiceRef注释是一个工具,用于完成 Java EE 平台向完全托管环境的演变。这样想:

Almost every component within the Java EE stack is injectable by some means, EJBs, JSF managed beans, CDI beans, @Resources etc. Why not be able to inject a webservice reference? With the ability to inject a webservice reference using this annotation, the following are ready injection targets:

  • EJBs
  • Servlets (under Servlet 3.0)
  • JSF Managed Beans
  • CDI Beans
  • MDBs
于 2013-03-28T03:10:07.497 回答