WebService学习更新中~
来源:互联网 发布:加里波利战役数据 编辑:程序博客网 时间:2024/06/01 08:13
1.Jax-ws:java api xml webservice 入门
SEI:Service Endpoint Interface 服务提供的接口——ICalcService
SIB:Service Implemetion Bean 实现服务的具体类——CalcServiceImpl
下面是利用jdk1.6.0_38的环境,实现简单的webService。
步骤:
服务器:
1.创建服务接口(ICalcService)
2.创建服务实现类(CalcServiceImpl)
3.创建服务发布类 (Server)
客户端:
客户端调用远程接口,访问服务。
服务器短代码:
package com.techbirds.service; import javax.jws.WebService; @WebService public interface ICalcService { public int add(int a,int b); public int del(int a,int b); }
package com.techbirds.service; import javax.jws.WebService; @WebService(endpointInterface="com.techbirds.service.ICalcService") public class CalcServiceImpl implements ICalcService { /* (non-Javadoc) * @see com.techbirds.service.IOneService#add(int, int) */ @Override public int add(int a, int b) { System.out.println("a+b="+(a+b)); return a+b; } /* (non-Javadoc) * @see com.techbirds.service.IOneService#del(int, int) */ @Override public int del(int a, int b) { System.out.println("a-b="+(a-b)); return a-b; } }
package com.techbirds.service; import javax.xml.ws.Endpoint; /** * @author techbirds * */ public class Server { /** * @param args */ public static void main(String[] args) { String address="http://localhost:8888/ns"; Endpoint.publish(address, new CalcServiceImpl()); } }
客户端代码:
package com.techbirds.service; import java.net.MalformedURLException; import java.net.URL; import javax.xml.namespace.QName; import javax.xml.ws.Service; public class Client { public static void main(String[] args) { try { URL url=new URL("http://localhost:8888/ns?wsdl"); QName sname=new QName("http://service.techbirds.com/", "CalcServiceImplService"); Service service=Service.create(url,sname); ICalcService ics=service.getPort(ICalcService.class); ics.add(1, 2); ics.del(2, 1); //System.out.println(ics.add(1, 2)); //System.out.println(ics.del(2, 1)); } catch (MalformedURLException e) { e.printStackTrace(); } } }
项目结构:
此demo的缺点在于:ICalcSercie接口必须提供给客户端,否则其不知如何使用远程服务。后续中会有改善。。
ps:在使用jdk自带实现webservice时,会遇到com.sun.xml.internal.ws.model.RuntimeModelerException异常,原因在于jdk版本不够高不支持,为此我直接下载了jdk1.6.0_38 。下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html
- WebService学习更新中~
- webservice学习中...
- jQuery学习更新中~
- Excel学习更新中
- sed学习笔记 更新中...
- 学习目录---永远更新中
- linux学习 持续更新中
- Ant学习笔记(更新中~)
- clojure学习笔记(更新中)
- 数据库学习笔记(更新中)
- notification学习--持续更新中。。。
- SourceInsight学习笔记,更新中
- swift学习总结(更新中...)
- 学习笔记,持续更新中
- Javascript学习路程(更新中)
- shell学习(更新中)
- Jenkins学习(更新中)
- 裸机学习:持续更新中
- 怎样在Windows中制作u盘linux操作系统
- “虚拟运营商”巨头维珍带来的“移动通信转售业务”经验
- hibernate一对一双向主键关联_Annotation
- 推荐php开发利器 快速创建web应用
- URL的一些建议
- WebService学习更新中~
- data and bindings
- 关闭本程序多个Activity
- hdu1065&&poj1051 Wooden Sticks
- "我的电脑"出现多个盘符,指向同一块硬盘?(SUBST命令)
- ubuntu中如何自己设置分辨率和主显示器
- JAVA项目开发中常遇到的字符串替换问题
- 将long数据存到字符串中并格式化字符串数组
- 开源软件的编译流程