Axsi2Client端sub方式访问

1)解压axis2的bin压缩包,在bin目录下找到wsdl2java.bat文件
2)在当前目录下,新建bat文件,文件内容是:
wsdl2java -uri http://10.0.10.209:9000/platform/services/BookService?wsdl -p client -s -o stub
3)运行bat文件,生成stub客户端
public class StubNormal {
	public static void main(String[] args) throws AxisFault {
		// 初始化Sub类
		BookServiceStub stub = new BookServiceStub();
		try {
			// 取得返回值
			BookServiceStub.Find find = new BookServiceStub.Find();
			Integer faa = stub.find(find).get_return();
			System.out.println(faa + "=========");
			
			// 传递AxisServiceStub.ShowName对象,相关参数在这边赋值。
			BookServiceStub.Ooooo command = new BookServiceStub.Ooooo();
			command.setIsbn("Hello!");

			String aa = stub.ooooo(command).get_return();
			System.out.println(aa + "=========");
            
			BookServiceStub.FindBook fbook = new BookServiceStub.FindBook ();
			BookServiceStub.Book b = new BookServiceStub.Book();
			b.setName("This is book!");
	        b.setISBN("1234-2234-3234-4234");
			fbook.setBook(b);
			
			BookServiceStub.Book  rebook =stub.findBook(fbook).get_return();
			System.out.println(rebook.getISBN() + "========="+rebook.getName());
			
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}


2)初始化stub类,以BookServiceStub为例。BookServiceStub stub = new BookServiceStub();
3)根据参数设定不同分别调用方式
   ①若没有参数,则直接调用:Integer name = stub.find().get_return();其中:find()为方法名
   ②若传基本数据类型,则增加传递对象:
BookServiceStub.Find command = new BookServiceStub.Find();其中:Find为调用方法名
command.setIsbn("Hello!"); 参数在这赋值
     String aa = stub.Find(command).get_return();调用方法时把对象传入
   ③若传对象数据类型,则增加传递对象:
BookServiceStub.FindBook fbook = new BookServiceStub.FindBook ();其中:FindBook 为调用方法名
BookServiceStub.Book b = new BookServiceStub.Book();//客户端传入参数对象
       b.setName("托斯卡纳");//设置对象属性
       b.setISBN("1234-2234-3234-4234");
      fbook.setBook(b);//设置方法参数
      BookServiceStub.Book  rebook =stub.findBook(fbook).get_return();调用方法时把对象传入

你可能感兴趣的:(client)