1.sample 实例之一---java_first_pojo
服务端发布服务的方法:
客户度调用的方法:
//创建服务代理工程bean
ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
//设置服务代理地址
factory.setAddress("http://localhost:9000/Hello");
//创建代理服务
HelloWorld client = factory.create(HelloWorld.class);
//调用代理服务
System.out.println(client.sayHi(System.getProperty("user.name")));
2.sample实例之二---java_first_jaxws
服务端发布服务的方法:
HelloWorldImpl implementor = new HelloWorldImpl();
String address = "http://localhost:9000/helloWorld";
Endpoint.publish(address, implementor);
客户端调用的方法:
private static final QName SERVICE_NAME = new QName("http://server.hw.demo/", "HelloWorld");
private static final QName PORT_NAME = new QName("http://server.hw.demo/", "HelloWorldPort");
Service service = Service.create(SERVICE_NAME);
// Endpoint Address
String endpointAddress = "http://localhost:9000/helloWorld";
// If web service deployed on Tomcat deployment, endpoint should be changed to:
// String endpointAddress = "http://localhost:8080/java_first_jaxws/services/hello_world";
// Add a port to the Service
service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
HelloWorld hw = service.getPort(HelloWorld.class);
3. sample实例之---java_first_jaxws_factory_bean
服务端发布服务的方法:
private static final QName SERVICE_NAME = new QName("http://server.hw.demo/", "HelloWorld");
private static final QName PORT_NAME = new QName("http://server.hw.demo/", "HelloWorldPort");
Service service = Service.create(SERVICE_NAME);
// Endpoint Address
String endpointAddress = "http://localhost:9000/helloWorld";
// If web service deployed on Tomcat deployment, endpoint should be changed to:
// String endpointAddress = "http://localhost:8080/java_first_jaxws/services/hello_world";
// Add a port to the Service
service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
HelloWorld hw = service.getPort(HelloWorld.class);
客户端调用的方法:
HelloWorldImpl implementor = new HelloWorldImpl();
JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
svrFactory.setServiceClass(HelloWorld.class);
svrFactory.setAddress("http://localhost:9000/helloWorld");
svrFactory.setServiceBean(implementor);
svrFactory.getInInterceptors().add(new LoggingInInterceptor());
svrFactory.getOutInterceptors().add(new LoggingOutInterceptor());
svrFactory.create();
4.sample实例之一---java_first_spring_support
服务端发布服务
客户度调用服务:
ClassPathXmlApplicationContext context
= new ClassPathXmlApplicationContext(new String[] {"client-beans.xml"});
HelloWorld client = (HelloWorld)context.getBean("client");
String response = client.sayHi("Joe");
客户度调用小结
(引用http://blog.csdn.net/liaomin416100569/article/details/5503410)
UserServiceImplService serivce = new UserServiceImplService();
UserServiceImpl impl = serivce.getUserServiceImplPort();
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setAddress("http://localhost:8088/abc");
QName SERVICE = new QName("http://liaomin", "UserServiceImplService");
factory.setServiceName(SERVICE);
factory.setServiceClass(UserService.class);
UserService us = (UserService) factory.create();
QName SERVICE = new QName("http://liaomin", "UserServiceImplService");
QName UserServiceImplPort = new QName("http://liaomin", "UserServiceImplPort");
URL url = new URL("http://localhost:8088/abc?wsdl");
ServiceDelegate dele=Provider.provider().createServiceDelegate(url,SERVICE,Service.class);
UserService us = (UserService) dele.getPort(UserServiceImplPort,UserService.class);
ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
factory.setServiceClass(UserService.class);
factory.setAddress("http://localhost:8088/abc");
// factory.getServiceFactory().setDataBinding(new AegisDatabinding());
UserService client = (UserService) factory.create();