WSDL样式详解
Web服务是通过WSDL文档来描述的。WSDL绑定描述了如何把服务绑定到消息传递协议(特别是SOAP消息传递协议)。WSDL的SOAP绑定style描述了服务调用方式,即远程过程调用rpc(RemoteProcedureCall)方式或文档document方式。use定义了类型是编码encoded方式还是文字literal方式。
创建绑定时,可以选择document样式或rpc样式。二者均具有自己的优点和缺点。使用rpc样式时,要执行的方法的名称同时也是有效负载的根元素的名称。
WSDL调用服务提供了6种样式:
1.rpc/encoded
2.rpc/literal
3.document/encoded
4.document/literal
5.document/literal/wrapped
6.document/encoded/wrapped
?
1.??????rpc/encoded样式
由SOAP消息定义实际类型信息。
WSDL文档样例:
? ????????targetNamespace="http://org.apache.axis2/xsd"
????????elementFormDefault="unqualified"
????????attributeFormDefault="unqualified">
...
?
?
?
...
?
???
???
?
...
?type="tns:ClassifiedServicePortType">
?
?
???
???
????? ?namespace="http://ws.apache.org/axis2"/>
???
???
?????
???
?
...
...
SOAP请求报文样例:
??????xmlns:xsd="http://www.w3.org/2001/XMLSchema"
??????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
??
????
????????Vintage1963T-Bird...
????????4/30/07
????
??
优点:
????????WSDL基本达到了尽可能地简单易懂的要求。
????????操作名出现在消息中,这样接收者就可以很轻松地把消息发送到方法的实现。
缺点:
????????类型编码信息(比如xsi:type="xsd:int")通常就是降低吞吐量性能的开销。
????????不能简单地检验此消息的有效性,因为只有Vintage1963T-Bird...行包含在Schema中定义的内容;其余的soap:body内容都来自WSDL定义。
2.??????rpc/literal样式
WSDL样例:
...
? ????????targetNamespace="http://org.apache.axis2/xsd"
????????elementFormDefault="unqualified"
????????attributeFormDefault="unqualified">
...
?
?
?
...
?
???
???
?
...
...
?
?
???
???
?????
???
???
?????
???
?
...
...
SOAP请求报文样例:
??????xmlns:env="http://schemas.xmlSOAP.org/SOAP/envelope/"
??????xmlns:xsd="http://www.w3.org/2001/XMLSchema"
??????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
??
????
??????Vintage1963T-Bird
??????4/30/2007
????
??
优点:
????????WSDL还是基本达到了尽可能地简单易懂的要求。
????????操作名仍然出现在消息中。
????????去掉了类型编码。
缺点:
????????仍然不能简单地检验此消息的有效性。因为只有和行中包含定义在Schema中的内容;soap:body内容的其余部分来自于WSDL定义。
3.??????document/encoded样式
此种方式很少使用。
WSDL样例:
...
? ????????targetNamespace="http://org.apache.axis2/xsd"
????????elementFormDefault="unqualified"
????????attributeFormDefault="unqualified">
...
???
???
...
?
?
?
...
?
???
???
?
...
...
?
?
???
???
?????
???
???
?????
???
?
...
SOAP请求报文样例:
??????xmlns:xsd="http://www.w3.org/2001/XMLSchema"
??????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
??
??????Vintage1963T-Bird
??????4/30/07
?
4.??????document/literal样式
WSDL样例:
...
? ????????targetNamespace="http://org.apache.axis2/xsd"
????????elementFormDefault="unqualified"
????????attributeFormDefault="unqualified">
...
???
???
...
?
?
?
...
?
???
???
?
...
...
?
?
???
???
?????
???
???
?????
???
?
...
SOAP请求报文样例:
??????xmlns:env="http://schemas.xmlSOAP.org/SOAP/envelope/"
??????xmlns:xsd="http://www.w3.org/2001/XMLSchema"
??????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
??????Vintage1963T-Bird...
??????4/30/07
优点:
????????没有编码信息
????????可以在最后用任何XML检验器检验此消息的有效性。soap:body中每项内容都定义在Schema中。
缺点:
????????SOAP消息中缺少操作名。而如果没有操作名,发送就可能比较困难,并且有时变得不可能。
5.??????document/literal/wrapped样式
WSDL样例:
...
? ????????targetNamespace="http://org.apache.axis2/xsd"
????????elementFormDefault="unqualified"
????????attributeFormDefault="unqualified">
...
???
?????
???????
?????????
?????????
???????
?????
???
...
?
?
...
?
???
???
?
...
...
?
?
???
???
?????
???
???
?????
???
?
...
...
SOAP请求报文样例:
??????xmlns:xsd="http://www.w3.org/2001/XMLSchema"
??????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
??
????
????????Vintage1963T-Bird...
????????4/30/07
????
??
注意此时SOAPBody中第一个元素的名称并不是操作的名称,而是Schema中的元素的名称。此时Schema中的元素的名称可以与操作名相同,也可以不同。如果取相同则是一种将操作名放入SOAP消息的巧妙方式。
此SOAP消息看起来非常类似于RPC/literal的SOAP消息。您可能会说,它看起来与RPC/literal的SOAP消息是完全一样的,不过,这两种消息之间存在着微妙的区别。在RPC/literal的SOAP消息中,下的根元素是操作的名称。在document/literal/wrapped的SOAP消息中,子句是单个输入消息的组成部分引用的元素的名称。
document/literal/wrapped样式的特征有:
????????输入消息只有一个组成部分。
????????该部分就是一个元素。
????????该元素有与操作相同的名称。
????????该元素的复杂类型没有属性。
优点:
????????没有编码信息。
????????出现在soap:body中的每项内容都是由Schema定义的,可以很容易地检验此消息的有效性。
????????方法名又出现在SOAP消息中。
缺点:
????????WSDL较为复杂。
6.??????document/encoded/wrapped样式
此种方式很少使用
WSDL样例:
...
? ????????targetNamespace="http://org.apache.axis2/xsd"
????????elementFormDefault="unqualified"
????????attributeFormDefault="unqualified">
...
???
?????
???????
?????????
?????????
???????
?????
???
...
?
?
...
?
???
???
?
...
...
?
?
???
???
?????
???
???
?????
???
?
...
...
SOAP请求报文样例:
??????xmlns:xsd="http://www.w3.org/2001/XMLSchema"
??????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
??
????
????????Vintage1963T-Bird...
????????4/30/07
????
??
附录:WSDL1.1规范中的SOAPBinding信息(对其中关键部分进行了中文翻译)
SOAPBinding
WSDLincludesabindingforSOAP1.1endpoints,whichsupportsthespecificationofthefollowingprotocolspecificinformation:
AnindicationthatabindingisboundtotheSOAP1.1protocol
AwayofspecifyinganaddressforaSOAPendpoint.
TheURIfortheSOAPActionHTTPheaderfortheHTTPbindingofSOAP
AlistofdefinitionsforHeadersthataretransmittedaspartoftheSOAPEnvelope
ThisbindinggrammaritisnotanexhaustivespecificationsincethesetofSOAPbindingsisevolving.NothingprecludesadditionalSOAPbindingstobederivedfromportionsofthisgrammar.Forexample:
SOAPbindingsthatdonotemployaURIaddressingschememaysubstituteanotheraddressingschemebyreplacingthesoap:addresselementdefinedinsection3.8.
SOAPbindingsthatdonotrequireaSOAPActionomitthesoapActionattributedefinedinsection3.4.
3.1SOAPExamples
Inthefollowingexample,aSubscribeToQuotesSOAP1.1one-waymessageissenttoaStockQuoteserviceviaaSMTPbinding.Therequesttakesatickersymboloftypestring,andincludesaheaderdefiningthesubscriptionURI.
Example3.SOAPbindingofone-wayoperationoverSMTPusingaSOAPHeader
?????????targetNamespace="http://example.com/stockquote.wsdl"
?????????xmlns:tns="http://example.com/stockquote.wsdl"
?????????xmlns:xsd1="http://example.com/stockquote.xsd"
?????????xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
?????????xmlns="http://schemas.xmlsoap.org/wsdl/">
?
???
???????
???????
???
?
???
???????
??????????
???????
???
?
???
???????
???????
??????????
??????????????
??????????????
??????????
???????
???
?
???
???????
??????????
???????
???
?
???
??????? ??????????????xmlns="http://www.w3.org/2000/10/XMLSchema">
??????????
??????????????
??????????????????
??????????????????????
??????????????????
??????????????
??????????
??????????
???????
???
ThisexampledescribesthataGetTradePriceSOAP1.1requestmaybesenttoaStockQuoteserviceviatheSOAP1.1HTTPbinding.Therequesttakesatickersymboloftypestring,atimeoftypetimeInstant,andreturnsthepriceasafloatintheSOAPresponse.
Example4.SOAPbindingofrequest-responseRPCoperationoverHTTP
?????????targetNamespace="http://example.com/stockquote.wsdl"
?????????xmlns:tns="http://example.com/stockquote.wsdl"
?????????xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
?????????xmlns:xsd1="http://example.com/stockquote.xsd"
?????????xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
?????????xmlns="http://schemas.xmlsoap.org/wsdl/">
?
???
???????
???????
???
?
???
???????
???
?
???
???????
??????????
??????????
???????
???
?
???
???????
???????
??????????
??????????
?????????????? ?????????????????????????encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
??????????
??????????
???????>
???
?
???
???????Myfirstservice
???????
??????????
???????
???
ThisexampledescribesthataGetTradePricesSOAP1.1requestmaybesenttoaStockQuoteserviceviatheSOAP1.1HTTPbinding.Therequesttakesastockquotesymbolstring,anapplicationdefinedTimePeriodstructurecontainingastartandendtimeandreturnsanarrayofstockpricesrecordedbytheservicewithinthatperiodoftime,aswellasthefrequencyatwhichtheywererecordedastheSOAPresponse.?TheRPCsignaturethatcorrespondstothisservicehasinparameterstickerSymbolandtimePeriodfollowedbytheoutputparameterfrequency,andreturnsanarrayoffloats.
Example5.SOAPbindingofrequest-responseRPCoperationoverHTTP
?
targetNamespace="http://example.com/stockquote.wsdl"
?????????xmlns:tns="http://example.com/stockquote.wsdl"
?????????xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
?????????xmlns:xsd1="http://example.com/stockquote/schema"
?????????xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
?????????xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
?????????xmlns="http://schemas.xmlsoap.org/wsdl/">
?
???
?????? ?????????????xmlns="http://www.w3.org/2000/10/XMLSchema">
??????????
?????????????
?????????????????
?????????????????
?????????????
??????????
??????????
?????????????
?????????????????
?????????????????????
?????????????????
?????????????
??????????
??????
???
?
???
???????
???????
???
?
???
???????
???????
???
?
???
???????
??????????
??????????
???????
???
?
???
???????
???????
??????????
??????????
?????????????? ?????????????????????????encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
??????????
??????????
???????>
???
?
???
???????Myfirstservice
???????
??????????
???????
???
?
3.2HowtheSOAPBindingExtendsWSDL
TheSOAPBindingextendsWSDLwiththefollowingextensionelements:
???
???????
???????
???????????
??????????
?????????????? ?????????????????????????encodingStyle="uri-list"?namespace="uri"?>
?????????????? ???????????????????????????encodingStyle="uri-list"?namespace="uri"?>
???????????????? ??????????????????????????????????encodingStyle="uri-list"?namespace="uri"?/>
?????????????????????????????????????????????
???????????
??????????
??????????
?????????????? ??????????????????????????encodingStyle="uri-list"?namespace="uri"?>
???????????
???????
???
?
???
???????
????
EachextensionelementoftheSOAPbindingiscoveredinsubsequentsections.
3.3soap:binding
ThepurposeoftheSOAPbindingelementistosignifythatthebindingisboundtotheSOAPprotocolformat:Envelope,HeaderandBody.Thiselementmakesnoclaimsastotheencodingorformatofthemessage(e.g.thatitnecessarilyfollowssection5oftheSOAP1.1specification).
Thesoap:bindingelementMUSTbepresentwhenusingtheSOAPbinding.
???
???????
???
Thevalueofthestyleattributeisthedefaultforthestyleattributeforeachcontainedoperation.Ifthestyleattributeisomitted,itisassumedtobe"document".Seesection3.4formoreinformationonthesemanticsofstyle.
ThevalueoftherequiredtransportattributeindicateswhichtransportofSOAPthisbindingcorrespondsto.TheURIvaluehttp://schemas.xmlsoap.org/soap/httpcorrespondstotheHTTPbindingintheSOAPspecification.OtherURIsmaybeusedheretoindicateothertransports(suchasSMTP,FTP,etc.).
3.4soap:operation
Thesoap:operationelementprovidesinformationfortheoperationasawhole.
???
???????
???????????
???????
???
ThestyleattributeindicateswhethertheoperationisRPC-oriented(messagescontainingparametersandreturnvalues)ordocument-oriented(messagecontainingdocument(s)).Thisinformationmaybeusedtoselectanappropriateprogrammingmodel.ThevalueofthisattributealsoaffectsthewayinwhichtheBodyoftheSOAPmessageisconstructed,asexplainedinSection3.5below.Iftheattributeisnotspecified,itdefaultstothevaluespecifiedinthesoap:bindingelement.Ifthesoap:bindingelementdoesnotspecifyastyle,itisassumedtobe"document".
ThesoapActionattributespecifiesthevalueoftheSOAPActionheaderforthisoperation.ThisURIvalueshouldbeuseddirectlyasthevaluefortheSOAPActionheader;noattemptshouldbemadetomakearelativeURIvalueabsolutewhenmakingtherequest.FortheHTTPprotocolbindingofSOAP,thisisvaluerequired(ithasnodefaultvalue).ForotherSOAPprotocolbindings,itMUSTNOTbespecified,andthesoap:operationelementMAYbeomitted.
3.5soap:body
Thesoap:bodyelementspecifieshowthemessagepartsappearinsidetheSOAPBodyelement.
soap:body元素说明了message元素中的part部分如何出现在SOAPBody元素中。
Thepartsofamessagemayeitherbeabstracttypedefinitions,orconcreteschemadefinitions.Ifabstractdefinitions,thetypesareserializedaccordingtosomesetofrulesdefinedbyanencodingstyle.EachencodingstyleisidentifiedusingalistofURIs,asintheSOAPspecification.SincesomeencodingstylessuchastheSOAPEncoding(http://schemas.xmlsoap.org/soap/encoding/)allowvariationinthemessageformatforagivensetofabstracttypes,itisuptothereaderofthemessagetounderstandalltheformatvariations:"readermakesright".Toavoidhavingtosupportallvariations,amessagemaybedefinedconcretelyandthenindicateit’soriginalencodingstyle(ifany)asahint.Inthiscase,thewriterofthemessagemustconformexactlytothespecifiedschema:"writermakesright".
Message中的part部分可以是抽象类型定义,也可以是具体的schema定义。如果是抽象定义,那么类型将根据一种encodingstyle所定义的一些规则进行序列化。每一种encodingstyle通过一系列的URIs来指定,如SOAP规范中所展示的。由于一些encodingstyles,如SOAPEncoding(http://schemas.xmlsoap.org/soap/encoding/),允许variation(变化)出现在给定抽象类型的消息格式中,因此,将由消息的阅读者来理解所有的variation(变化)的格式:"readermakesright"。为了避免支持所有的variation(变化),一个消息可以被具体定义,并根据提示指出它的原始encodingstyle,在这种情况下消息的书写者将将严格遵守schema规范:"writermakesright"。
Thesoap:bodybindingelementprovidesinformationonhowtoassemblethedifferentmessagepartsinsidetheBodyelementoftheSOAPmessage.Thesoap:bodyelementisusedinbothRPC-orientedanddocument-orientedmessages,butthestyleoftheenclosingoperationhasimportanteffectsonhowtheBodysectionisstructured:
Iftheoperationstyleisrpceachpartisaparameterorareturnvalueandappearsinsideawrapperelementwithinthebody(followingSection7.1oftheSOAPspecification).Thewrapperelementisnamedidenticallytotheoperationnameanditsnamespaceisthevalueofthenamespaceattribute.Eachmessagepart(parameter)appearsunderthewrapper,representedbyanaccessornamedidenticallytothecorrespondingparameterofthecall.Partsarearrangedinthesameorderastheparametersofthecall.
Iftheoperationstyleisdocumenttherearenoadditionalwrappers,andthemessagepartsappeardirectlyundertheSOAPBodyelement.
soap:bodybinding元素提供了信息用于组合不同的messageparts到SOAP消息的Body元素中。soap:body元素可以使用RPC-oriented和document-oriented类型的消息,但不同的封装形式对于Body部分的构造有重要的影响:
如果是RPCstyle,message中的每个part将作为是一个参数或者一个返回值,由一个wrapperelement进行封装,放入到SOAPBody中。此wrapperelement的名称将同WSDL中的对应operation的名称一样,其namespace将由绑定信息(soap:body)中的namespace属性决定。每一个出现在wrapperelement中的messagepart同所对应的调用中的参数名称一样。并且Parts将安调用中的参数顺序编排。
如果是documentstyle,那么将没有额外的wrapperelement,messageparts将直接出现在SOAPBody元素中。
ThesamemechanismsareusedtodefinethecontentoftheBodyandparameteraccessorelements.
???
???????
??????????
?????????????? ?????????????????????????encodingStyle="uri-list"?namespace="uri"?>
??????????
??????????
???????
???
TheoptionalpartsattributeoftypenmtokensindicateswhichpartsappearsomewherewithintheSOAPBodyportionofthemessage(otherpartsofamessagemayappearinotherportionsofthemessagesuchaswhenSOAPisusedinconjunctionwiththemultipart/relatedMIMEbinding).Ifthepartsattributeisomitted,thenallpartsdefinedbythemessageareassumedtobeincludedintheSOAPBodyportion.
Therequireduseattributeindicateswhetherthemessagepartsareencodedusingsomeencodingrules,orwhetherthepartsdefinetheconcreteschemaofthemessage.
所必须的use属性指明了messageparts是通过某些编码规则进行编码的,或者由消息的具体schema进行定义的。
Ifuseisencoded,theneachmessagepartreferencesanabstracttypeusingthetypeattribute.TheseabstracttypesareusedtoproduceaconcretemessagebyapplyinganencodingspecifiedbytheencodingStyleattribute.Thepartnames,typesandvalueofthenamespaceattributeareallinputstotheencoding,althoughthenamespaceattributeonlyappliestocontentnotexplicitlydefinedbytheabstracttypes.Ifthereferencedencodingstyleallowsvariationsinit’sformat(suchastheSOAPencodingdoes),thenallvariationsMUSTbesupported("readermakesright").
Ifuseisliteral,theneachpartreferencesaconcreteschemadefinitionusingeithertheelementortypeattribute.Inthefirstcase,theelementreferencedbythepartwillappeardirectlyundertheBodyelement(fordocumentstylebindings)orunderanaccessorelementnamedafterthemessagepart(inrpcstyle).Inthesecond,thetypereferencedbythepartbecomestheschematypeoftheenclosingelement(Bodyfordocumentstyleorpartaccessorelementforrpcstyle).ForanexamplethatillustratesdefiningthecontentsofacompositeBodyusingatype,seesection2.3.1.?ThevalueoftheencodingStyleattributeMAYbeusedwhentheuseisencodedtoindicatethattheconcreteformatwasderivedusingaparticularencoding(suchastheSOAPencoding),butthatonlythespecifiedvariationissupported("writermakesright").
如果use属性值为encoded,那么每个messagepart将通过type属性指定一个抽象类型。通过encodingStyle属性所表示的编码规范,这些抽象类型将用于构造一个具体的消息。partnames,typesa以及valueofthenamespaceattribute将作为编码的输入,其中的namespaceattribute仅仅在内容中被应用,没有被abstracttypes显式定义。如果所指定的encodingstyle允许variations(变化)它的格式,那么所有的variations(变化)都将被支持。
如果use属性值为literal,那么每个messagepart将通过element或者type属性指向一个具体的schema定义。在第一种情况下,part中的element所指向的内容将直接位于Body元素下(对于documentstylebindings),或者位于Body元素下的wrapperelement元素中(对于rpcstyle)。在第二种情况下,part中的type所指向的内容将作为其所对应元素的schema类型。
ThevalueoftheencodingStyleattributeisalistofURIs,eachseparatedbyasinglespace.TheURI''srepresentencodingsusedwithinthemessage,inorderfrommostrestrictivetoleastrestrictive(exactlyliketheencodingStyleattributedefinedintheSOAPspecification).
encodingStyle属性的值是一个URIs列表,由单个空格隔开。这些URIs代表着消息的编码类型,按照限制的从强到弱排序。
3.6soap:fault
Thesoap:faultelementspecifiesthecontentsofthecontentsoftheSOAPFaultDetailselement.Itispatternedafterthesoap:bodyelement(seesection3.5).
???
???????
??????????
?????????????? ????????????????????????????????encodingStyle="uri-list"?namespace="uri"?>
??????????
???????
???
Thenameattributerelatesthesoap:faulttothewsdl:faultdefinedfortheoperation.
ThefaultmessageMUSThaveasinglepart.Theuse,encodingStyleandnamespaceattributesareallusedinthesamewayaswithsoap:body(seesection3.5),onlystyle="document"isassumedsincefaultsdonotcontainparameters.
3.7soap:headerandsoap:headerfault
Thesoap:headerandsoap:headerfaultelementsallowsheadertobedefinedthataretransmittedinsidetheHeaderelementoftheSOAPEnvelope.Itispatternedafterthesoap:bodyelement(seesection3.5).
ItisnotnecessarytoexhaustivelylistallheadersthatappearintheSOAPEnvelopeusingsoap:header.Forexample,extensions(seesection2.1.3)toWSDLmayimplyspecificheadersshouldbeaddedtotheactualpayloadanditisnotrequiredtolistthoseheadershere.
???
???????
??????????
???????????? ?????????????????????????encodingStyle="uri-list"?namespace="uri"?>
?????????????? ????????????????????????????????encodingStyle="uri-list"?namespace="uri"?/>
???????????????????????????????????????????
???????????
??????????
???????
???
Theuse,encodingStyleandnamespaceattributesareallusedinthesamewayaswithsoap:body(seesection3.5),onlystyle="document"isassumedsinceheadersdonotcontainparameters.
Together,themessageattribute(oftypeQName)andthepartattribute(oftypenmtoken)referencethemessagepartthatdefinestheheadertype.TheschemareferencedbythepartMAYincludedefinitionsforthesoap:actorandsoap:mustUnderstandattributesifuse="literal",butMUSTNOTifuse="encoded".ThereferencedmessageneednotbethesameasthemessagethatdefinestheSOAPBody.
Theoptionalheaderfaultelementswhichappearinsidesoap:headerandhavethesamesyntaxassoap:header)allowsspecificationoftheheadertype(s)thatareusedtotransmiterrorinformationpertainingtotheheaderdefinedbythesoap:header.TheSOAPspecificationstatesthaterrorspertainingtoheadersmustbereturnedinheaders,andthismechanismallowsspecificationoftheformatofsuchheaders.
3.8soap:address
TheSOAPaddressbindingisusedtogiveaportanaddress(aURI).AportusingtheSOAPbindingMUSTspecifyexactlyoneaddress.?TheURIschemespecifiedfortheaddressmustcorrespondtothetransportspecifiedbythesoap:binding.
???
???????
??????????
????????
???
|
|