私はWebサービスの世界の初心者です。プロデューサーとクライアントの両方で以下のWebサービスのJAX-WSを開発していたので、1つのクエリがありますが、注釈を使用していました。使用せずに同じプログラムを開発する方法を教えてください。 XMLを使用している注釈の..それ自体..
Webサービスエンドポイントインターフェイスを作成する
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloWorld{
@WebMethod String getHelloWorldAsString(String name);
}
Webサービスエンドポイント実装を作成する
import javax.jws.WebService;
//Service Implementation
@WebService(endpointInterface = "com.mkyong.ws.HelloWorld")
public class HelloWorldImpl implements HelloWorld{
@Override
public String getHelloWorldAsString(String name) {
return "Hello World JAX-WS " + name;
}
}
エンドポイントパブリッシャーを作成する
import javax.xml.ws.Endpoint;
import com.mkyong.ws.HelloWorldImpl;
//Endpoint publisher
public class HelloWorldPublisher{
public static void main(String[] args) {
Endpoint.publish("http://localhost:9999/ws/hello", new HelloWorldImpl());
}
}
Wsimportツールを介したJavaWebサービスクライアント
wsimport -keep http://localhost:9999/ws/hello?wsdl
提供されたwsdlファイルに依存する必要なクライアントファイルを生成します。この場合、1つのインターフェースと1つのサービス実装ファイルが生成されます。
最後に、生成されたスタブクラスを使用するメインクラス。
package com.mkyong.client;
import com.mkyong.ws.HelloWorld;
import com.mkyong.ws.HelloWorldImplService;
public class HelloWorldClient{
public static void main(String[] args) {
HelloWorldImplService helloService = new HelloWorldImplService();
HelloWorld hello = helloService.getHelloWorldImplPort();
System.out.println(hello.getHelloWorldAsString("mkyong"));
}
}