【问题标题】:How to Consume Webservice - NOT using wsimport - Using Dependency Injection如何使用 Web 服务 - 不使用 wsimport - 使用依赖注入
【发布时间】:2015-07-22 22:25:41
【问题描述】:

大家晚上好,

我想知道如何在不使用 WSIMPORT 和注入服务接口的情况下使用 Web 服务。

让我更具体地说明我在想做什么:

假设我们有项目:project-ws

如下导出接口和DTO

@WebService(targetNamespace = "http://namespace", name = "ServiceName")
public interface Webservice {
    
    @WebMethod
    public @WebResult List<DTOObject> method() throws WebServiceException;

}

假设是 DTO:

public class DTO {
   /*Attributes and DTO related stuff */
}

然后我想做的是导出一个带有接口和 DTO 类的 JAR,以便所有客户端都可以通过将这个“JAR-API”添加到类路径中来知道“接口的东西”,然后注入服务类然后 CDI 会以某种方式知道这是一个 Web 服务接口,并且每次调用它时都会将其转发到 Web 服务端点,然后再包装回我的调用堆栈。

我为什么要这样做?因为我厌倦了每次在 DTO 或 Web 服务界面中更改某些内容时,我必须在所有客户端项目中执行整个 WSIMPORT 工作,这会浪费大量时间!

我知道这是可能的,我曾在我曾经工作过的一个旧项目中看到过,该项目使用了 Spring,但我不知道如何使用 CDI 和 EJB3 来实现这一点。有可能吗?

非常感谢你们。 问候。

【问题讨论】:

    标签: java web-services dependency-injection ejb cdi


    【解决方案1】:

    经过几天的搜索,我自己弄清楚了。

    以下是我解决问题的方法:

    http://tomee.apache.org/examples-trunk/simple-webservice/README.html

    整个想法是用@Stateless 和@WebService 来注释Impl Endpoint 接口

    在客户端项目中,在单独的 JAR 文件或指向 Eclipse 文件夹的链接中公开接口和 DTO 后,请执行以下操作:

        Service calculatorService = Service.create(
                        new URL("http://127.0.0.1:4204/Calculator?wsdl"),
                        new QName("http://superbiz.org/wsdl", "CalculatorService"));
    
                CalculatorWs calculator = calculatorService.getPort(CalculatorWs.class);
    
    /*Use your methods Freely!!*/
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-24
      • 2013-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      • 2012-08-25
      相关资源
      最近更新 更多