WebService是一种跨编程语言和跨操作系统平台的远程调用技术。
XML+XSD, SOAP 和 WSDL 是构成WebService平台的三大技术。
SOAP = HTTP协议 + XML数据格式
一条SOAP消息就是一个普通的XML文档
入门文档介绍:
http://blog.csdn.net/wooshn/article/details/8069087/
http://blog.csdn.net/WOOSHN/article/details/8145763
参考示例:
http://www.cnblogs.com/coshaho/p/5105364.html
几种方式:
1.使用命令cxf构建WebService客户端:
客户端:
JaxWsProxyFactoryBean svr = new JaxWsProxyFactoryBean();
svr.setServiceClass(HelloWoldClientServiceI.class);
svr.setAddress("http://localhost:8080/Service/ServiceHello");
HelloWoldClientServiceI serviceHello = (HelloWoldClientServiceI) svr.create();
System.out.println(serviceHello.getValue("Hello hahahahahaha"));
或者 JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
String wsdlUrl = "http://localhost:8080/Service/ServiceHello?wsdl";
Client client = clientFactory.createClient(wsdlUrl);
Object[] result = client.invoke("getValue", "Hello web service");
System.out.println(result[0]);
服务端:
JaxWsServerFactoryBean factoryBean = new JaxWsServerFactoryBean(); // Web服务的地址
factoryBean.setAddress("http://localhost:8081/hello"); // Web服务对象调用接口
factoryBean.setServiceClass(HelloWorldServiceImpl.class);
Server server = factoryBean.create();
server.start();
2.使用命令wsimport构建WebService客户端
http://www.cnblogs.com/yisheng163/p/4524808.html
JaxWsProxyFactoryBean 与 JaxWsDynamicClientFactory
1、 JaxWsProxyFactoryBean
- public class Client {
- public static void main(String[] args) {
- JaxWsProxyFactoryBean bean = new JaxWsProxyFactoryBean();
- bean.setServiceClass(HelloWorldService.class);
- bean.setAddress("http://localhost:9090/helloWorldService");
- HelloWorldService helloWorldService = (HelloWorldService)bean.create();
- String result = helloWorldService.sayHello("Kevin");
- System.out.println(result);
- }
- public class Client3 {
- public static void main(String[] args) throws Exception {
- JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
- Client client = clientFactory.createClient("http://localhost:9090/helloWorldService?wsdl");
- Object[] result = client.invoke("sayHello", "KEVIN");
- System.out.println(result[0]);
- }
- }
用JaxWsServerFactoryBean发布,需要独立的jetty包。