JAX-WS
Java6についたJAX-WSのメモ
サービスクラスを作成
package sample;
import javax.jws.WebService;
@WebService
public class Sample {
public int count(String str) {
return str.length();
}
}
サービススタブを生成
サーバー側で使用するスタブを生成する。以下をコマンドラインから実行
wsgen -cp . sample.Sample
サーバークラスを作成
import javax.xml.ws.Endpoint;
public class Server {
public static void main(String[] args) throws Exception {
Endpoint.publish("http://localhost:8090/sample", new Sample());
}
}
クライアントスタブを生成
クライアントが使用するスタブを生成する。以下をコマンドラインから実行
wsimport http://localhost:8090/sample?wsdl
クライアントクラスを作成
import sample.Sample;
import sample.SampleService;
public class Client {
public static void main(String[] args) throws Exception {
Sample smp = new SampleService().getSamplePort();
System.out.println(smp.count("hoge"));
}
}