第一个web service 程序

xiaoxiao2026-03-16  5

使用cxf实现的一个helloworld web service 一个借口HelloWorld.java和一个实现类HelloWorldImpl.java 实现输入一个name,输出一个"Hello name" Web service服务器: MainServer.java package test; import org.apache.cxf.endpoint.Server; import org.apache.cxf.jaxws.JaxWsServerFactoryBean; public class MainServer { /** * @param args */ public static void main(String[] args) { JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean(); factory.setServiceClass(HelloWorldImpl.class); factory.setAddress("http://localhost:8080/HelloWorld"); Server server = factory.create(); server.start(); } } Web Service客户端HelloWorldClient.java package test; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; public class HelloWordClient { /** * @param args */ public static void main(String[] args) { JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setAddress("http://localhost:8080/HelloWorld"); factory.setServiceClass(HelloWorld.class); HelloWorld helloWorld = (HelloWorld) factory.create(); System.out.println(helloWorld.sayHello("Wubiao")); } } 运行结果: 客户端输出:Hello Wubiao 服务器端输出:Hello World is called!
转载请注明原文地址: https://www.6miu.com/read-5046014.html

最新回复(0)