一. Web Service是一个应用程序,是能够用编程的方法通过Web调用来实现某个功能的应用程序
Web Service支持Web协议,如:HTTP,TCP/IP,SMTP等
Web Service的标准
XML数据格式
SOAP (简单对象访问协议)
WSDL(Web Service描述语言)
二. 为什么使用webservice
为了,跨平台,跨语言
三。怎样使用webservice
1.添加xfire支持 1.类库 2.web.xml中注册servlet 3.webservices/service.xml
2.开发接口,和实瑞类,并注册在services.xml之中
注册:
<service>
<name>类名</name>
<namespace>命名空间名</namespace>
<serviceClass>包+接口名</serviceClass>
<implementationClass>包+实现类名</implementationClass>
</service>
3.查看webservice
http://localhost:8080/EBook/services/SayHello?wsdl
4.调用webservice
1.远程客端,是通通myeclips生成的
2.通过servlet调用
// 创建服务的元数据
Service serviceModel = new ObjectServiceFactory()
.create(Order.class);
//创建服务的代理
XFire xfire = XFireFactory.newInstance().getXFire();
XFireProxyFactory factory = new XFireProxyFactory(xfire);
//指定服务的地址
String serviceUrl = "http://localhost:8080/EBook/services/Order";
//声明一个接口对象
Order client = null;
try {
//创建服务的对象
client = (Order) factory.create(serviceModel, serviceUrl);
} catch (Exception e) {
}
String str = "" ;
try {
client.save(title) ;
} catch (Exception e) {
}
3.通过C#调用webservice
三。单元测试
1>添加Junit
在MyEclipse工具的"包资源管理器"中的项目名称上,单击标右键,选择Properties---->Java Build Path
-->Libraries-->AddLibrary--->JUnit---Next->出来一个Add Library对话框选择JUnit library version
-->选择JUnit4--点Finish
2>Junit3,Junit4
Junit3规则:extends TestCase 方法名以test开头,不能接收参数,没有返回值
Junit4:不需要继承任何类
@Before @Test @After这三个常用的注解