ftp 上传网站,交易所网站建设教程,连锁酒店网站建设,免费浏览的网站简介
Web服务#xff08;Web Service#xff09;是一种Web应用开发技术#xff0c;用XML描述、发布、发现Web服务。它可以跨平台、进行分布式部署。 Web服务包含了一套标准#xff0c;例如SOAP、WSDL、UDDI#xff0c;定义了应用程序如何在Web上实现互操作。 Web服务的服…简介
Web服务Web Service是一种Web应用开发技术用XML描述、发布、发现Web服务。它可以跨平台、进行分布式部署。 Web服务包含了一套标准例如SOAP、WSDL、UDDI定义了应用程序如何在Web上实现互操作。 Web服务的服务端和客户端使用简单对象访问协议SOAP进行通信通信的双方可以使用不同的编程语言、运行在不同的平台上。
简单对象访问协议SOAPSimple Object Access Protocol
总体介绍
SOAP是一个基于XML的轻量级的协议用于在去中心化的、分布式环境中交换结构化的、有类型的信息。是 Web服务的通信协议。 SOAP本身没有定义任何应用语义例如一种编程模型或者定义实现特有的语义它只是通过提供一个模块化的包模型、通过一种编码机制用于对模块内的数据编码来定义一种简单的机制用来表达应用语义。这样就使得SOAP可以用在各种各样的系统中从消息系统到远程过程调用RPC。
一个SOAP消息用于请求一个web服务例如远程过程调用RPC。但SOAP不仅仅、也不是必须用于RPC。
SOAP协议运行在其它协议之上例如HTTP协议。
SOAP版本SOAP 1.1、SOAP 1.2两者都是W3C的标准。Web服务部署的时候可以两个版本都支持。
SOAP 1.1
协议介绍
SOAP 1.1协议https://www.w3.org/TR/2000/NOTE-SOAP-20000508/
SOAP 1.1包含如下三个部分
SOAP 信封envelope定义了一个总体框架用于表达消息内是什么、谁应该处理这个消息、是可选的还是强制的。SOAP 编码规则encoding rules定义了一种序列化机制用于交换应用定义的数据类型实例。SOAP RPC表达定义了一个规则用来表达远程过程调用RPC和响应。
一个SOAP消息就是一个XML文档其中必须包含一个SOAP envelope和一个SOAP body一个可选的SOAP header。
SOAP 1.1不依赖于传输协议可以和多种传输协议结合例如HTTP协议、java消息服务JMS。
SOAP独立于操作系统、不绑定某一个编程语言或者组件技术。 只要客户端能发出XML消息就行用什么技术实现客户端无关紧要。类似地服务可以用任何语言来实现只要服务能处理SOAP消息就行。客户端和服务端可以运行在任何合适的平台上。
消息示例用于RPC的场景
本示例来自SOAP 1.1协议https://www.w3.org/TR/2000/NOTE-SOAP-20000508/。 更多示例请参考协议中的附录Ahttps://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383539
备注本示例中SOAP消息底层绑定了HTTP协议
示例中一个GetLastTradePrice SOAP请求发送给StockQuote 服务。请求有一个字符串类型的参数ticker symbol在 SOAP 响应中返回一个float类型的值。
内嵌到HTTP 请求中的SOAP请求消息
POST /StockQuote HTTP/1.1
Host: www.stockquoteserver.com
Content-Type: text/xml; charsetutf-8
Content-Length: nnnn
SOAPAction: Some-URISOAP-ENV:Envelopexmlns:SOAP-ENVhttp://schemas.xmlsoap.org/soap/envelope/SOAP-ENV:encodingStylehttp://schemas.xmlsoap.org/soap/encoding/SOAP-ENV:Bodym:GetLastTradePrice xmlns:mSome-URIsymbolDIS/symbol/m:GetLastTradePrice/SOAP-ENV:Body
/SOAP-ENV:Envelope内嵌到HTTP 响应中的SOAP 响应消息
HTTP/1.1 200 OK
Content-Type: text/xml; charsetutf-8
Content-Length: nnnnSOAP-ENV:Envelopexmlns:SOAP-ENVhttp://schemas.xmlsoap.org/soap/envelope/SOAP-ENV:encodingStylehttp://schemas.xmlsoap.org/soap/encoding//SOAP-ENV:Bodym:GetLastTradePriceResponse xmlns:mSome-URIPrice34.5/Price/m:GetLastTradePriceResponse/SOAP-ENV:Body
/SOAP-ENV:EnvelopeSOAP 1.2
协议介绍
SOAP 1.2包含三个部分、另外包含一些断言和一套测试集 Part 0入门https://www.w3.org/TR/soap12-part0/ 描述了有代表性的SOAP消息结构和消息交互模式通过各种使用场景描述了SOAP的特征目的是为SOAP 1.2特征提供一个更加容易理解的指南帮助技术开发者理解SOAP怎么使用。 Part 1消息框架https://www.w3.org/TR/soap12-part1/ 这部分提供了一个处理模型、一个扩展性模型、一个底层协议绑定框架、和SOAP消息结构。 Part 2附加部分https://www.w3.org/TR/soap12-part2/ 描述了SOAP数据模型、SOAP编码、SOAP RPC表示、描述特性和绑定的惯例、SOAP提供的消息交互模式、SOAP HTTP绑定。
消息示例用于多轮交互的旅行预订场景
本示例来自SOAP 1.2版本的part0https://www.w3.org/TR/soap12-part0/
备注本示例只演示SOAP消息而暂时不管底层绑定了什么协议。
例1从旅行预订应用 -》旅行预订服务发起旅行预订请求
?xml version1.0 ?
env:Envelope xmlns:envhttp://www.w3.org/2003/05/soap-envelope env:Headerm:reservation xmlns:mhttp://travelcompany.example.org/reservation env:rolehttp://www.w3.org/2003/05/soap-envelope/role/nextenv:mustUnderstandtruem:referenceuuid:093a2da1-q345-739r-ba5d-pqff98fe8j7d/m:referencem:dateAndTime2001-11-29T13:20:00.000-05:00/m:dateAndTime/m:reservationn:passenger xmlns:nhttp://mycompany.example.com/employeesenv:rolehttp://www.w3.org/2003/05/soap-envelope/role/nextenv:mustUnderstandtruen:nameÅke Jógvan Øyvind/n:name/n:passenger/env:Headerenv:Bodyp:itineraryxmlns:phttp://travelcompany.example.org/reservation/travelp:departurep:departingNew York/p:departingp:arrivingLos Angeles/p:arrivingp:departureDate2001-12-14/p:departureDatep:departureTimelate afternoon/p:departureTimep:seatPreferenceaisle/p:seatPreference/p:departurep:returnp:departingLos Angeles/p:departingp:arrivingNew York/p:arrivingp:departureDate2001-12-20/p:departureDatep:departureTimemid-morning/p:departureTimep:seatPreference//p:return/p:itineraryq:lodgingxmlns:qhttp://travelcompany.example.org/reservation/hotelsq:preferencenone/q:preference/q:lodging/env:Body
/env:Envelope例2从旅行预订服务 -》 旅行预订应用返回响应提供机场列表供选择
?xml version1.0 ?
env:Envelope xmlns:envhttp://www.w3.org/2003/05/soap-envelope env:Headerm:reservation xmlns:mhttp://travelcompany.example.org/reservation env:rolehttp://www.w3.org/2003/05/soap-envelope/role/nextenv:mustUnderstandtruem:referenceuuid:093a2da1-q345-739r-ba5d-pqff98fe8j7d/m:referencem:dateAndTime2001-11-29T13:35:00.000-05:00/m:dateAndTime/m:reservationn:passenger xmlns:nhttp://mycompany.example.com/employeesenv:rolehttp://www.w3.org/2003/05/soap-envelope/role/nextenv:mustUnderstandtruen:nameÅke Jógvan Øyvind/n:name/n:passenger/env:Headerenv:Bodyp:itineraryClarification xmlns:phttp://travelcompany.example.org/reservation/travelp:departurep:departingp:airportChoicesJFK LGA EWR /p:airportChoices/p:departing/p:departurep:returnp:arrivingp:airportChoicesJFK LGA EWR /p:airportChoices/p:arriving/p:return /p:itineraryClarification/env:Body
/env:Envelope例3从旅行预订应用 -》 旅行预订服务选择了机场
?xml version1.0 ?
env:Envelope xmlns:envhttp://www.w3.org/2003/05/soap-envelope env:Headerm:reservation xmlns:mhttp://travelcompany.example.org/reservation env:rolehttp://www.w3.org/2003/05/soap-envelope/role/nextenv:mustUnderstandtruem:referenceuuid:093a2da1-q345-739r-ba5d-pqff98fe8j7d/m:referencem:dateAndTime2001-11-29T13:36:50.000-05:00/m:dateAndTime/m:reservationn:passenger xmlns:nhttp://mycompany.example.com/employeesenv:rolehttp://www.w3.org/2003/05/soap-envelope/role/nextenv:mustUnderstandtruen:nameÅke Jógvan Øyvind/n:name/n:passenger/env:Headerenv:Bodyp:itinerary xmlns:phttp://travelcompany.example.org/reservation/travelp:departurep:departingLGA/p:departing/p:departurep:returnp:arrivingEWR/p:arriving/p:return/p:itinerary/env:Body
/env:EnvelopeSOAP 1.1 和 SOAP 1.2之间的变化
https://www.w3.org/TR/soap12-part0/#L4697 Web服务描述语言WSDLWeb Services Description Language
简介
WSDL是XML格式用于描述Web服务。 WSDL 1.1版本W3C发布出来仅仅用于讨论但没有批准。 WSDL 2.0版本是被W3C批准的正式版本。
WSDL 1.1
https://www.w3.org/TR/2001/NOTE-wsdl-20010315
包含如下几部分
服务定义SOAP绑定HTTP GET 和 POST绑定MIME绑定
WSDL 2.0
介绍
WSDL 2.0包括3部分
part 0 入门https://www.w3.org/TR/wsdl20-primer/ 本部分包含WSDL 2.0基本知识、导入机制、扩展性和预先定义的扩展、杂项。Part 1 核心https://www.w3.org/TR/wsdl20/ 本部分包含组件模型、类型、模块化、文档、语言扩展性、定位 WSDL 2.0文档。Part 2 附件https://www.w3.org/TR/wsdl20-adjuncts/ 本部分包含预先定义的消息交互模式、预先定义的扩展、预先定义的行为样式、WSDL SOAP绑定扩展、WSDL HTTP绑定扩展。
WSDL 2.0文档样例
样例来自https://www.w3.org/TR/wsdl20-primer/#basics-greath-scenario
?xml version1.0 encodingutf-8 ?
description xmlnshttp://www.w3.org/ns/wsdltargetNamespace http://greath.example.com/2004/wsdl/resSvc xmlns:tns http://greath.example.com/2004/wsdl/resSvcxmlns:ghns http://greath.example.com/2004/schemas/resSvcxmlns:wsoap http://www.w3.org/ns/wsdl/soapxmlns:soaphttp://www.w3.org/2003/05/soap-envelopexmlns:wsdlx http://www.w3.org/ns/wsdl-extensionsdocumentationThis document describes the GreatH Web service. Additional application-level requirements for use of this service -- beyond what WSDL 2.0 is able to describe -- are available at http://greath.example.com/2004/reservation-documentation.html/documentationtypesxs:schema xmlns:xshttp://www.w3.org/2001/XMLSchematargetNamespacehttp://greath.example.com/2004/schemas/resSvcxmlnshttp://greath.example.com/2004/schemas/resSvcxs:element namecheckAvailability typetCheckAvailability/ xs:complexType nametCheckAvailability xs:sequence xs:element namecheckInDate typexs:date/ xs:element namecheckOutDate typexs:date/ xs:element nameroomType typexs:string/ /xs:sequence /xs:complexType xs:element namecheckAvailabilityResponse typexs:double/ xs:element nameinvalidDataError typexs:string/ /xs:schema /typesinterface name reservationInterface fault name invalidDataFaultelement ghns:invalidDataError/ operation nameopCheckAvailability patternhttp://www.w3.org/ns/wsdl/in-out stylehttp://www.w3.org/ns/wsdl/style/iriwsdlx:safe trueinput messageLabelIn elementghns:checkAvailability /output messageLabelOut elementghns:checkAvailabilityResponse /outfault reftns:invalidDataFault messageLabelOut//operation/interfacebinding namereservationSOAPBinding interfacetns:reservationInterfacetypehttp://www.w3.org/ns/wsdl/soapwsoap:protocolhttp://www.w3.org/2003/05/soap/bindings/HTTP/fault reftns:invalidDataFault wsoap:codesoap:Sender/operation reftns:opCheckAvailability wsoap:mephttp://www.w3.org/2003/05/soap/mep/soap-response//bindingservice namereservationService interfacetns:reservationInterfaceendpoint namereservationEndpoint bindingtns:reservationSOAPBindingaddress http://greath.example.com/2004/reservation//service/description统一描述、发现和集成UDDIUniversal Description, Discovery and Integration
备注OASIS已经宣布关闭了UDDI技术委员
UDDI基于XML规定如何注册、分发、发现 Web服务。发布的标准有 V2和V3。
UDDI Version 2 OASIS标准包含如下部分 https://www.oasis-open.org/committees/uddi-spec/doc/tcspecs.htm#uddiv2
UDDI Version 3 OASIS标准包含如下部分 https://www.oasis-open.org/committees/uddi-spec/doc/tcspecs.htm#uddiv3
支持带附件的SOAP消息Java接口SAAJSOAP with Attachments API for Java interface
SAAJ提供了利用Java编程模型在互联网上发送XML SOAP消息的标准方法SOAP消息可以携带附件例如附件是二进制形式。SAAJ用来处理 SOAP消息例如读、写、发送和接收。
主要的类和接口 https://www.ibm.com/docs/en/was/9.0.5?topicSSEQTP_9.0.5/com.ibm.websphere.nd.multiplatform.doc/ae/cwbs_saaj.htm
SAAJ 1.2 只支持SOAP 1.1消息而SAAJ 1.3支持SOAP 1.1 和SOAP 1.2 消息。 SAAJ 1.3向后兼容SAAJ 1.2SAAJ 1.4向后兼容SAAJ 1.3。
SAAJ 1.3 https://www.jcp.org/aboutJava/communityprocess/maintenance/jsr067/SAAJ1_3ChangeLog.html
SAAJ 1.4 https://download.oracle.com/otn-pub/jcp/saaj-1_4-mrel4-eval-spec/saaj-1.4.pdf
Web服务策略WS-PolicyWeb Services Policy
Web服务策略用来表示Web服务的能力和需求是供机器阅读的语言。 Web服务策略提供了一种机制用来表示Web服务的能力和需求一致的结合决定策略的兼容性命名和引用策略将Web服务元数据结构例如service、endpoint 和operation和策略关联。 Web服务策略是一门简单的语言有四个元素Policy, All, ExactlyOne 和 PolicyReference 和两个属性wsp:Optional 和 wsp:Ignorable。
例如文档中给出的策略示例(https://www.w3.org/TR/ws-policy-primer/)
Allwsam:Addressing…/wsam:AddressingExactlyOnesp:TransportBinding…/sp:TransportBindingsp:AsymmetricBinding…/sp:AsymmetricBinding/ExactlyOne
/AllAllmtom:OptimizedMimeSerialization wsp:Optionaltrue/wsam:Addressing…/wsam:AddressingExactlyOnesp:TransportBinding…/sp:TransportBindingsp:AsymmetricBinding…/sp:AsymmetricBinding/ExactlyOne
/Allsp:TransportBindingPolicysp:TransportTokenPolicysp:HttpsTokenwsp:Policy//sp:HttpsToken/Policy/sp:TransportTokensp:AlgorithmSuitePolicysp:Basic256Rsa15//Policy/sp:AlgorithmSuite…/Policy
/sp:TransportBindingWeb Services Policy 1.5版本包含如下几部分
入门https://www.w3.org/TR/ws-policy-primer/ 这部分不是一篇正式的规范。它提供了Web服务策略语言的介绍性描述。基本概念—策略表达式章节覆盖了Web服务策略的基本机制高级概念—策略表达式章节针对策略实现者和断言作者提供了更深层次的资料策略语言版本章节提供了策略语言版本管理的例子和最佳实践。框架https://www.w3.org/TR/ws-policy/ 这部分提供一个通用目的模型和对应的语法来描述基于Web服务的系统中实体的策略。定义了一套基本的结构可以被其它的Web服务规范使用和扩展来描述更广范围的要求和能力。附件https://www.w3.org/TR/ws-policy-attach/ 这部分定义了两个通用目的关联策略和目标的机制也定义了这些通用目的的机制怎么来使策略和WSDL 和 UDDI 描述关联。
Web服务寻址WS-AddressingWeb Services Addressing
Web服务寻址提供了跟传输无关的访问Web服务和消息的机制。
示例在SOAP 1.2消息中利用寻址属性示例来自https://www.w3.org/TR/ws-addr-core/#tocRange
(01) S:Envelope xmlns:Shttp://www.w3.org/2003/05/soap-envelope xmlns:wsahttp://www.w3.org/2005/08/addressing
(02) S:Header
(03) wsa:MessageIDhttp://example.com/6B29FC40-CA47-1067-B31D-00DD010662DA/wsa:MessageID
(04) wsa:ReplyTo
(05) wsa:Addresshttp://example.com/business/client1/wsa:Address
(06) /wsa:ReplyTo
(07) wsa:Tohttp://example.com/fabrikam/Purchasing/wsa:To
(08) wsa:Actionhttp://example.com/fabrikam/SubmitPO/wsa:Action
(09) /S:Header
(10) S:Body
(11) ...
(12) /S:Body
(13) /S:EnvelopeWeb服务寻址 1.0 - Corehttps://www.w3.org/TR/ws-addr-core/ 本部分包含端点引用、消息寻址属性、安全考虑。
Web服务安全WS-Security
Web Services Security: SOAP Message Security 1.0 (WS-Security 2004) : http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0.pdf
这是OASIS发布的规范取代Web Service Security (WS-Security) Version 1.0、Web Services Security Addendum Version 1.0。 本规范包括如下章节
消息保护机制ID引用安全头安全标识标识引用签名加密安全时间戳扩展样例错误处理安全考虑互操作性隐私考虑
Java API for XML-Based Web Services(JAX-WS)
https://download.oracle.com/otn-pub/jcp/jaxws-2_3-mrel5-eval-spec/jaxws-2.3.pdf
JAX-WS 2.0 规范是代替JAX-RPC 1.0的下一代Web服务API。JAX-RPCThe Java API for XML Based RPC是基于XML的RPC远程过程调用的Java API。
本规范包括如下章节
介绍WSDL 1.1 到Java的 映射Java 到 WSDL 1.1的映射客户端API服务API核心API注解定制化Handler框架SOAP绑定HTTP绑定