您的位置:首页 > 运维架构 > Apache

apache cxf之 一个简单的JAX-WS服务程序

2013-07-10 10:29 337 查看
推荐一本apache cxf的书籍:



apache cxf的配置,这边就不做介绍了。请参照我关于它配置的博文。

开发步骤:

1、新建Java project,build path引入cxf runtime。



2、新建SEI服务接口:

package demo.cxf.helloworld;

import javax.jws.WebParam;

public interface HelloWorld {
public String sayHello(@WebParam(name="text")String text);//注解定义web参数的
}


3、服务的实现:

package demo.cxf.helloworld;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService(name="HelloWorld")//注解定义服务
public class HelloWorldImpl implements HelloWorld {

@Override
public String sayHello(@WebParam(name="text")String text) {
System.out.println("sayHello called");
return "Hello "+text+",this is world!";
}

}


4、服务的发布与测试

package demo.cxf.helloworld.server;

import java.io.IOException;

import javax.xml.ws.Endpoint;

import demo.cxf.helloworld.HelloWorld;
import demo.cxf.helloworld.HelloWorldImpl;

public class Server {

public static void main(String[] args) throws IOException {
Server server = new Server();
server.startServer();
System.out.println("Startting ready...");
System.in.read();//按任意键退出
System.out.println("Server exiting...");
System.exit(0);//程序退出
}

public void startServer(){
System.out.println("Starting Server.....");
HelloWorld helloWorld = new HelloWorldImpl();
String address = "http://localhost:8080/HelloWorld";

//发布服务
Endpoint.publish(address, helloWorld);
}

}


测试:run as java application



浏览器访问:http://localhost:8080/HelloWorld?wsdl

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: