webService教程(1)
一:简介Web service是一个平台独立的,低耦合的,自包含的、基于可编程的web的应用程序,可使用开放的XML(标准通用标记语言下的一个子集)标准来描述、发布、发现、协调和配置这些应用程序,用于开发分布式的互操作的应用程序。 Web Service技术, 能使得运行在不同机器上的不同应用无须借助附加的、专门的第三方软件或硬件, 就可相互交换数据或集成。依据Web Service规范实施的应用之间, 无论它们所使用的语言、 平台或内部协议是什么, 都可以相互交换数据。Web Service是自描述、 自包含的可用网络模块, 可以执行具体的业务功能。Web Service也很容易部署, 因为它们基于一些常规的产业标准以及已有的一些技术,诸如标准通用标记语言下的子集XML、HTTP。Web Service减少了应用接口的花费。Web Service为整个企业甚至多个组织之间的业务流程的集 二:需要知识XML. Extensible Markup Language -扩展性标记语言 WSDL – WebService Description Language – Web服务描述语言。 SOAP-Simple Object Access Protocol(简单对象访问协议) 三:wsdl语言解析Wsdl文档从下往上读 Types - 数据类型定义的容器,它使用某种类型系统(一般地使用XML Schema中的类型系统)。(入参和出参的数据类型) Service- 相关服务访问点的集合。 四:webService调用网站http://www.webxml.com.cn 五:生成客户端代码
六:soap协议版本1.1和1.2的理解1) SOAP1.1请求消息体 POST /WebServices/MobileCodeWS.asmx HTTP/1.1
Host: webservice.webxml.com.cn
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://WebXml.com.cn/getMobileCodeInfo"
<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <getMobileCodeInfo xmlns="http://WebXml.com.cn/"> <mobileCode>string</mobileCode> <userID>string</userID> </getMobileCodeInfo> </soap:Body> </soap:Envelope>
2) SOAP1.1相应消息体 HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <getMobileCodeInfoResponse xmlns="http://WebXml.com.cn/"> <getMobileCodeInfoResult>string</getMobileCodeInfoResult> </getMobileCodeInfoResponse> </soap:Body> </soap:Envelope>
而1.1和1.2的主要的区别:Content-Type的不同。 七:利用jdk发布webservice服务注意:用Jdk1.6.0_21以后的版本发布一个WebService服务. 说明: 在JDK1.6中JAX-WS规范定义了如何发布一个webService服务。 helloService.java package org.sihai.cxf;
import javax.jws.WebService;
import javax.xml.ws.BindingType;
@WebService
public class HelloService {
public String sayHello(String name){
return "hello" + name;
}
}
发布类: package org.sihai.cxf;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
public class TestCxf {
public static void main(String[] args) {
JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();//设置服务工厂bean
sf.setAddress("http://localhost:8888/hello");//设置服务地址
sf.setServiceBean(new HelloService());//设置服务类
sf.setServiceClass(HelloService.class);
sf.create();
}
}
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- HDU 1566 Color the ball [树状数组区间更新]【数据结构】
- angular创建项目以及项目文件之间作用
- $inject.instantiate VS $inject.get VS $injector.invoke
- WebService 动态 IP 配置
- 如何在bash中覆盖函数重定向?
- scala – 从一个列表中提取不在另一个列表中的元素
- shell – 如何通过替换文件名中的单词来重命名多个文件?
- angular 结合 css 用图片自定义radio及checkbox样式
- Scala(单例)对象与典型类级别工件相比有什么好处
- autocomplete – Mat选择显示在Dialog后面的选项