//不用通过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]);
}
更多资料:
CXF学习笔记(1)-HelloWorld!-发布webservice
CXF学习笔记(2)-HelloWorld!-客户端调用
CXF学习笔记(3)-HelloWorld!-通过servlet发布webservice
CXF学习笔记(4)-HelloWorld!-安全认证
.
.
.