Академический Документы
Профессиональный Документы
Культура Документы
ContentsSOAP
BasicProblemstosolve
1. 2.
3.
4.
Howtomaketheserviceinvocationpartofthelanguageinamoreorless transparentmanner. Dontforgetthisimportantaspect:whateveryoudesign,otherswillhaveto programanduse Howtoexchangedatabetweenmachinesthatmightusedifferentrepresentations fordifferentdatatypes.Thisinvolvestwoaspects: datatypeformats(e.g.,byteordersindifferentarchitectures) datastructures(needtobeflattenedandthereconstructed) Howtofindtheserviceoneactuallywantsamongapotentiallylargecollectionof servicesandservers. Thegoalisthattheclientdoesnotnecessarilyneedtoknowwheretheserver residesorevenwhichserverprovidestheservice. Howtodealwitherrorsintheserviceinvocationinamoreorlesselegantmanner: serverisdown, communicationisdown, serverbusy, duplicatedrequests...
SOAP
RemotecallsinRPC/DCE
RemotecallsinCORBA
Client Identifying and locating services Interface repository Implementation repository Service (sever)
RemotecallsinDCOM
Client Identifying and locating services Registry Registry Service (sever)
Wireprotocols,XMLandSOAP
RPC,CORBA,DCOM,evenJava,use Toaddressthisproblem,XMLwasused differentmechanismsandprotocols todefineSOAP forcommunicating.Allofthemmapto SOAPisconceptuallyquitesimple: TCPorUDPonewayoranotherbut RPCusingHTTP usedifferentsyntaxformarshalling, (attheclient)turnanRPCcall serializingandpackagingmessages intoanXMLdocument Theproblemisthatthesemechanisms arealegacyfromthetimewhen (attheserver)turntheXML communicationsweremostlywithin documentintoaprocedurecall LANsandwithinhomogeneous (attheserver)turnthe systems proceduresresponseintoan BuildingaB2Benvironment XMLdocument combiningthesystemsofdifferent (attheclient)turntheXML companiesbecomesdifficultbecause theprotocolsavailableinRPC,CORBA, documentintotheresponseto orDCOMaretoolowleveland theRPC certainlynotcompatibleamongeach useXMLtoserializethe other(gatewaysareneeded,etc.)
argumentsfollowingtheSOAP specification
ThebackgroundforSOAP
SOAPwasoriginallyconceivedastheminimalpossibleinfrastructure necessarytoperformRPCthroughtheInternet: useofXMLasintermediaterepresentationbetweensystems verysimplemessagestructure mappingtoHTTPfortunnelingthroughfirewallsandusingtheWeb infrastructure TheideawastoavoidtheproblemsassociatedwithCORBAsIIOP/GIOP (whichfulfilledasimilarrolebutusinganonstandardintermediate representationandhadtobetunneledthroughHTTPanyway) Thegoalwastohaveanextensionthatcouldbeeasilypluggedontopof existingmiddlewareplatformstoallowthemtointeractthroughthe InternetratherthanthroughaLANasintheoriginalcase.Hencethe emphasisonRPCfromtheverybeginning(essentiallyallformsof middlewareuseRPCatoneleveloranother) EventuallySOAPstartedtobepresentedasagenericvehicleforcomputer drivenmessageexchangesthroughtheInternetandthenitwasopenedto supportinteractionsotherthanRPCandprotocolsotherthenHTTP.
SOAPasRPCmechanism
CLIENT call stubs, runtime service location SOAP system
Serialized XML doc Wrap doc in HTTP POST request
SERVER service
SOAP system
Serialized XML doc
INTERNET
SOAP
WhatisSOAP?
TheW3CstartedworkingonSOAPin1999.ThecurrentW3C recommendationisVersion1.2 Originally:SimpleObjectAccessProtocol SOAPcoversthefollowingmainareas: Messageconstruct:Amessageformatforonewaycommunication describinghowamessagecanbepackedintoanXMLdocument Processingmodel:rulesforprocessingaSOAPmessageandasimple classificationoftheentitiesinvolvedinprocessingaSOAPmessage. Whichpartsofthemessagesshouldbereadbywhomandhowtoreact incasethecontentisnotunderstood ExtensibilityModel:Howthebasicmessageconstructcanbeextended withapplicationspecificconstructs Protocolbindingframework:AllowsSOAPmessagestobe transportedusingdifferentprotocols(HTTP,SMTP,) AconcretebindingforHTTP ConventionsonhowtoturnanRPC callintoaSOAPmessageandback aswellashowtoimplementtheRPCstyleofinteraction
12
SOAP:amessagingframework
SOAP RPC:Sinceversion1.1,SOAPabstractsfromtheRPCprogramming model SOAPisalightweightprotocolintendedforexchangingstructured information[],astateless,onewaymessageexchangeparadigm Definesthegeneralformatofamessageandhowtoprocessit Morecomplexinteractionpatternscanbecreatedbyapplications RPCisimplementedontopofthecorespecificationfollowingconventions oftheSOAPRPCrepresentation SOAP HTTP:Sinceversion1.1,SOAPabstractsfromtheprotocolusedto transportthemessages HTTPisoneofmanypossibletransports
13
TheSOAPmessagepath
ASOAPmessagecanpassthrough multiplehops onthewayfrom theinitialsendertotheultimate receiver Theentitiesinvolvedin transportingthemessageare calledSOAPnodes SOAPintermediaries forwardthe messageandmaymanipulateit EverySOAPnodeassumesa certainrole whichinfluencesthe messageprocessingatthenode.
Intermedaries
Ultimate receiver
14
SOAPmessages
SOAPmessage=SOAPenvelope Envelopecontainstwoparts: Header(optional): independentheaderblocks withmetadata(security, transactions,session,) Body:severalblocksof applicationdata SOAPdoesnotdefinethe semanticsoftheheadernorthe body,onlythestructureofthe message.
16
SkeletonSOAPmessage
<?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <soap:Header> ... ... </soap:Header> <soap:Body> ... ... <soap:Fault> ... ... </soap:Fault> </soap:Body> </soap:Envelope>
From http://www.w3schools.com
17
TheSOAPheader
Theheaderisintendedasagenericplaceholderforinformationthatis notnecessarilyapplicationdependent(theapplicationmaynotevenbe awarethataheaderwasattachedtothemessage). Typicalusesoftheheaderare:coordinationinformation,identifiers (e.g.,fortransactions),securityinformation(e.g.,certificates) SOAPprovidesmechanismstospecifywhoshoulddealwithheaders andwhattodowiththem.Forthispurposeitincludes: Actor attribute:whoshouldprocessthatparticularheaderblock. BooleanmustUnderstand attribute:indicateswhetheritis mandatorytoprocesstheheader.Ifaheaderisdirectedatanode (asindicatedbytheactorattribute),themustUnderstandattribute determineswhetheritismandatorytodoso. SOAP1.2addsarelay attribute(forwardheaderifnotprocessed)
18
SOAPHeaderExample
<?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <soap:Header> <m:Trans xmlns:m="http://www.w3schools.com/transaction/" soap:mustUnderstand="1">234</m:Trans> </soap:Header> ... ... </soap:Envelope>
From http://www.w3schools.com
19
Example:SOAPHeadersforSecurity
RPC Request SOAP Envelope SOAP header Security context Message Signature SOAP Body Name of Procedure Input param 1 Input param 2 RPC Response (one of the two) SOAP Envelope SOAP header Security context Message Signature SOAP Body Return parameter SOAP Envelope SOAP header Security context Message Signature SOAP Body Fault entry
20
TheSOAPbody
21
SOAPbodyexample
XML name space identifier for SOAP serialization XML name space identifier for SOAP envelope
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <m:GetLastTradePrice xmlns:m="Some-URI"> <symbol>DIS</symbol> </m:GetLastTradePrice> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
From the: Simple Object Access Protocol (SOAP) 1.1. W3C Note 08 May 2000
22
SOAPexample,headerandbody
<SOAP-ENV:Envelope xmlns:SOAP-ENV= "http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle= "http://schemas.xmlsoap.org/soap/encoding/"/> <SOAP-ENV:Header> <t:Transaction xmlns:t="some-URI" SOAP-ENV:mustUnderstand="1"> 5 </t:Transaction> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:GetLastTradePrice xmlns:m="Some-URI"> <symbol>DEF</symbol> </m:GetLastTradePrice> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Gustavo Alonso, D-INFK. ETH Zrich.
From the: Simple Object Access Protocol (SOAP) 1.1. W3C Note 08 May 2000
23
TheSOAPfault
WhenaSOAPmessagecouldnotbeprocessed,aSOAPfaultisreturned Afaultmustcarrythefollowinginformation: FaultCode:indicatingtheclassoferrorandpossiblyasubcode(for applicationspecificinformation) FaultString:humanreadableexplanationofthefault(notintendedfor automatedprocessing) Faultactor:whocausedthefaulttohappen Detail:Applicationspecificdatarelatedtothefault Thefaultcodesinclude: Versionmismatch:invalidnamespaceinSOAPenvelope MustUnderstand:aheaderelementwithmustunderstansettotruewas notunderstood Client:messagewasincorrect(formatorcontent) Server:problemwiththeserver,messagecouldnotbeprocessed Errorsinunderstandingamandatoryheaderblockarerespondedusingafault elementbutalsoincludeaspecialheaderindicatingwhichoneoftheoriginal headerblockswasnotunderstood.
24
MessageProcessingModel
Foreachmessagereceived,everySOAPnodeonthemessagepathmust processthemessageasfollows Decideinwhichrolestoact(standardroles:nextorultimateReceiver, orotherapplicationdefinedroles).Theserolesmayalsodependonthe contentsofthemessage. Identifythemandatoryheaderblockstargetedatthenode(matching role,mustUnderstand=true) Ifamandatoryheaderblockisnotunderstoodbythenode,afaultmust begenerated.Themessagemustnotbeprocessedfurther. Processthemandatoryheaderblocksand,incaseoftheultimate receiver,thebody.Otherheaderblockstargetedatthenodemaybe processed.Theorderofprocessingisnotsignificant. SOAPintermediarieswillfinallyforwardthemessage Processedheaderblocksmayberemoveddependingonthe specificationfortheblock. Headerblockswhichweretargetedattheintermediarybutnot processedarerelayedonlyifthetherelayattributeissettotrue. ActiveSOAPintermediariesmayalsochangeamessageinwaysnot describedhere(e.g.,encryptthemessage).
25
SOAPRPCrepresentation
27
RPCExample
Request:
Response:
28
SOAPprotocolbindingframework
30
SOAPandHTTP
SOAPmessagesaretypically transferredusingHTTP ThebindingtoHTTPdefinedinthe SOAPspecification SOAPcanuseGETorPOST.With GET,therequestisnotaSOAP messagebuttheresponseisaSOAP message,withPOSTbothrequest andresponseareSOAPmessages(in version1.2,version1.1mainly considerstheuseofPOST).
HTTP POST SOAP Envelope SOAP header Transactional context SOAP Body Name of Procedure Input parameter 1 Input parameter 2
31
InXML(arequest)
POST /StockQuote HTTP/1.1 Host: www.stockquoteserver.com Content-Type: text/xml; charset="utf-8" Content-Length: nnnn SOAPAction: "GetLastTradePrice" <SOAP-ENV:Envelope xmlns:SOAP-ENV= "http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle= "http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <m:GetLastTradePrice xmlns:m="Some-URI"> <symbol>DIS</symbol> </m:GetLastTradePrice> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Gustavo Alonso, D-INFK. ETH Zrich. 32
InXML(theresponse)
HTTP/1.1 200 OK Content-Type: text/xml; charset="utf-8" Content-Length: nnnn <SOAP-ENV:Envelope xmlns:SOAP-ENV= "http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle= "http://schemas.xmlsoap.org/soap/encoding/"/> <SOAP-ENV:Body> <m:GetLastTradePriceResponse xmlns:m="Some-URI"> <Price>34.5</Price> </m:GetLastTradePriceResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
33
Alltogether
HTTP Request SOAP Envelope SOAP header Transactional context SOAP Body Name of Procedure
SERVICE REQUESTER
SERVICE PROVIDER
Procedure
SOAP engine
HTTP Response SOAP Envelope SOAP header Transactional context SOAP Body Return parameter
SOAP engine
34
Additionalbindings(example)
SOAPoverJavaMessageService1.0RC1:
1 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 2 xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 3 xmlns:xsd="http://www.w3.org/2001/XMLSchema" 4 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 5 <soapenv:Body soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 6 <postMessage><ngName xsi:type="xsd:string">news.current.events</ngName> 7 <msg xsi:type="xsd:string">This is a sample news item.</msg> 8 </postMessage> 9 </soapenv:Body> 10 </soapenv:Envelope>
35
Additionalbindings
WSInvocationFramework UseWSDLtodescribeaservice UseWSIFtoletthesystemdecidewhattodowhenthe serviceisinvoked: IfthecallistoalocalEJBthendonothing IfthecallistoaremoteEJBthenuseRMI IfthecallistoaqueuethenuseJMS IfthecallistoaremoteWebservicethenuseSOAPand XML Thereisasingleinterfacedescription,thesystemdecides onthebinding Thistypeoffunctionalityisatthecoreofthenotionof ServiceOrientedArchitecture
36
SOAP Attachments
Theneedforattachments
SOAPisbasedonXMLand reliesonXMLfor representingdatatypes TheoriginalideainSOAP wastomakealldata exchangedexplicitinthe formofanXMLdocument muchlikewhathappens withIDLsinconventional middlewareplatforms Thisapproachreflectsthe implicitassumptionthat whatisbeingexchangedis similartoinputandoutput parametersofprogram invocations Thisapproachmakesitvery difficulttouseSOAPfor exchangingcomplexdata typesthatcannotbeeasily translatedtoXML(andthere isnoreasontodoso): images,binaryfiles, documents,proprietary representationformats, embeddedSOAPmessages, etc.
W3C December 2002 <env:Body> <p:itinerary xmlns:p="http://.../reservation/travel"> <p:departure> <p:departing>New York</p:departing> <p:arriving>Los Angeles</p:arriving> <p:depDate>2001-12-14</p:depDate> <p:depTime>late afternoon</p:depTime> <p:seatPreference>aisle</p:seatPreference> </p:departure> <p:return> <p:departing>Los Angeles</p:departing> <p:arriving>New York</p:arriving> <p:depDate>2001-12-20</p:depDate> <p:depTime>mid-morning</p:depTime> <p:seatPreference/> </p:return> </p:itinerary> </env:Body>
38
Apossiblesolution
ThereisaSOAPmessageswith attachmentsnoteproposedin 11.12.02thataddressesthis problem ItusesMIMEtypes(likee mails)anditisbasedin includingtheSOAPmessage intoaMIMEelementthat containsboththeSOAP messageandtheattachment (seenextpage) Thesolutionissimpleandit followsthesameapproachas thattakeninemailmessages: includeareferenceandhave theactualattachmentatthe endofthemessage TheMIMEdocumentcanbe embeddedintoanHTTP requestinthesamewayasthe SOAPmessage
Problemswiththisapproach: handlingthemessageimplies draggingtheattachmentalong, whichcanhaveperformance implicationsforlargemessages scalabilitycanbeseriously affectedastheattachmentis sentinonego(nostreaming) notallSOAPimplementations supportattachments SOAPenginesmustbe extendedtodealwithMIME types(nottoocomplexbutit addsoverhead) Therearealternativeproposals likeDIMEofMicrosoft(Direct InternetMessageEncapsulation) andWSattachments
39
AttachmentsinSOAP
From SOAP Messages with Attachments. W3C Note 11 December 2000
MIME-Version: 1.0 Content-Type: Multipart/Related; boundary=MIME_boundary; type=text/xml; start="<claim061400a.xml@claiming-it.com>" Content-Description: This is the optional message description. --MIME_boundary Content-Type: text/xml; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-ID: <claim061400a.xml@claiming-it.com>
SOAP Message <?xml version='1.0' ?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body> .. <theSignedForm href="cid:claim061400a.tiff@claiming-it.com"/> .. Reference </SOAP-ENV:Body> </SOAP-ENV:Envelope> --MIME_boundary Content-Type: image/tiff Content-Transfer-Encoding: binary Content-ID: <claim061400a.tiff@claiming-it.com> ATTACHMENT
Theproblemswithattachments
Attachmentsarerelativelyeasytoincludeinamessageandall proposals(MIMEorDIMEbased)aresimilarinspirit Thedifferencesareinthewaydataisstreamedfromthesendertothe receiverandhowthesedifferencesaffectefficiency MIMEisoptimizedforthesenderbutthereceiverhasnoideaof howbigamessageitisreceivingasMIMEdoesnotincludemessage lengthforthepartsitcontains thismaycreateproblemswithbuffersandmemoryallocation italsoforcesthereceivertoparsetheentiremessageinsearchfor theMIMEboundariesbetweenthedifferentparts(DIMEexplicitly specifiesthelengthofeachpartwhichcanbeusetoskipwhatisnot relevant) AlltheseproblemscanbesolvedwithMIMEasitprovidesmechanisms foraddingpartlengthsanditcouldconceivablybeextendedtosupport somebasicformofstreaming Technically,thesearenotveryrelevantissuesandhavemoretodowith marketingandcontrolofthestandards Therealimpactofattachmentsliesonthespecificationoftheinterface ofWebservices(howtomodelattachmentsinWSDL?)
41
SOAPandtheclientservermodel
ThecloserelationbetweenSOAP,RPCandHTTPhastwomainreasons: SOAPhasbeeninitiallydesignedforclientservertypeofinteraction whichistypicallyimplementedasRPCorvariationsthereof RPC,SOAPandHTTPfollowverysimilarmodelsofinteractionthatcan beveryeasilymappedintoeachother(andthisiswhatSOAPhasdone) TheadvantagesofSOAParisefromitsabilitytoprovideauniversalvehicle forconveyinginformationacrossheterogeneousmiddlewareplatformsand applications.Inthisregard,SOAPwillplayacrucialroleinenterprise applicationintegrationeffortsinthefutureasitprovidesthestandardthat hasbeenmissingalltheseyears ThelimitationsofSOAParisefromitsadherencetotheclientservermodel: dataexchangesasparametersinmethodinvocations rigidinteractionpatternsthatarehighlysynchronous andfromitssimplicity: SOAPisnotenoughinarealapplication,manyaspectsaremissing
43
AfirstuseofSOAP
Someofthefirstsystemsto incorporateSOAPasanaccess methodhavebeendatabases.The processisextremelysimple: client astoredprocedureis essentiallyanRPCinterface Webservice=stored procedure IDLforstoredprocedure= translatedintoWSDL calltoWebservice=useSOAP enginetomaptocalltostored procedure Thisusedemonstrateshowwell SOAPfitswithconventional middlewarearchitecturesand interfaces.Itisjustanatural extensiontothem
Web services interfaces HTTP engine XML mapping HTTP wrapping SOAP engine stored procedure API
Stored procedure interfaces
database
resource manager
external application
SOAPSummary
SOAP,initscurrentform,providesa basicmechanismfor: encapsulatingmessagesintoan XMLdocument mappingtheXMLdocument withtheSOAPmessageintoan HTTPrequest transformingRPCcallsinto SOAPmessages simplerulesonhowtoprocess aSOAPmessage(rulesbecame morepreciseand comprehensiveinv1.2ofthe specification) SOAPisaverysimpleprotocol intendedfortransferringdatafrom onemiddlewareplatformto another.Inspiteofitsclaimstobe open(whicharetrue),current specificationsandimplementations areverytiedtoRPCandHTTP.
SOAPtakesadvantageofthe standardizationofXMLtoresolve problemsofdatarepresentation andserialization(itusesXML Schematorepresentdataanddata structures,anditalsorelieson XMLforserializingthedatafor transmission).AsXMLbecomes morepowerfulandadditional standardsaroundXMLappear, SOAPcantakeadvantageofthem bysimplyindicatingwhatschema andencodingisusedaspartofthe SOAPmessage.Currentschema andencodingaregenericbutsoon therewillbeverticalstandards implementingschemasand encodingtailoredtoaparticular applicationarea(e.g.,theefforts aroundEDI)
45