Webサービスを利用するWebサービスクライアントの実装クラスを作成します。
Webサービスに対して1回の呼び出しをするWebサービスクライアントの作成例を次に示します。
package com.sample.client;
import java.io.File;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import com.sample.UserInfoImpl;
import com.sample.UserData;
import com.sample.UserInfoService;
import com.sample.UserInfoException_Exception;
public class TestClient {
public static void main( String[] args ) {
try {
//DataHandlerオブジェクト生成
File imagefile = new File("image.jpg");
FileDataSource fdSource = new FileDataSource(imagefile);
DataHandler dhandler = new DataHandler(fdSource);
UserInfoService service = new UserInfoService();
UserInfoImpl_port = service.getUserInfoImplPort();
UserData userdata = port.getUserData( "1", dhandler );
System.out.print( "[RESULT] " + userdata.getMessage() );
System.out.println( " Name:" + userdata.getName()
+ ", Section:" + userdata.getSection() );
}
catch( UserInfoException_Exception e ){
e.printStackTrace();
}
catch( Exception e ){
e.printStackTrace();
}
}
} |
作成したTestClient.javaは,UTF-8形式でc:¥temp¥jaxws¥works¥attachments¥client¥src¥com¥sample¥client¥ディレクトリに保存します。