此处将为大家介绍关于webService概念的详细内容,并且为您解答有关webservice简介的相关问题,此外,我们还将为您介绍关于axis2实现webservice之使用services.xml文
此处将为大家介绍关于webService概念的详细内容,并且为您解答有关webservice简介的相关问题,此外,我们还将为您介绍关于axis2实现webservice之使用services.xml文件发布WebService、Java 的 WebService概述、PHP使用SOAP扩展实现WebService的方法 webservice视频教程 c# webservice php webservice、Web Service概念和术语的有用信息。
本文目录一览:- webService概念(webservice简介)
- axis2实现webservice之使用services.xml文件发布WebService
- Java 的 WebService概述
- PHP使用SOAP扩展实现WebService的方法 webservice视频教程 c# webservice php webservice
- Web Service概念和术语
webService概念(webservice简介)
Web服务是一种服务导向架构的技术,通过标准的Web协议提供服务,目的是保证不同平台的应用服务可以互操作。
根据W3C的定义,Web服务(Web service)应当是一个软件系统,用以支持网络间不同机器的互动操作。网络服务通常是许多应用程序接口(API)所组成的,它们透过网络,例如国际互联网(Internet)的远程服务器端,执行客户所提交服务的请求。
尽管W3C的定义涵盖诸多相异且无法介分的系统,不过通常我们指有关于主从式架构(Client-server)之间根据SOAP协议进行传递XML格式消息。无论定义还是实现,WEB服务过程中会由服务器提供一个机器可读的描述(通常基于WSDL)以辨识服务器所提供的WEB服务。另外,虽然WSDL不是SOAP服务端点的必要条件,但目前基于Java的主流WEB服务开发框架往往需要WSDL实现客户端的源代码生成。一些工业标准化组织,比如WS-I,就在WEB服务定义中强制包含SOAP和WSDL。
核心定义
考虑到并没某个独立文档包含一切相关内容,可采用模块化的方式给出对WEB服务的描述,但不能给出一个“绝对全面和准确”的定义。受外部环境和实现技术影响,各方给出的核心定义可能稍有出入,但通常包括:
- SOAP
- 一个基于XML的可扩展消息信封格式,需同时绑定一个传输用 协议。这个协议通常是HTTP或 HTTPS,但也可能是 SMTP或 XMPP。
- WSDL
- 一个XML格式文档,用以描述服务端口访问方式和使用协议的细节。通常用来辅助生成服务器和客户端代码及配置信息。
- UDDI
- 一个用来发布和搜索WEB服务的协议,应用程序可借由此协议在设计或运行时找到目标WEB服务。
这些标准由这些组织制订:W3C负责XML、SOAP及WSDL;OASIS负责uddi。
[编辑]协议集
为提高WEB服务间的互操作能力,WS-I还特别发布了WEB服务协议集(Profile)。协议集包含了一系列特定版本的核心定义(诸如SOAP和WSDL),以及对其使用上的限制与约束。WS-I还发布了用于部署协议集兼容WEB服务的测试工具及相关用例。
[编辑]WS-系列追加定义
为扩展WEB服务能力,一些新的标准已经或正在被开发。这些标准通常被冠以WS字头(Web Service的简称),以下是一个WS系列追加标准的不完全列表:
- WS安全(WS-Security)
- 定义了如何在SOAP中使用XML加密或XML签名来保护消息传递。可作为HTTPS保护的一种替代或扩充。
- WS信赖性(WS-Reliability)
- 一个来自oasis的标准协议,用来提供可信赖的WEB服务间消息传递。
- WS可信赖消息(WS-ReliableMessaging)
- 同样是一个提供信赖消息的协议,由Microsoft,BEA 和IBM发布。目前oasis正对其实施标准化工作。
- WS寻址(WS-Addressing)
- 定义了在SOAP消息内描述发送/接收方地址的方式。
- WS事务(WS-Transaction)
- 定义事务处理方式。
一直以来,W3C负责制定了不少WS追加定义,但近来此举开始受到怀疑。一些人呼吁W3C作为网络和语义网构建者应当把精力放在核心网络本身,而不是为WEB服务改换版本。特别是2007年2月的企业级WEB服务论坛上,对W3C不再充当WEB服务定义者的诉求开始表面化。 此外,oasis对WEB服务扩展实施了许多标准化工作。包括WEB服务资源框架以及WSDM。
使用WEB服务的方式
WEB服务实际上是一组工具,并有多种不同的方法调用之。三种最普遍的手段是:远程过程调用(RPC),面向服务架构(SOA)以及表述性状态转移(REST)。
[编辑]远程过程调用
-
主条目: 远程过程调用
WEB服务提供一个分布式函数或方法接口供用户调用,这是一种比较传统的方式。通常,在WSDL中对RPC接口进行定义(类似于早期的XML-RPC)。
尽管最初的WEB服务广泛采用RPC方式部署,但针对其过于紧密之耦合性的批评声也随之不断。这是因为RPC式WEB服务实质上是利用一个简单的映射,以把用户请求直接转化成为一个特定语言编写的函数或方法。如今,多数服务提供商认定此种方式在未来将难有作为,在他们的推动下,WS-I基本协议集(WS-I Basic Profile)已不再支持远程过程调用。
[编辑]服务导向架构
-
主条目: 服务导向架构
现在,业界比较关注的是遵从服务导向架构(Service-oriented architecture,SOA)概念来构筑WEB服务。在服务导向架构中,通讯由消息驱动,而不再是某个动作(方法调用)。这种WEB服务也被称作面向消息的服务。
SOA式WEB服务得到了大部分主要软件供应商以及业界专家的支持和肯定。作为与RPC方式的最大差别,SOA方式更加关注如何去连接服务而不是去特定某个实现的细节。WSDL定义了联络服务的必要内容。
[编辑]表述性状态转移
-
主条目: REST
表述性状态转移式(Representational state transfer,REST)WEB服务类似于HTTP或其他类似协议,它们把接口限定在一组广为人知的标准动作中(比如HTTP的GET、PUT、DELETE)以供调用。此类WEB服务关注与那些稳定的资源的互动,而不是消息或动作。
此种服务可以通过WSDL来描述SOAP消息内容,通过HTTP限定动作接口;或者完全在SOAP中对动作进行抽象。
类似方式
无论是在WEB服务出现以前,还是现在,一直不断有各种同类技术问世。比如,RMI作为这样一种中间件系统就得到了广泛部署。CORBA和DCOM则更加雄心壮志,两者都尝试将作用域波及到分布式对象,这一点也为WEB服务所模仿。
这些类似方式往往借助于XML-RPC和HTTP本身,而不依靠SOAP封装参数。
[编辑]外部链接
- W3C Web Services Activity home page
- Web Services Architecture (W3C Working Group Note)
- Secure,Reliable,Transacted Web Services(IBM/Microsoft白皮书)
- XMethods - Collection of public Web Services
axis2实现webservice之使用services.xml文件发布WebService
还是对教程的延伸,本来是周五要写的,但是耽搁了一下,就拖到周一了。
用Axis2实现Web Service,虽然可以将POJO类放在axis2\WEB-INF\pojo目录中直接发布成Web Service,这样做不需要进行任何配置,但这些POJO类不能在任何包中。这似乎有些不方便,为此,Axis2也允许将带包的POJO类发布成Web Service。
先实现一个POJO类,代码如下:
这个类有两个方法,这两个方法都需要发布成Web Service方法。这种方式和直接放在pojo目录中的POJO类不同。要想将MyService类发布成Web Service,需要一个services.xml文件,这个文件需要放在meta-inf目录中,该文件的内容如下:
其中<service>元素用于发布Web Service,一个<service>元素只能发布一个WebService类,name属性表示WebService名,如下面的URL可以获得这个WebService的WSDL内容:
http://localhost:8080/axis2/services/myService?wsdl (这个得等到.aar文件出来之后)
其中name属性名就是上面URL中"?"和"/"之间的部分。
<description>元素表示当前Web Service的描述,<parameter>元素用于设置WebService的参数,在这里用于设置WebService对应的类名。在这里最值得注意的是<messageReceivers>元素,该元素用于设置处理WebService方法的处理器。例如,getGreeting方法有一个返回值,因此,需要使用可处理输入输出的RPcmessageReceiver类,而update方法没有返回值,因此,需要使用只能处理输入的RPCInOnlyMessageReceiver类。
使用这种方式发布WebService,必须打包成.aar文件,..aar文件实际上就是改变了扩展名的.jar文件。在现在建立了两个文件(这两个文件夹任意):MyService.java和services.xml。将MyService.java编译,生成MyService.class。services.xml和MyService.class文件的位置如下:
D:\ws\service\MyService.class
D:\ws\meta-inf\services.xml
在windows控制台中进入ws目录,并输入如下的命令生成.aar文件(实际上,.jar文件也可以发布webservice,但axis2官方文档中建议使用.aar文件发布webservice):
jar cvf ws.aar . jar cvf AxisTest.aar .
如下是我测试的过程
原来发现不管要.aar,之后还需要一个“.”,即.arr.,但是最坑爹的就是这里了,加了“.”之后还是不对啊,最后的问题居然是这个后面的点要空一格,不能紧挨着.arr
如下成功之后的文件夹情况
最后将ws.aar文件复制到<Tomcat安装目录>\webapps\axis2\WEB-INF\services目录中,启动Tomcat后,就可以调用这个WebService了。
已经显示webservice发布成功了,接下来就是编写客户端进行调运了,跟前面一样,也需要wsdl2java命令去生成stub类,过程我就不多说了,之前的博客里有
如下是调用客户端的代码
运行结果
由于“帅哥”是在服务器端打印的,所以客户端是看不到的。
在打包arr文件的时候,发现有一个build.xml文件,这个是ant脚本中的知识,在本题中暂时不涉及,以后再介绍。
如果想发布多个WebService,可以使用<serviceGroup>元素,如再建立一个MyService1类,代码如下:
在services.xml文件中可以使用如下的配置代码来配置MyService和MyService1类:
Java 的 WebService概述
Java 的 WebService框架有JWS、Axis2、XFire、CXF、spring WS,简单介绍:
1、JWS是Java语言对WebService服务的一种实现,用来开发和发布服务。而从服务本身的角度来看JWS服务是没有语言界限的。但是Java语言为Java开发者提供便捷发布和调用WebService服务的一种途径。
2、Axis2是Apache下的一个重量级WebService框架,准确说它是一个Web Services / SOAP / WSDL 的引擎,是WebService框架的集大成者,它能不但能制作和发布WebService,而且可以生成Java和其他语言版WebService客户端和服务端代码。这是它的优势所在。但是,这也不可避免的导致了Axis2的复杂性,使用过的开发者都知道,它所依赖的包数量和大小都是很惊人的,打包部署发布都比较麻烦,不能很好的与现有应用整合为一体。但是如果你要开发Java之外别的语言客户端,Axis2提供的丰富工具将是你不二的选择。
3、XFire是一个高性能的WebService框架,在Java6之前,它的知名度甚至超过了Apache的Axis2,XFire的优点是开发方便,与现有的Web整合很好,可以融为一体,并且开发也很方便。但是对Java之外的语言,没有提供相关的代码工具。XFire后来被Apache收购了,原因是它太优秀了,收购后,随着Java6 JWS的兴起,开源的WebService引擎已经不再被看好,渐渐的都败落了。
4、CXF是Apache旗下一个重磅的SOA简易框架,它实现了ESB(企业服务总线)。CXF来自于XFire项目,经过改造后形成的,就像目前的Struts2来自WebWork一样。可以看出XFire的命运会和WebWork的命运一样,最终会淡出人们的视线。CXF不但是一个优秀的Web Services / SOAP / WSDL 引擎,也是一个不错的ESB总线,为SOA的实施提供了一种选择方案,当然他不是最好的,它仅仅实现了SOA架构的一部分。
基于以上的认识,我们可以得知,虽然有了Java6,但是我们还可以选择Axis2、XFire、CXF等。我们不能指望有了Java6 JWS,就能异想天开去实施SOA。如果要与别的语言交互,也许我们还有赖于Axis2等等,当然这不是唯一选择,仅仅是一种可供选择的方案。
还有,目前很多企业的应用还是基于Java5的,而Java5的项目不会瞬间都升级到Java6,如果要在老项目上做扩展,我们还有赖于其他开源的WS引擎。
WebService历来都很受重视,特别是Java阵营,WebService框架和技术层出不穷。知名的XFile(新的如CXF)、Axis1、Axis2等。
而Sun公司也不甘落后,从早期的JAX-RPC到现在成熟的、支持RPC调用与消息传递的JAX-WS都经过了市场的考验,十分成熟,而且使用JAX-WS开发WebService的收益是很大的,它是轻量级的。
PHP使用SOAP扩展实现WebService的方法 webservice视频教程 c# webservice php webservice
Web Service概念和术语
XML (eXtensible Markup Language)
XML is used to organize documents and business data. XML files can be stored or transmitted between two applications on a network. Basically, they are just plain text documents that contain special tags that label different parts of a document or fields of data.
XML是一种由规范定义的元语言。XML标记语言定义了一套用来组织和描述文本的标记(tag)。标记通常成对出现,其中一个标记是开始标记,另一个标记是结束标记。位于这两个标记之间的所有内容均成为元素。
SOAP (Simple Object Access Protocol)
SOAP defines a standard packaging format for transmitting XML data between applications on a network. A SOAP message is just an XML document. SOAP is specially designed, however, to contain and transmit other XML documents as well as information related to routing, processing, security, transactions, and other qualities of service.
SOAP消息是一种XML文档,它有其自己的XML模式、命名空间和处理规则。目前的版本是SOAP 1.2。
WSDL (Web Services Description Language)
WSDL is a standard for describing the structure of the XML data exchanged between two systems using SOAP.
WSDL是一个用于精确描述Web服务的文档格式,它用来指定客户与具体的Web服务通信时必须使用的确切的消息格式、Internet协议以及地址。目前的版本是WSDL 2.0
UDDI (Universal Description, Discovery, and Integration)
UDDI defines a standard set of Web service operations (methods) that are used to store and look up information about other Web service applications. In other words, UDDI defines a standard SOAP-based interface for a Web services registry. You can use a UDDI registry to find a particular type of Web service, or to find out about the Web services hosted by a specific organization. A UDDI registry is often referred to as a "Yellow Pages" for Web services. The UDDI specification is now maintained by the Organization for the Advancement of Structured Information Standards (OASIS)
UDDI定义了一套标准的Web服务操作方法,用于存储、查找有关其他Web服务应用程序方面的信息。
WS-I BP (Web Services Interoperability Basic Profile)
Web Services Interoperability Organization is an organization of Web services vendors that are committed to defining a standard for Web services interoperability. The first deliverable of the WS-I was the Basic Profile 1.0, 第二个是WS-I Basic Profile 2.0
二. Web Service Advanced概念
WS-Addressing
WS-Addressing specification is to provide the means to identify a Web service endpoint and a way to use such identifiers in SOAP messages for the delivery and exchange of messages between Web service providers and Web service requesters.
WS-Addressing通过对SOAP消息的扩展,为Web Services的寻址问题提供更强大的支持。WS-Addressing规范主要描述了两个概念:EndpointReference 以及Message Addressing Properties。在Web Services中代表一类逻辑功能的服务实现可能存在不同的Endpoint,每一个Endpoint可能代表了一种不同的绑定方式,甚至对外表现出不同的接口,比如Endpoint A可能使用TCP协议通讯,而Endpoint B则可能使用Http协议。通过EndpointReferrence我们就可以引用到相应的Endpoint上,从而访问该服务。 Message Addressing Properties作为SOAP Head的扩展将包含在每一个SOAP 消息中,用于该消息的寻址。
WS-Policy
WS-Policy defines a general-purpose framework for representing and combining statements about the quality of service properties. WS-Policy is an extensible framework that can accommodate domain-specific dialects to represent these assertions and allow the attachment of policies to arbitrary types of subjects though the generic attachment mechanisms that WS-Policy Attachments define.
Web服务策略框架规范(Web Services Policy Framework,WS-Policy)提供了一种灵活、可扩展的语法,用于表示基于XML Web services的系统中实体的能力、要求和一般特性。WS-Policy定义了一个框架和一个模型,将这些特性表示为策略。策略表示法既支持简单的声明式断言,也支持比较复杂的条件式断言。策略断言是要表示行为的 个体要求、能力或其他特性。例如,可以创建一个策略断言,定义这样一个要求:必须使用受信任的X.509证书签名SOAP消息主体。WS-Policy 提供了一个通用模型和语法,用于描述 Web 服务的策略及就此进行沟通。WS-Policy 断言说明特定 Web 服务的功能和约束。WS-PolicyAttachments 定义了用于将 WS-Policy 表达式与 Web 服务(即 WSDL)关联的若干方法。
WS-Reliable Messaging
WS-Reliable Messaging promises to bring the benefits of reliable messaging to SOA and Web services, enabling enterprises to extend Web services to support reliable business-to-business (B2B) exchanges.
WS-Coordination (WS-AT and WS-BA)
WS Atomic Transactions Application operations on Web services occur completely or not at all, and results are not available until the transaction is complete.
WS Business Activity Application operations on Web services exhibit a loose unit of work, in which results are shared prior to completion of the overall activity. Each participant undoes the operations it has performed within the conversation.
WS-Coordination specification provides the generic foundation for coordinating outcome agreements between interoperating Web services. WS-Atomic Transaction and WS-Business Activity specifications contain definitions of atomic and business transaction protocols, respectively, that you can use with WS-Coordination. WS-Coordination is defined as an extensible framework that can support additional protocols for other coordination patterns as required.
WS-AT and WS-BA用来定义规范WS的事务。
WS-Security
WS-Security SOAP Message Security is optimized for exchanging a small number of messages. A requester might engage in a prolonged "conversation" with a Web service. WS-SecureConversation builds on WS-Trust and message security to provide support for multimessage, long-lived conversations. WS-SecureConversation provides a better level of security and improved efficiency. This chapter also provides an overview of WS-Secure Conversation.
WS-Trust
WS-Security supports security tokens. Collaboration between enterprises often requires sharing additional information, such as customer identity information and preferences. WS-Federation extends WS-Trust to provide these functions, and is discussed later in this chapter.
WS-Authorization/ WS-Privacy
WS-Authorization and WS-Privacy are in progress.
WS-BPEL
Web services Business Process Execution Language is an extensible workflow-based language that aggregates services by choreographing service interactions. The aggregation is recursive, such that the process exposes WSDL interfaces to those that interact with it, and the corresponding services may be used in other choreographies.
BPEL用来描述和规范WS的业务流程.
三. J2EE Web Service APIs基本概念
用来在J2EE平台实现Web Service。包括JAX-RPC, SAAJ, JAXR, and JAXP
JAX-RPC (Java API for XML-based RPC)
You can think of JAX-RPC as Java RMI over SOAP. JAX-RPC is divided into two parts: a set of client-side APIs, and a set of server-side components, called endpoints.
The client-side APIs allow you to communicate with Web service endpoints hosted on some other platform. There are three client-side APIs: generated stub, dynamic proxy, and DII (Dynamic Invocation Interface). The generated stub is the one you will use the most, and its semantics closely resemble those of Java RMI. The dynamic proxy API also follows many of the Java RMI semantics, but is used less often. The DII is a very low-level API used primarily by vendor tools, but can also be employed by Web services developers if necessary.
The server-side components include the JAX-RPC service endpoint (JSE) and the EJB endpoint. The JSE component is actually a type of servlet that has been adapted for use as a Web services component. The EJB endpoint is simply a type of stateless session EJB that has been adapted for use as a Web service endpoint. The EJB endpoint provides all the transactional and security features of a normal stateless session bean, but it''s specifically designed to process SOAP requests.
SAAJ (SOAP with Attachments API for Java)
SAAJ is a low-level SOAP API that complies with SOAP 1.1 and the SOAP Messages with Attachments specification. SAAJ allows you to build SOAP messages from scratch as well as read and manipulate SOAP messages. You can use it alone to create, transmit, and process SOAP messages, but you''re more likely to use it in conjunction with JAX-RPC. In JAX-RPC, SAAJ is used primarily to process SOAP header blocks (the SOAP message meta-data).
JAXR (Java API for XML Registries)
JAXR provides an API for accessing UDDI registries. It simplifies the process of publishing and searching for Web service endpoints.
JAXP (Java API for XML Processing)
JAXP provides a framework for using DOM 2 and SAX2, standard Java APIs that read, write, and modify XML documents.
DOM 2 (Document Object Model, Level 2) is a Java API that models XML documents as trees of objects. It contains objects that represent elements, attributes, values, and so on. DOM 2 is used a lot in situations where speed and memory are not factors, but complex manipulation of XML documents is required. DOM 2 is also the basis of SAAJ 1.1.
DOM 2在处理XML文档的时候会将所有infoset在内存中创建相应的对象,所以比较消耗内存。
SAX2 (Simple API for XML, version 2) is very different in functionality from DOM 2. When a SAX parser reads an XML document, it fires events as it encounters start and end tags, attributes, values, etc. You can register listeners for these events, and they will be notified as the SAX2 parser detects changes in the XML document it is reading.
SAX2是基于push方式,StAX是pull的方式。
Streaming API for XML (StAX)
StAX is a streaming Java-based, event-driven, pull-parsing API for reading and writing XML documents. StAX provides is the latest API in the JAXP family, and provides an alternative to SAX, DOM, TrAX, and DOM for developers looking to do high-performance stream filtering, processing, and modification, particularly with low memory and limited extensibility requirements.
StAX is a bidirectional API, meaning that it can both read and write XML documents. SAX is read only, so another API is needed if you want to write XML documents.
JAX-WS2.0
JAX-WS2.0即Java API for XML Web Services (JAX-WS) 2.0,JAX-RPC 1.1即Java API for XML-Based RPC (JAX-RPC) 1.1。它们都是Sun公司的使用 Java 技术开发 Web 服务的规范,前者是后者的升级版本。
JAX-WS2.0的binding层用JAXB(JSR 222),xml解析层用StAX(JSR 173),完全基于标准,性能得到大幅提升;支持Java 5的注释(annotation),容易开发。
Java™Architecture for XML Binding (JAXB)
JAXB provides a fast and convenient way to bind between XML schemas and Java representations, making it easy for Java developers to incorporate XML data and processing functions in Java applications. JAXB provides methods for unmarshalling XML instance documents into Java content trees, and then marshalling Java content trees back into XML instance documents.
关于webService概念和webservice简介的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于axis2实现webservice之使用services.xml文件发布WebService、Java 的 WebService概述、PHP使用SOAP扩展实现WebService的方法 webservice视频教程 c# webservice php webservice、Web Service概念和术语的相关知识,请在本站寻找。
本文标签: