//不用經過wsdl生成類來調用ws,採用發送soap包的方式,動態調用,很方便 import org.apache.cxf.endpoint.Client; import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory; public class TestMain { public static void main(String[] args) { 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>"; JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); String wsUrl = "地址"; String method = "findAllUser"; Client client = dcf.createClient(wsUrl); Object[] res = null; try { res = client.invoke(method, xmlInput); } catch (Exception e) { e.printStackTrace(); } System.exit(0); } }
@Test public void testWs() { JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setAddress("http://127.0.0.1:8080/xxx/webservice/info"); factory.setServiceClass(cn.net.xxx.webservice.InfoWebserviceI.class); boolean delete = ((cn.net.xxx.webservice.InfoWebserviceI) factory.create()).delete("5555555"); System.out.println("TestWs:" + delete); } @Test public void testWss() throws Exception { // 不依賴服務器端接口來完成調用的,也就是不單單能調用Java的接口 JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance(); Client client = clientFactory.createClient("http://127.0.0.1:8080/xxx/webservice/helloworld?wsdl"); Object[] result = client.invoke("sayHello2", "張莉"); System.out.println(result[0]); }
更多資料:java
CXF學習筆記(1)-HelloWorld!-發佈webservice
CXF學習筆記(2)-HelloWorld!-客戶端調用
CXF學習筆記(3)-HelloWorld!-經過servlet發佈webservice
CXF學習筆記(4)-HelloWorld!-安全認證sql
CXF安全認證apache
.安全
.服務器
.sqlserver