locked="false">account.AccountOper
9.打包要发布的Service,Eclipse中New-->File-->Other-->Axis2wizards-->
Axis2ServicesArchiver,按照向导选择刚建立的类编译后的class文件和services.xml文件。
1》、选择class文件目录,注意,不是java源文件,而是WEB-INF\classes目录,
2》、连按两次下一步,选择service.xml文件,
3》、按下一步,输入service文件的保存路径和文件名,完成。
这里将保存路径设为D盘,文件名为AccountService.jar,按完成保存成功,然后修改后缀为aar(也可不修改),将其拷贝到Tomcat5.5\webapps\axis2\WEB-INF\services目录下,重新打开http:
//127.0.0.1:
8080/axis2/services/listService就会发现AccountService已经发布成功,现在就可以应用这个Web服务了。
10.Eclipse中New-->File-->Other-->Axis2wizards-->Axis2CodeGenerator,按向导通过javasource文件,即AccoutOper.class生成WSDL文件。
1》选择GenerateaWSDLfromaJavasourcefile,按下一步
2》、填入class文件的包及文件名,我这是account.AccountOper,然后按AddFolder增加AccountOper.class的所在目录路径,按TestClassLoading..按钮测试是否成功装载这个类文件,若未装载成功请检查包名、类名和路径是否正确。
3》、按下一步,这里的参数设置我们不用管它,用默认的就行了。
4》、选择wsdl文件的保存位置及确定wsdl文件的文件名AcountServices.wsdl,按完成,WSDL文件生成成功。
11、通过WSDL文件生成AccountServiceCallbackHandler.java和AccountServiceStub.java,可以重新建立Project,我在做的过程中为了方便仍利用刚才建立的Project.
1》、New-->File-->Other-->Axis2wizards-->Axis2CodeGenerator
2》、选择GenerateJavasourcecodefromaWSDLfile,按下一步
3》、按Browse选择wsdl文件,按下一步
4》、使用默认的配置,按下一步。
5》、选择生成文件的存放路径,完成AccountServiceCallbackHandler.java和AccountServiceStub.java的生成。
6》、在工程目录按F5刷新,就可以看到刚生成的文件,但提示都有错误,这是因为包名不一样。
解决方法是将生成的两个文件直接移动到account包下,如图:
11.编写服务测试程序AccountTest.java如下:
packageaccount;
publicclassAccountTest{
publicstaticvoidmain(String[]args)throwsException{
//TODOAuto-generatedmethodstub
Stringendpoint= "http:
//localhost:
8080/axis2/services/AccountService";
AccountServiceStubstub=newAccountServiceStub(endpoint);
AccountServiceStub.SetAccountIDset=newAccountServiceStub.SetAccountID();
set.setId
(2);
stub.setAccountID(set);
AccountServiceStub.GetAccountResponseget=stub.getAccount();
System.out.println("Current:
"+get.get_return());
AccountServiceStub.Depositdep=newAccountServiceStub.Deposit();
dep.setMoney(120);
AccountServiceStub.DepositResponsedepRes=stub.deposit(dep);
System.out.println("AfterDeposit120:
"+depRes.get_return());
AccountServiceStub.Withdrawdraw=newAccountServiceStub.Withdraw();
draw.setMoney(50);
AccountServiceStub.WithdrawResponsedrawRes=stub.withdraw(draw);
System.out.println("AfterWithdraw50:
"+drawRes.get_return());
AccountServiceStub.GetAccountResponsegetLast=stub.getAccount();
System.err.println("Atlast:
"+getLast.get_return());
}
}
运行结果如下:
测试成功
官方文檔非常多及齊全,若想進一步了解,需要花更長的時間:
http:
//ws.apache.org/axis2/1_0/index.html
Axis2的文檔及教學非常充足.官方文檔如下連結:
http:
//ws.apache.org/axis2/1_0/index.html
Axis2官方的安裝教學:
http:
//ws.apache.org/axis2/1_0/installationguide.html
Axis2用戶指南:
http:
//ws.apache.org/axis2/1_0/userguide.html
Axis2WEBAdministration介面的使用教學:
http:
//ws.apache.org/axis2/1_0/webadminguide.html
Axis2的設定文檔:
http:
//ws.apache.org/axis2/1_0/axis2config.html
AXIOM(AxisObjectModel)教學:
http:
//ws.apache.org/axis2/1_0/OMTutorial.html
Axis2Eclipseplugin教學:
http:
//ws.apache.org/axis2/tools/1_0/eclipse/wsdl2java-plugin.html