Beruflich Dokumente
Kultur Dokumente
Lo que es SOAP?
SOAPesunacrnimodeSimpleObjectAccessProtocol.Setratadeunprotocolodemensajera
basadoenXMLparaelintercambiodeinformacinentrelosordenadores.SOAPesuna
aplicacindelaespecificacinXML.
http://www.w3ii.com/es/soap/soap_quick_guide.html 1/15
30/11/2016 SOAPGuarpida
NOTATodasestasespecificacionesestnsujetasacambios.Asquemantenerla
actualizacindesmismoconlasltimasespecificacionesdisponiblesenelsitiowebW3.
<?xmlversion="1.0"?>
<SOAPENV:Envelopexmlns:SOAPENV="http://www.w3.org/2001/12/soapenvelope"SOAPENV:encodin
<SOAPENV:Header>
...
...
</SOAPENV:Header>
<SOAPENV:Body>
...
...
<SOAPENV:Fault>
...
...
</SOAPENV:Fault>
</SOAPENV:Body>
</SOAP_ENV:Envelope>
LaenvolventecambiacuandocambianlasversionesSOAP.
LaenvolturaSOAPseespecificautilizandoelprefijodeespaciodenombresENVyel
elementodesobres.
LacodificacindeSOAPopcionaltambinseespecificaelusodeunnombredeespaciode
nombresyelelementoencodingStyleopcional,quetambinpodraapuntaraunestilode
codificacindistintadeladeSOAPuno.
UnprocesadordeSOAPv1.1compatiblegeneraunfalloalrecibirunmensajequecontiene
elespaciodenombressobrev1.2.
UnprocesadordeSOAPv1.2compatiblegeneraunfalloVersionMismatchsirecibeun
mensajedequenoincluyeelespaciodenombressobrev1.2.
<?xmlversion="1.0"?>
<SOAPENV:Envelopexmlns:SOAPENV="http://www.w3.org/2001/12/soapenvelope"SOAPENV:encodin
...
Messageinformationgoeshere
...
</SOAPENV:Envelope>
POST/OrderEntryHTTP/1.1
Host:www.w3ii.com
ContentType:application/soap;charset="utf8"
ContentLength:nnnn
<?xmlversion="1.0"?>
<SOAPENV:Envelopexmlns:SOAPENV="http://www.w3.org/2001/12/soapenvelope"SOAPENV:encodin
...
Messageinformationgoeshere
...
</SOAPENV:Envelope>
http://www.w3ii.com/es/soap/soap_quick_guide.html 3/15
30/11/2016 SOAPGuarpida
NOTALauninespecificalaubicacindelservicioHTTP.
atributo Actor
ElprotocoloSOAPdefineunavademensajecomounalistadenodosdeservicioSOAP.Cada
unodeestosnodosintermediospuederealizaralgnprocesamientoyluegoreenviarelmensaje
alsiguientenodoenlacadena.AlestablecerelatributoActor,elclientepuedeespecificarel
destinatariodelacabeceraSOAP.
MustUnderstand atributo
Seindicasiunelementodecabeceraesopcionaluobligatorio.Siesverdadero,elreceptordebe
entenderyprocesarelatributocolectorasegnsusemnticadefinidas,odevolverunerror.
ElsiguienteejemplomuestracmoutilizarunencabezadoenunmensajeSOAP.
<?xmlversion="1.0"?>
<SOAPENV:Envelopexmlns:SOAPENV="http://www.w3.org/2001/12/soapenvelope"SOAPENV:encodi
http://www.w3ii.com/es/soap/soap_quick_guide.html 4/15
30/11/2016 SOAPGuarpida
<SOAPENV:Header>
<t:Transactionxmlns:t="http://www.w3ii.com/transaction/"SOAPENV:mustUnderstand="tru
</SOAPENV:Header>
...
...
</SOAPENV:Envelope>
<?xmlversion="1.0"?>
<SOAPENV:Envelope>
........
<SOAPENV:Body>
<m:GetQuotationxmlns:m="http://www.tp.com/Quotation">
<m:Item>Computers</m:Item>
</m:GetQuotation>
</SOAPENV:Body>
</SOAPENV:Envelope>
Elejemploanteriorsolicitaunaofertadejuegosdeordenador.Tengaencuentaqueelm:
GetQuotationyloselementosdelartculoarribasonelementosespecficosdelaaplicacin.No
sonunapartedelanormaSOAP.
Aquestlarespuestaalaconsultaanterior
<?xmlversion="1.0"?>
<SOAPENV:Envelope>
........
<SOAPENV:Body>
<m:GetQuotationResponsexmlns:m="http://www.tp.com/Quotation">
<m:Quotation>ThisisQutation</m:Quotation>
http://www.w3ii.com/es/soap/soap_quick_guide.html 5/15
30/11/2016 SOAPGuarpida
</m:GetQuotationResponse>
</SOAPENV:Body>
</SOAPENV:Envelope>
Normalmente,laaplicacintambindefineunesquemaparacontenersemnticaasociadacon
loselementosdesolicitudyrespuesta.
ElserviciodecitapodraserimplementadousandounEJBseejecutaenunservidorde
aplicacionesencasoafirmativo,elprocesadordeSOAPseraresponsabledelacartografadela
informacincuerpocomoparmetrosdeentradaysalidadelaaplicacinEJBdel
servicioGetQuotationResponse.ElprocesadordeSOAPtambinpodraserelmapeodela
informacindecuerpoaunobjeto.NET,unobjetoCORBA,unprogramaCOBOL,yas
sucesivamente.
Subelemento Descripcin
<FaultCode> Esuncdigodetextoseutilizaparaindicaruna
clasedeerrores.Consultelasiguientetabla
paraobtenerunalistadeloscdigosdeerror
predefinidos.
<FaultString> Esunmensajedetextoqueexplicaelerror.
http://www.w3ii.com/es/soap/soap_quick_guide.html 6/15
30/11/2016 SOAPGuarpida
<FaultActor> Esunacadenadetextoqueindicaquecausel
fallo.EstilsielmensajeSOAPviajaatravs
devariosnodosenelcaminodelmensaje
SOAP,yelclientetienequesaberqunodo
provocelerror.Unnodoquenoactacomoel
destinofinaldeberincluirun
elementofaultActor.
<Detalle> Esunelementoutilizadoparallevarmensajes
deerrorespecficosdelaaplicacin.Eldetalle
elementopuedecontenerelementos
secundariosdenominadosentradasdetalle.
Error Descripcin
DeSOAPENV: Sehanencontradounespaciodenombre
VersionMismatch novlidoparaelelementoSOAP.
DeSOAPENV: Unelementosecundarioinmediatodel
MustUnderstand elementodecabecera,conel
mustUnderstandatributoestablecidoen
"1",nofuecomprendido.
DeSOAPENV: Elmensajeseformdemanera
Cliente incorrectaocontieneinformacin
incorrecta.
DeSOAPENV: Hubounproblemaconelservidor,porlo
Servidor queelmensajenopudocontinuar.
<?xmlversion='1.0'encoding='UTF8'?>
http://www.w3ii.com/es/soap/soap_quick_guide.html 7/15
30/11/2016 SOAPGuarpida
<SOAPENV:Envelopexmlns:SOAPENV="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsi="htt
<SOAPENV:Body>
<SOAPENV:Fault>
<faultcodexsi:type="xsd:string">SOAPENV:Client</faultcode>
<faultstringxsi:type="xsd:string">
Failedtolocatemethod(ValidateCreditCard)inclass(examplesCreditCard)at/u
</faultstring>
</SOAPENV:Fault>
</SOAPENV:Body>
</SOAPENV:Envelope>
JABN Codificacin
JABNincluyeunconjuntointegradodenormasparalacodificacindelostiposdedatos.
PermitequeelmensajeSOAPparaindicarlostiposdedatosespecficos,talescomonmeros
enteros,flota,dobles,omatrices.
tiposdedatosdeSOAPsedividenendosgrandescategorastiposescalaresytiposde
compuestos.
tiposescalarescontienenexactamenteunvalorcomounapellido,elpreciooladescripcin
delproducto.
tiposcompuestoscontienenmltiplesvalores,comounaordendecompraounalistade
cotizacionesdebolsa.
tiposcompuestossesubdividenenlasmatricesyestructuras.
ElestilodecodificacindeunmensajeSOAPseestableceatravsdeSOAP
ENV:atributoencodingStyle.
ParautilizarlacodificacinSOAP1.1,utiliceel
valorhttp://schemas.xmlsoap.org/soap/encoding/
ParautilizarlacodificacinSOAP1.2,utiliceelvalorhttp://www.w3.org/2001/12/soap
encoding
ltimaespecificacinSOAPadoptatodoslostiposincorporadasdefinidasporelesquema
XML.Anas,SOAPmantienesupropiaconvencinparaladefinicindelasconstrucciones
noestandarizadasporelesquemaXML,talescomomatricesyreferencias.
Tipos escalares
http://www.w3ii.com/es/soap/soap_quick_guide.html 8/15
30/11/2016 SOAPGuarpida
Paralostiposescalares,SOAPadoptatodoslostipossimplesincorporadosespecificadosporla
especificacindeesquemaXML.Estoincluyecuerdas,flotadores,doblesyenteros.
Enlasiguientetablaseenumeranlosprincipalestipossimples,extradodelesquemaXMLParte
0Primerhttp://www.w3.org/TR/2000/WDxmlschema020000407/
TipossimplesincorporadosparaXMLSchema
Tiposimple Ejemplo(s)
cuerda Confirmaresteeselctrica.
booleano verdadero,falso,1,0.
flotador INF,1E4,0,0,12.78E2,12,INF,NaN.
doble INF,1E4,0,0,12.78E2,12,INF,NaN.
decimal 1.23,0,123,4,1000.00.
binario 100010
entero 126789,1,0,1,126,789.
nonPositiveInteger 126789,1,0.
negativeInteger 126789,1.
largo 1,12678967543233
int 1,126789675
corto 1,12678
byte 1,126
nonNegativeInteger 0,1,126789
UnsignedLong 0,12678967543233
unsignedInt 0,1267896754
unsignedShort 0,12678
unsignedByte 0,126
enteropositivo 1,126,789.
fecha 05/31/1999,05.
hora 13:20:00.000,13:20:00,000a05:00
http://www.w3ii.com/es/soap/soap_quick_guide.html 9/15
30/11/2016 SOAPGuarpida
Porejemplo,aquhayunarespuestaSOAPconuntipodedatosdouble
<?xmlversion='1.0'encoding='UTF8'?>
<SOAPENV:Envelopexmlns:SOAPENV="http://www.w3.org/2001/12/soapenvelope"xmlns:xsi="http:
<SOAPENV:Body>
<ns1:getPriceResponsexmlns:ns1="urn:examples:priceservice"SOAPENV:encodingStyle="h
<returnxsi:type="xsd:double">54.99</return>
</ns1:getPriceResponse>
</SOAPENV:Body>
</SOAPENV:Envelope>
tipos compuestos
matricesdeSOAPtienenunconjuntomuyespecficodereglas,lascualesrequierenquese
especifiquetantoeltipodeelementoytamaodelamatriz.JABNtambinescompatiblecon
matricesmultidimensionales,peronotodaslasimplementacionesdeSOAPadmitelafuncin
multidimensional.
Paracrearunamatriz,debeespecificarcomounxsi:tipodematriz.Lamatriztambindebe
incluirunatributoArrayType.Esteatributoesnecesarioespecificareltipodedatosparalos
elementoscontenidosyladimensin(s)delamatriz.
Porejemplo,elsiguienteatributoespecificaunconjuntode10valoresdobles
arrayType="xsd:double[10]"
Porelcontrario,elsiguienteatributoespecificaunamatrizbidimensionaldecadenas
arrayType="xsd:string[5,5]"
AquestunarespuestaSOAPmuestraconunamatrizdevaloresdobles
<?xmlversion='1.0'encoding='UTF8'?>
<SOAPENV:Envelopexmlns:SOAPENV="http://www.w3.org/2001/12/soapenvelope"xmlns:xsi="http:
<SOAPENV:Body>
<ns1:getPriceListResponsexmlns:ns1="urn:examples:pricelistservice"SOAPENV:encoding
<returnxmlns:ns2="http://www.w3.org/2001/09/soapencoding"xsi:type="ns2:Array"n
<itemxsi:type="xsd:double">54.99</item>
<itemxsi:type="xsd:double">19.99</item>
http://www.w3ii.com/es/soap/soap_quick_guide.html 10/15
30/11/2016 SOAPGuarpida
</return>
</ns1:getPriceListResponse>
</SOAPENV:Body>
</SOAPENV:Envelope>
Lasestructurascontienenvariosvalores,perocadaelementoseespecificaconunelementode
accesonico.Porejemplo,considereunelementodentrodeuncatlogodeproductos.Eneste
caso,laestructurapodracontenerunproductoSKU,nombredelproducto,ladescripcinyel
precio.AsescomounaestructuracomoserepresentaenunmensajeSOAP
<?xmlversion='1.0'encoding='UTF8'?>
<SOAPENV:Envelopexmlns:SOAPENV="http://www.w3.org/2001/12/soapenvelope"xmlns:xsi="http:
<SOAPENV:Body>
<ns1:getProductResponsexmlns:ns1="urn:examples:productservice"SOAPENV:encodingStyle
<returnxmlns:ns2="urn:examples"xsi:type="ns2:product">
<namexsi:type="xsd:string">RedHatLinux</name>
<pricexsi:type="xsd:double">54.99</price>
<descriptionxsi:type="xsd:string">
RedHatLinuxOperatingSystem
</description>
<SKUxsi:type="xsd:string">A358185</SKU>
</return>
</ns1:getProductResponse>
</SOAPENV:Body>
</SOAPENV:Envelope>
NOTAPorfavor,cuidardesangradoadecuadomientrasseescribeelcdigo
SOAP.Cadaelementodeunaestructuraseespecificaconunnombredeaccesonico.Por
ejemplo,elmensajeanteriorincluyecuatroelementosdedescriptordeaccesoelnombre,
precio,ladescripcinySKU.Cadaelementopuedetenersupropiotipodedatos.Porejemplo,el
nombreseespecificacomounacadena,mientrasqueelprecioseespecificacomodoble.
JABN Transporte
Eljabnnoestvinculadoaningnprotocolodetransporte.DeSOAPpuedesertransportadoa
travsdeSMTP,FTP,MQSeriesdeIBMoMicrosoftMessageQueuing(MSMQ).
especificacinSOAPincluyedetallessobreHTTPsolamente.HTTPsiguesiendoelprotocolode
transportedeSOAPmspopular.
http://www.w3ii.com/es/soap/soap_quick_guide.html 11/15
30/11/2016 SOAPGuarpida
urn:xmethodsBabelFish#BabelFish
InclusosielservidornorequiereunacabeceraSOAPActioncompleta,elclientedebeespecificar
unacadenavaca("")ounvalornulo.Porejemplo
SOAPAction:""
SOAPAction:
AquestunamuestradeenviadoatravsdeHTTPparaelserviciodetraduccindeBabelfish
XMethods
POST/perl/soaplite.cgiHTTP/1.0
Host:services.xmethods.com
ContentType:text/xml;charset=utf8
ContentLength:538
SOAPAction:"urn:xmethodsBabelFish#BabelFish"
<?xmlversion='1.0'encoding='UTF8'?>
<SOAPENV:Envelopexmlns:SOAPENV="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsi="htt
<SOAPENV:Body>
<ns1:BabelFishxmlns:ns1="urn:xmethodsBabelFish"SOAPENV:encodingStyle="http://schema
<translationmodexsi:type="xsd:string">en_fr</translationmode>
<sourcedataxsi:type="xsd:string">Hello,world!</sourcedata>
</ns1:BabelFish>
</SOAPENV:Body>
</SOAPENV:Envelope>
http://www.w3ii.com/es/soap/soap_quick_guide.html 12/15
30/11/2016 SOAPGuarpida
TengaencuentaeltipodecontenidoylacabeceraSOAPAction.Tambintengaencuentaqueel
mtodoBabelFishrequieredosparmetrosdetipoString.Elmododetraduccinen_frtraduce
delInglsalFrancs.
AquestlarespuestadeXMethods
HTTP/1.1200OK
Date:Sat,09Jun200115:01:55GMT
Server:Apache/1.3.14(Unix)tomcat/1.0PHP/4.0.1pl2
SOAPServer:SOAP::Lite/Perl/0.50
CacheControl:smaxage=60,proxyrevalidate
ContentLength:539
ContentType:text/xml
<?xmlversion="1.0"encoding="UTF8"?>
<SOAPENV:Envelopexmlns:SOAPENC="http://schemas.xmlsoap.org/soap/encoding/"SOAPENV:encod
<SOAPENV:Body>
<namesp1:BabelFishResponsexmlns:namesp1="urn:xmethodsBabelFish">
<returnxsi:type="xsd:string">Bonjour,monde!</return>
</namesp1:BabelFishResponse>
</SOAPENV:Body>
</SOAPENV:Envelope>
respuestasdeSOAPentregadasatravsdeHTTPestnobligadosaseguirlosmismoscdigos
deestadoHTTP.Porejemplo,uncdigodeestadode200OKindicaunarespuestacorrecta.Un
cdigodeestadode500Errorinternodelservidorindicaquehayunerrorenelservidoryquela
respuestaSOAPincluyeunelementodefalta.
Ejemplos de SOAP
Enelsiguienteejemplo,unasolicitudGetQuotationseenvaaunservidorSOAPsobreHTTP.La
solicitudtieneunparmetroQuotationName,yunacitasedevuelveenlarespuesta.
Elespaciodenombresparalafuncinsedefineenhttp://www.xyz.org/quotationdireccin.
AquestlasolicitudSOAP
POST/QuotationHTTP/1.0
Host:www.xyz.org
ContentType:text/xml;charset=utf8
ContentLength:nnn
<?xmlversion="1.0"?>
<SOAPENV:Envelopexmlns:SOAPENV="http://www.w3.org/2001/12/soapenvelope"SOAPENV:encodin
http://www.w3ii.com/es/soap/soap_quick_guide.html 13/15
30/11/2016 SOAPGuarpida
<SOAPENV:Bodyxmlns:m="http://www.xyz.org/quotations">
<m:GetQuotation>
<m:QuotationsName>MiscroSoft</m:QuotationsName>
</m:GetQuotation>
</SOAPENV:Body>
</SOAPENV:Envelope>
UnarespuestaSOAPcorrespondienteseparece
HTTP/1.0200OK
ContentType:text/xml;charset=utf8
ContentLength:nnn
<?xmlversion="1.0"?>
<SOAPENV:Envelopexmlns:SOAPENV="http://www.w3.org/2001/12/soapenvelope"SOAPENV:encodin
<SOAPENV:Bodyxmlns:m="http://www.xyz.org/quotation">
<m:GetQuotationResponse>
<m:Quotation>Hereisthequotation</m:Quotation>
</m:GetQuotationResponse>
</SOAPENV:Body>
</SOAPENV:Envelope>
Normas de SOAP
SOAP1.1sepresentoriginalmentealaW3Cenmayode2000.Oficialespeticionariosincluyen
grandescompaascomoMicrosoft,IBMyAriba,ylasempresasmspequeas,comoUserLand
SoftwareyDevelopMentor.
Enjuliode2001,elGrupodeTrabajodeProtocoloXMLdioaconocerun"borradordetrabajo"
deSOAP1.2.DentrodelW3C,estedocumentoesoficialmenteuntrabajoenprogreso,loque
significaqueeldocumentoesprobablequeseractualizadomuchasvecesantesdequese
finalice.
SOAPVersin1.1estdisponibleenlneaenhttp://www.w3.org/TR/SOAP/
ElborradordetrabajodelaversinSOAP1.2estdisponibleenhttp://www.w3.org/TR/soap12/
http://www.w3ii.com/es/soap/soap_quick_guide.html 14/15
30/11/2016 SOAPGuarpida
TengaencuentaqueelW3Ctambinalbergaunapresentacinde"LosmensajesSOAPcon
adjuntos",queseseparadelaespecificacinbsicadeSOAP.Estaespecificacinpermitealos
mensajesSOAPparaincluirarchivosadjuntosbinarios,comoimgenesyarchivosdesonido.
Paramsdetalles,verlaNotadelW3Cenhttp://www.w3.org/TR/SOAPattachments.
http://www.w3ii.com/es/soap/soap_quick_guide.html 15/15