¿QUE SON?
Un servicio web es una interfaz de software que describe un conjunto de operaciones a las cuales se puede acceder por la red a través de mensajería XML estandarizada. Usa protocolos basados en el lenguaje XML con el objetivo de describir una operación para ejecutar o datos para intercambiar con otro servicio web.
CARACTERÍSTICAS
Las características principales de los servicios Web, son las siguientes:
- Utilización de estándares de internet. La única forma para que los servicios Web sean utilizados por la cantidad de sistemas heterogéneos existentes en Internet es el empleo del protocolo de transferencia de datos HTTP utilizado por todos los navegadores Web y XML.
- Basados en tecnologías de paso de mensajes. La interacción entre el cliente y el proveedor del servicio es empaquetada en unidades autodesciptivas denominadas mensajes. Dicha interacción se describe en función de los mensajes intercambiados.
- Combinan lo mejor de la tecnología de componentes y de la tecnología Web. Los servicios Web presentan una funcionalidad de caja negra que puede ser reutilizada sin preocuparse de cómo es implementada y ello proporciona interfaces bien definidas.
TIPOS
Servicios Web SOAP
Los servicios Web SOAP, o servicios Web "big", utilizan mensajes XML para intercomunicarse que siguen el estándar SOAP (Simple Object Access Protocol), un lenguaje XML que define la arquitectura y formato de los mensajes. Dichos sistemas normalmente contienen una descripción legible por la máquina de la descripción de las operaciones ofrecidas por el servicio, escrita en WSDL (Web Services Description Language), que es un lenguaje basado en XML para definir las interfaces sintácticamente.
Servicios Web RESTful
Los servicios Web RESTful (Representational State Transfer Web Services) son adecuados para escenarios de integración básicos ad-hoc. Dichos servicios Web se suelen integrar mejor con HTTP que los servicios basado en SOAP, ya que no requieren mensajes XML o definciones del servicio en forma de fichero WSDL
ARQUITECTURA
Los servicios Web presentan una arquitectura orientada a servicios que permite crear una definición abstracta de un servicio, proporcionar una implementación concreta de dicho servicio, publicar y localizar un servicio, seleccionar un instancia de un servicio, y utilizar dicho servicio con una elevada interoperabilidad. Es posible desacoplar la implementación del servicio Web y su uso por parte de un cliente. También es posible desacoplar la implementación del servicio y de cliente. Las implementaciones concretas del servicio pueden desacoplarse a nivel de lógica y transporte. La siguiente figura muestra el diagrama de una arquitectura orientada a servicios.
El proveedor del servicio define la descripción abstracta de dicho servicio utilizando un lenguaje de descripción de Servicios Web (WSDL: Web Services Description Language: ). A continuación se crea un Servicio concreto a partir de la descripción abstracta del servicio, produciendo así una descripción concreta del servicio en WSDL. Dicha descripción concreta puede entonces publicarse en un servicio de registro como por ejemplo UDDI (Universal Description, Descovery and Integration). Un cliente de un servicio puede utilizar un servicio de registro para localizar una descripción de un servicio, a partir de la cual podrá seleccionar y utilizar una implementación concreta de dicho servicio.
EJEMPLO
Para poder llamar a un Web Service desde su servidor, si trabaja con ASP 3.0, necesita tener instalado el Parser MSXML de Microsoft, el cual viene integrado con Internet Explorer 5 y superiores.
En este ASP puede ver cómo se invoca la función pudiendo elegir qué es lo que queremos que muestre: el resultado formateado en HTML, en XML puro o mostrar el mensaje de llamada en XML.
<%
'Parametros de la funcion
'La direccion deberá tener al final los parametros. Ej: ?lengua=C&curso=2009-10&codasi=9240&orden=T
wlengua = "C" 'Request.QueryString("lengua")
wcurso = "2010-11" 'Request.QueryString("curso")
wcodasi = "9244" 'Request.QueryString("codasi")
worden = "T" 'Request.QueryString("orden")
if worden = "" then worden = "T"
if wlengua = "" then wlengua = "C"
funcion = "wshorarios"
clase = "ClaseHorarios"
namespace = "http://UASI/WS_GESTDOCENTE.wsdl"
endpoint = "https://cvnet.cpd.ua.es/servicioweb/publicos/pub_gestdocente.asmx"
action = "http://UASI/WS_GESTDOCENTE.wsdl/" & funcion
cadenaXML = "<?xml version=""1.0"" encoding=""utf-8""?>" & vbCrLf
cadenaXML = cadenaXML & " <SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"""
cadenaXML = cadenaXML & " SOAP-ENV:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"""
cadenaXML = cadenaXML & " xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"""
cadenaXML = cadenaXML & " xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">"
cadenaXML = cadenaXML & " <SOAP-ENV:Body>" & vbCrLf
cadenaXML = cadenaXML & " <" & funcion & " xmlns=""" & namespace & """>" & vbCrLf
cadenaXML = cadenaXML & " <plengua xsi:type=""xsd:string"">" & wlengua & "</plengua>" & vbCrLf
cadenaXML = cadenaXML & " <pcurso xsi:type=""xsd:string"">" & wcurso & "</pcurso>" & vbCrLf
cadenaXML = cadenaXML & " <pcodasi xsi:type=""xsd:string"">" & wcodasi & "</pcodasi>" & vbCrLf
cadenaXML = cadenaXML & " <porden xsi:type=""xsd:string"">" & worden & "</porden>" & vbCrLf
cadenaXML = cadenaXML & " </" & funcion & ">" & vbCrLf
cadenaXML = cadenaXML & " </SOAP-ENV:Body>" & vbCrLf
cadenaXML = cadenaXML & " </SOAP-ENV:Envelope>" & vbCrLf
Set objInputXMLDoc = Server.CreateObject("Microsoft.XMLDOM")
objInputXMLDoc.loadXML cadenaXML
Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXMLHTTP.open "POST", endpoint, false
objXMLHTTP.setRequestHeader "Content-Type", "text/xml"
objXMLHTTP.setRequestHeader "soapAction", action
objXMLHTTP.send objInputXMLDoc
'Cabeceras
if sLengua = "C" then
sTxtTeoPra = "T/P"
sTxtGrp = "Grupo"
sTxtFinicio = "Dia Inicio"
sTxtFfin = "Dia Finalización"
sTxtDia = "Dia Semana"
sTxtHinicio = "Hora inicio"
sTxtHfin = "Hora fin"
sTxtAula = "Aulas"
sTxtDescaul = "Nombre aula"
sTxtTipoAct = "Tipo actividad"
sTxtAct = "Actividad"
else
sTxtTeoPra = "T/P"
sTxtGrp = "Grup"
sTxtFinicio = "Dia d'Inicio"
sTxtFfin = "Dia Finalització"
sTxtDia = "Dia Setmana"
sTxtHinicio = "Hora d'inici"
sTxtHfin = "Hora finalització"
sTxtAula = "Aules"
sTxtDescaul = "Nom d'aula"
sTxtTipoAct = "Tipus activitat"
sTxtAct = "Activitat"
end if
response.write "<HTML><HEAD>" & vbCrLf
response.write "</HEAD><BODY>" & vbCrLf
Set objOutputXMLDoc = Server.CreateObject("Microsoft.XMLDOM")
objOutputXMLDoc.loadXML objXMLHTTP.responseText
Set Nodes = objOutputXMLDoc.getElementsByTagName("faultstring")
if Nodes.length>0 then
For Each Node In Nodes
p = Instr(Node.Text, "@@")
if p>0 then
E = Mid(Node.Text,p+2)
p = Instr(E, "@@")
E = Mid(E,1,p-1)
else
E = Node.Text
end if
next
response.write(E)
else
response.write "<TABLE>" & vbCrLf
response.write "<tbody>" & vbCrLf
response.write "<TR>" & vbCrLf
'Escribimos las cabeceras
if sOrden="T" then
response.write " <TH>" & sTxtTeoPra & "</TH>" & vbCrLf
response.write " <TH>" & sTxtGrp & "</TH>" & vbCrLf
response.write " <TH>" & sTxtFinicio & "</TH>" & vbCrLf
response.write " <TH>" & sTxtFfin & "</TH>" & vbCrLf
response.write " <TH>" & sTxtDia & "</TH>" & vbCrLf
response.write " <TH>" & sTxtHinicio & "</TH>" & vbCrLf
response.write " <TH>" & sTxtHfin & "</TH>" & vbCrLf
response.write " <TH>" & sTxtAula & "</TH>" & vbCrLf
response.write " <TH>" & sTxtTipoAct & "</TH>" & vbCrLf
response.write " <TH>" & sTxtAct & "</TH>" & vbCrLf
elseif sOrden = "G" then
response.write " <TH>" & sTxtGrp & "</TH>" & vbCrLf
response.write " <TH>" & sTxtFinicio & "</TH>" & vbCrLf
response.write " <TH>" & sTxtFfin & "</TH>" & vbCrLf
response.write " <TH>" & sTxtDia & "</TH>" & vbCrLf
response.write " <TH>" & sTxtHinicio & "</TH>" & vbCrLf
response.write " <TH>" & sTxtHfin & "</TH>" & vbCrLf
response.write " <TH>" & sTxtTeoPra & "</TH>" & vbCrLf
response.write " <TH>" & sTxtAula & "</TH>" & vbCrLf
response.write " <TH>" & sTxtTipoAct & "</TH>" & vbCrLf
response.write " <TH>" & sTxtAct & "</TH>" & vbCrLf
else
response.write " <TH>" & sTxtFinicio & "</TH>" & vbCrLf
response.write " <TH>" & sTxtFfin & "</TH>" & vbCrLf
response.write " <TH>" & sTxtDia & "</TH>" & vbCrLf
response.write " <TH>" & sTxtHinicio & "</TH>" & vbCrLf
response.write " <TH>" & sTxtHfin & "</TH>" & vbCrLf
response.write " <TH>" & sTxtGrp & "</TH>" & vbCrLf
response.write " <TH>" & sTxtTeoPra & "</TH>" & vbCrLf
response.write " <TH>" & sTxtAula & "</TH>" & vbCrLf
response.write " <TH>" & sTxtTipoAct & "</TH>" & vbCrLf
response.write " <TH>" & sTxtAct & "</TH>" & vbCrLf
end if
response.write "</TR>" & vbCrLf
Set Nodes = objOutputXMLDoc.getElementsByTagName(clase)
For Each Node In Nodes
pTeopra = Node.selectSingleNode("teopra").Text
pCodgrp = Node.selectSingleNode("codgrp").Text
pFechainicio = Node.selectSingleNode("fechainicio").Text
pFechafin = Node.selectSingleNode("fechafin").Text
pDia = Node.selectSingleNode("dia").Text
pDiasemana = Node.selectSingleNode("diasemana").Text
pHoraini = Node.selectSingleNode("horaini").Text
pHorafin = Node.selectSingleNode("horafin").Text
pAula = Node.selectSingleNode("aula").Text
pDescaula = Node.selectSingleNode("descaula").Text
pAulasig = Node.selectSingleNode("aulasig").Text
pclase_activ = Node.selectSingleNode("clase_activ").Text
pdesc_activ = Node.selectSingleNode("descactiv").Text
response.write "<TR>" & vbCrLf
response.Write "<td>" & pTeopra & "</td>"
response.Write "<td>" & pTeopra & "</td>"
response.Write "<td>" & pCodgrp & "</td>"
response.Write "<td>" & pFechainicio & "</td>"
response.Write "<td>" & pFechafin & "</td>"
response.Write "<td>" & pDia & "</td>"
response.Write "<td>" & pDiasemana & "</td>"
response.Write "<td>" & pHoraini & "</td>"
response.Write "<td>" & pHorafin & "</td>"
response.Write "<td>" & pAula & "</td>"
response.Write "<td>" & pDescaula & "</td>"
response.Write "<td>" & pAulasig & "</td>"
response.Write "<td>" & pclase_activ & "</td>"
response.Write "<td>" & pdesc_activ & "</td>"
response.write "</TR>" & vbCrLf
next
response.write "</tbody>" & vbCrLf
response.write "</TABLE>" & vbCrLf
end if
response.write "</BODY>" & vbCrLf
response.write "</HTML>" & vbCrLf
%>
<%
'Parametros de la funcion
'La direccion deberá tener al final los parametros. Ej: ?lengua=C&curso=2009-10&codasi=9240&orden=T
wlengua = "C" 'Request.QueryString("lengua")
wcurso = "2010-11" 'Request.QueryString("curso")
wcodasi = "9244" 'Request.QueryString("codasi")
worden = "T" 'Request.QueryString("orden")
if worden = "" then worden = "T"
if wlengua = "" then wlengua = "C"
funcion = "wshorarios"
clase = "ClaseHorarios"
namespace = "http://UASI/WS_GESTDOCENTE.wsdl"
endpoint = "https://cvnet.cpd.ua.es/servicioweb/publicos/pub_gestdocente.asmx"
action = "http://UASI/WS_GESTDOCENTE.wsdl/" & funcion
cadenaXML = "<?xml version=""1.0"" encoding=""utf-8""?>" & vbCrLf
cadenaXML = cadenaXML & " <SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"""
cadenaXML = cadenaXML & " SOAP-ENV:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"""
cadenaXML = cadenaXML & " xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"""
cadenaXML = cadenaXML & " xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">"
cadenaXML = cadenaXML & " <SOAP-ENV:Body>" & vbCrLf
cadenaXML = cadenaXML & " <" & funcion & " xmlns=""" & namespace & """>" & vbCrLf
cadenaXML = cadenaXML & " <plengua xsi:type=""xsd:string"">" & wlengua & "</plengua>" & vbCrLf
cadenaXML = cadenaXML & " <pcurso xsi:type=""xsd:string"">" & wcurso & "</pcurso>" & vbCrLf
cadenaXML = cadenaXML & " <pcodasi xsi:type=""xsd:string"">" & wcodasi & "</pcodasi>" & vbCrLf
cadenaXML = cadenaXML & " <porden xsi:type=""xsd:string"">" & worden & "</porden>" & vbCrLf
cadenaXML = cadenaXML & " </" & funcion & ">" & vbCrLf
cadenaXML = cadenaXML & " </SOAP-ENV:Body>" & vbCrLf
cadenaXML = cadenaXML & " </SOAP-ENV:Envelope>" & vbCrLf
Set objInputXMLDoc = Server.CreateObject("Microsoft.XMLDOM")
objInputXMLDoc.loadXML cadenaXML
Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXMLHTTP.open "POST", endpoint, false
objXMLHTTP.setRequestHeader "Content-Type", "text/xml"
objXMLHTTP.setRequestHeader "soapAction", action
objXMLHTTP.send objInputXMLDoc
'Cabeceras
if sLengua = "C" then
sTxtTeoPra = "T/P"
sTxtGrp = "Grupo"
sTxtFinicio = "Dia Inicio"
sTxtFfin = "Dia Finalización"
sTxtDia = "Dia Semana"
sTxtHinicio = "Hora inicio"
sTxtHfin = "Hora fin"
sTxtAula = "Aulas"
sTxtDescaul = "Nombre aula"
sTxtTipoAct = "Tipo actividad"
sTxtAct = "Actividad"
else
sTxtTeoPra = "T/P"
sTxtGrp = "Grup"
sTxtFinicio = "Dia d'Inicio"
sTxtFfin = "Dia Finalització"
sTxtDia = "Dia Setmana"
sTxtHinicio = "Hora d'inici"
sTxtHfin = "Hora finalització"
sTxtAula = "Aules"
sTxtDescaul = "Nom d'aula"
sTxtTipoAct = "Tipus activitat"
sTxtAct = "Activitat"
end if
response.write "<HTML><HEAD>" & vbCrLf
response.write "</HEAD><BODY>" & vbCrLf
Set objOutputXMLDoc = Server.CreateObject("Microsoft.XMLDOM")
objOutputXMLDoc.loadXML objXMLHTTP.responseText
Set Nodes = objOutputXMLDoc.getElementsByTagName("faultstring")
if Nodes.length>0 then
For Each Node In Nodes
p = Instr(Node.Text, "@@")
if p>0 then
E = Mid(Node.Text,p+2)
p = Instr(E, "@@")
E = Mid(E,1,p-1)
else
E = Node.Text
end if
next
response.write(E)
else
response.write "<TABLE>" & vbCrLf
response.write "<tbody>" & vbCrLf
response.write "<TR>" & vbCrLf
'Escribimos las cabeceras
if sOrden="T" then
response.write " <TH>" & sTxtTeoPra & "</TH>" & vbCrLf
response.write " <TH>" & sTxtGrp & "</TH>" & vbCrLf
response.write " <TH>" & sTxtFinicio & "</TH>" & vbCrLf
response.write " <TH>" & sTxtFfin & "</TH>" & vbCrLf
response.write " <TH>" & sTxtDia & "</TH>" & vbCrLf
response.write " <TH>" & sTxtHinicio & "</TH>" & vbCrLf
response.write " <TH>" & sTxtHfin & "</TH>" & vbCrLf
response.write " <TH>" & sTxtAula & "</TH>" & vbCrLf
response.write " <TH>" & sTxtTipoAct & "</TH>" & vbCrLf
response.write " <TH>" & sTxtAct & "</TH>" & vbCrLf
elseif sOrden = "G" then
response.write " <TH>" & sTxtGrp & "</TH>" & vbCrLf
response.write " <TH>" & sTxtFinicio & "</TH>" & vbCrLf
response.write " <TH>" & sTxtFfin & "</TH>" & vbCrLf
response.write " <TH>" & sTxtDia & "</TH>" & vbCrLf
response.write " <TH>" & sTxtHinicio & "</TH>" & vbCrLf
response.write " <TH>" & sTxtHfin & "</TH>" & vbCrLf
response.write " <TH>" & sTxtTeoPra & "</TH>" & vbCrLf
response.write " <TH>" & sTxtAula & "</TH>" & vbCrLf
response.write " <TH>" & sTxtTipoAct & "</TH>" & vbCrLf
response.write " <TH>" & sTxtAct & "</TH>" & vbCrLf
else
response.write " <TH>" & sTxtFinicio & "</TH>" & vbCrLf
response.write " <TH>" & sTxtFfin & "</TH>" & vbCrLf
response.write " <TH>" & sTxtDia & "</TH>" & vbCrLf
response.write " <TH>" & sTxtHinicio & "</TH>" & vbCrLf
response.write " <TH>" & sTxtHfin & "</TH>" & vbCrLf
response.write " <TH>" & sTxtGrp & "</TH>" & vbCrLf
response.write " <TH>" & sTxtTeoPra & "</TH>" & vbCrLf
response.write " <TH>" & sTxtAula & "</TH>" & vbCrLf
response.write " <TH>" & sTxtTipoAct & "</TH>" & vbCrLf
response.write " <TH>" & sTxtAct & "</TH>" & vbCrLf
end if
response.write "</TR>" & vbCrLf
Set Nodes = objOutputXMLDoc.getElementsByTagName(clase)
For Each Node In Nodes
pTeopra = Node.selectSingleNode("teopra").Text
pCodgrp = Node.selectSingleNode("codgrp").Text
pFechainicio = Node.selectSingleNode("fechainicio").Text
pFechafin = Node.selectSingleNode("fechafin").Text
pDia = Node.selectSingleNode("dia").Text
pDiasemana = Node.selectSingleNode("diasemana").Text
pHoraini = Node.selectSingleNode("horaini").Text
pHorafin = Node.selectSingleNode("horafin").Text
pAula = Node.selectSingleNode("aula").Text
pDescaula = Node.selectSingleNode("descaula").Text
pAulasig = Node.selectSingleNode("aulasig").Text
pclase_activ = Node.selectSingleNode("clase_activ").Text
pdesc_activ = Node.selectSingleNode("descactiv").Text
response.write "<TR>" & vbCrLf
response.Write "<td>" & pTeopra & "</td>"
response.Write "<td>" & pTeopra & "</td>"
response.Write "<td>" & pCodgrp & "</td>"
response.Write "<td>" & pFechainicio & "</td>"
response.Write "<td>" & pFechafin & "</td>"
response.Write "<td>" & pDia & "</td>"
response.Write "<td>" & pDiasemana & "</td>"
response.Write "<td>" & pHoraini & "</td>"
response.Write "<td>" & pHorafin & "</td>"
response.Write "<td>" & pAula & "</td>"
response.Write "<td>" & pDescaula & "</td>"
response.Write "<td>" & pAulasig & "</td>"
response.Write "<td>" & pclase_activ & "</td>"
response.Write "<td>" & pdesc_activ & "</td>"
response.write "</TR>" & vbCrLf
next
response.write "</tbody>" & vbCrLf
response.write "</TABLE>" & vbCrLf
end if
response.write "</BODY>" & vbCrLf
response.write "</HTML>" & vbCrLf
%>
No hay comentarios:
Publicar un comentario