Use CXF to develop WebService server and client

The jar package required for development:

server-side code:
package com.cxf.ws.service;

import javax.jws.WebService;

@WebService
public interface HelloWorld {
	public String sayHello(String name);
}

package com.cxf.ws.service.impl;


import javax.jws.WebService;
import com.cxf.ws.service.HelloWorld;

@WebService(endpointInterface="com.cxf.ws.service.HelloWorld",serviceName="HelloWorldImpl")
public class HelloWorldImpl implements HelloWorld{
	@Override
	public String sayHello(String name) {
		return "hello,"+name+"!";
	}
}

package com.cxf.ws.app;

import javax.xml.ws.Endpoint;

import com.cxf.ws.service.HelloWorld;
import com.cxf.ws.service.impl.HelloWorldImpl;



public class Server {

	public static void main(String[] args) {
//		JaxWsServerFactoryBean factoryBean=new JaxWsServerFactoryBean();
//		factoryBean.setAddress("http://192.168.0.251:9999/CXF-WS-Server");
//		factoryBean.setServiceClass(HelloWorld.class);
//		factoryBean.setServiceBean(new HelloWorldImpl());
//		factoryBean.create();
		HelloWorld hw=new HelloWorldImpl();
		Endpoint.publish("http://192.168.0.251:9999/CXF-WS-Server", hw);
		System.out.println("Published successfully!");
	}

}


Configure wsdl2java environment:
path:D:\apache-cxf-2.5.8\bin
cmd Command:
switch directory to wsdl2java under src of client project
http://192.168.0.251:9999/CXF-WS-Server/HelloWorld?wsdl
Client code:
package com.cxf.ws.app;

import com.cxf.ws.service.HelloWorld;
import com.cxf.ws.service.impl.HelloWorldImpl;

public class Client {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		HelloWorldImpl fac=new HelloWorldImpl();
		HelloWorld hw=fac.getHelloWorldImplPort();
		String word=hw.sayHello("Jin Congmin");
		System.out.println(word);
	}

}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327071308&siteId=291194637