没有服务器的纯webservice

郑富成 2013-10-23 01:37:27
目前有两种简单的实现方式:
1. 使用sun的HttpServer
2. 使用jws来实现webservice

通过直接运行java -jar webservice.jar来搭建webservice服务。
当然这只是对于简单单一的webservice需求所搭建的。
1.

public class SimpleHttpServer {
public static void main(String[] args) throws IOException {
HttpServer server = HttpServer.create(new InetSocketAddress(8000),0);
server.createContext("/test", new MyHandler());
server.setExecutor(null);
server.start();
}
}



2.

@WebService
@SOAPBinding(style = Style.RPC)
public interface Station {
@WebMethod
public String getTime();
}
@WebService(endpointInterface = "webservice.Station")
public class StationImpl implements Station{
@Override
public String getTime() {
return DateFormat.getInstance().format(new Date());
}
}
public class StationPublisher {
public static void main(String[] args){
Endpoint.publish("http://localhost:8000/test", new StationImpl());
}
}



欢迎讨论更多webservice方案
额外post自己的日记小本子:http://www.sightcorner.com/
...全文
223 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
郑富成 2013-10-25
  • 打赏
  • 举报
回复
引用 2 楼 winic57 的回复:
挽尊于2013-10-24 13:14:07
多谢挽回楼主尊严~
郑富成 2013-10-25
  • 打赏
  • 举报
回复
引用 1 楼 zhangzxing 的回复:
友情帮顶 这儿 太冷清了
感谢哥们!
winic57 2013-10-24
  • 打赏
  • 举报
回复
挽尊于2013-10-24 13:14:07
张在兴 2013-10-23
  • 打赏
  • 举报
回复
友情帮顶 这儿 太冷清了

199

社区成员

发帖
与我相关
我的任务
社区描述
GAE相关讨论
社区管理员
  • GAE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧