簡體   English   中英

生成Web服務的Wsdl /客戶端存根

[英]Generate Wsdl/Client Stubs For Web Service

我一直在閱讀有關使用Java,Eclipse等進行Web服務編程的內容,並且發現了一個特定的示例,該人員通過執行以下操作來創建Web服務和客戶端:

  1. 定義Web服務Java類(接口+ impl)
  2. 使用Endpoint.publish 部署 Web服務
  3. 從Web服務的URL中獲取wsdl (例如localhost:// greeting?wsdl)
  4. 使用wsimport生成存根
  5. 使用生成的存根創建客戶端類

是否有另一種無需發布Web服務並下載就可以生成wsdl的方法? 也許是一個Maven插件來自動生成wsdl和客戶端存根?

更新 :我不會提一個新問題,而只是just帶這個問題。

我通過定義接口創建了Web服務:

@WebService
public interface HelloWorldWs {
    @WebMethod
    public String sayHello(String name);
}

和一個impl類:

@WebService(endpointInterface = "com.me.helloworldws.HelloWorldWs")
public class HelloWorldWsImpl implements HelloWorldWs {
    @Override
    @WebMethod
    public String sayHello(String name) {
        return "Hello World Ws, " + name;
    }
}

當我運行wsgen時 ,出現以下錯誤:

The @javax.jws.WebMethod annotation cannot be used in with @javax.jws.WebService.endpointInterface element.

Eclipse似乎還可以。

知道為什么嗎?

注意,我最初沒有注釋,但是當我嘗試調用Web服務時,出現以下錯誤:

com.me.helloworldws.HelloWorldWsImpl is not an interface

JSR 224在3.1節中說:

SEI是滿足以下所有條件的Java接口:

  • 它的任何方法都可以帶有javax.jws.WebMethod注釋(參見7.11.2)。
  • 如果使用javax.jws.WebMethod ,則必須將exclude元素設置為true

如果實現類包括javax.jws.WebMethod ,則根據規范,您不能放置@WebMethod(exclude=true)而這不可能。

取決於Eclipse的定制版本,為此顯示了警告。 例如,用於Websphere的Rational Application Developer顯示:

JSR-181, 3.1: WebMethod cannot be used with the endpointInterface 
              property of WebService

通常,在使用一個高級IDE編程/構建項目時,您應該能夠在自動生成的東西之間找到它-IDE應該會生成它。 只是仔細檢查。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM