上一篇已成功发布接口,现在来测试客户端是否可以访问.
我也是在网上各种查的结果走了很多弯路,做出来了也不是很明白,等着经理讲呢
一开始我是在WebServiceServer端的项目里直接建的测试类..这样其实也可以测试,但是很不规范
1 package com.report.client; 2 3 import java.net.MalformedURLException; 4 5 import org.codehaus.xfire.XFireFactory; 6 import org.codehaus.xfire.client.XFireProxyFactory; 7 import org.codehaus.xfire.service.Service; 8 import org.codehaus.xfire.service.binding.ObjectServiceFactory; 9 10 import com.report.model.Report; 11 import com.report.service.ReportServiceHibernate; 12 13 public class ReportServiceInsert 14 { 15 public static void main(String[] args) 16 { 17 Service srvcModel = new ObjectServiceFactory().create(ReportServiceHibernate.class); 18 XFireProxyFactory factory = new XFireProxyFactory(XFireFactory.newInstance() 19 .getXFire()); 20 21 String URL = "http://127.0.0.1:8080/ExtWS/service/ReportServiceHibernate"; 22 try 23 { 24 ReportServiceHibernate service = (ReportServiceHibernate) factory.create(srvcModel,URL); 25 26 Report report = new Report("1" , "1" , "1" , "1"); 27 28 service.insert(report); 29 30 } 31 catch (MalformedURLException e) 32 { 33 e.printStackTrace(); 34 } 35 } 36 }
这样可以测试成功
规范的步骤应该是:
1.建立新java project(ExtClient),导入XFire1.2 Core Libraries和XFire1.2 Http Client Libraries
2.将com.report.model/form/service层考进来(service只考interface就行了, form类不要继承ActionForm)
3.新建com.report.client包将刚才的测试类考进来就OK了.
这里只提供了流程,具体意义还需要研究