1.//不用通过wsdl生成类来调用ws,采用发送soap包的方式,动态调用,很方便 2.import org.apache.cxf.endpoint.Client; 3.import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicclientFactory; 4.import org.springframework.context.support.ClasspathXmlApplicationContext; 5.public class TestMain { 6. 7. public static void main(String[] args) { 8. String xmlInput = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><request><operateType>query </operateType><dbType>sqlserver</dbType><orderBy></orderBy><userId>1</userId> <start>0</start><limit>20</limit><processName></processName></request>"; 9. JaxWsDynamicclientFactory dcf = JaxWsDynamicclientFactory.newInstance(); 10. String wsUrl = "地址" 11. String method = "findAllUser"; 12. Client client = dcf.createClient(wsUrl); 13. Object[] res = null; 14. try { 15. res = client.invoke(method,xmlInput); 16. } catch (Exception e) { 17. e.printstacktrace(); 18. } 19. System.exit(0); 20. } 21.} 2,生成客户端代码方式 这种适用cxf wsimport -keep -d D:/ -p ok http://127.0.0.1/Service.asmx?WSDL import java.util.List; import ok.ServiceSoap; import org.apache.cxf.jaxws.JaxWsProxyfactorybean; import org.springframework.beans.factory.annotation.Autowired; import com.ces.xarch.core.web.struts2.StringIDDefineserviceDaoController; import com.ces.zwww.dao.MacRoomDao; import com.ces.zwww.entity.MacRoom; import com.ces.zwww.service.MacRoomService; public static List<MacRoom> saveMac(){ //http://127.0.0.1/Service.asmx String xml ; try { JaxWsProxyfactorybean factory1 = new JaxWsProxyfactorybean(); factory1.setServiceClass(ServiceSoap.class); factory1.setAddress("http://127.0.0.1/Service.asmx?wsdl"); ServiceSoap u = (ServiceSoap) factory1.create(); xml= u.getAllMachineRooms(); System.out.println(xml); } catch (Exception e) { // Todo: handle exception e.printstacktrace(); } // return this.getService().saveMac(xml); return null; } 用Eclipse生成的如果不是cxf类型是anxi是调用不了的,要用anxi调用
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。