Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this document? Why not share!

WebServices/webServices.docx (1/14/2009 7:07 - LaSalleChihuahua ...

on

  • 2,151 views

 

Statistics

Views

Total Views
2,151
Views on SlideShare
2,151
Embed Views
0

Actions

Likes
0
Downloads
80
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

WebServices/webServices.docx (1/14/2009 7:07 - LaSalleChihuahua ... WebServices/webServices.docx (1/14/2009 7:07 - LaSalleChihuahua ... Document Transcript

  • 14/Noviembre/2008<br />I T E S M<br />Programación Avanzada Web<br />Web services<br />A00385674<br />MCE<br />Guerrero<br />Cortazar<br />Juan Carlos<br />Introducción<br />Un webService no es más que una función en protocolo HTTP.<br />Un WebService está compuesto por:<br />SOAP (Simple Object Access Protocol) <br />SOAP stands for Simple Object Access Protocol <br />SOAP is a communication protocol <br />SOAP is for communication between applications <br />SOAP is a format for sending messages <br />SOAP communicates via Internet <br />SOAP is platform independent <br />SOAP is language independent <br />SOAP is based on XML <br />SOAP is simple and extensible <br />SOAP allows you to get around firewalls <br />SOAP is a W3C recommendation <br />Sintaxis:<br /><?xml version=" 1.0" ?><br /><soap:Envelope<br />xmlns:soap=" http://www.w3.org/2001/12/soap-envelope" <br />soap:encodingStyle=" http://www.w3.org/2001/12/soap-encoding" ><br /><soap:Header><br /> ...<br /> ...<br /></soap:Header><br /><soap:Body><br /> ...<br /> ...<br /> <soap:Fault><br /> ...<br /> ...<br /> </soap:Fault><br /></soap:Body><br /></soap:Envelope><br />WSDL (Web Services Description Language).<br />WSDL stands for Web Services Description Language <br />WSDL is written in XML <br />WSDL is an XML document <br />WSDL is used to describe Web services <br />WSDL is also used to locate Web services <br />WSDL is a W3C recommendation <br />Sample:<br /><definitions><br /><types><br /> definition of types........<br /></types><br /><message><br /> definition of a message....<br /></message><br /><portType><br /> definition of a port.......<br /></portType><br /><binding><br /> definition of a binding....<br /></binding><br /></definitions><br />UDDI (Universal Description, Discovery and Integration) <br />UDDI is a directory service where businesses can register and search for Web services.<br />UDDI stands for Universal Description, Discovery and Integration <br />UDDI is a directory for storing information about web services <br />UDDI is a directory of web service interfaces described by WSDL <br />UDDI communicates via SOAP <br />UDDI is built into the Microsoft .NET platform <br />Sintaxis:<br /><wsdl:definitions name=" nmtoken" ? targetNamespace=" uri" ><br /> <import namespace=" uri" location=" uri" /> *<br /> <wsdl:documentation .... /> ?<br /> <wsdl:types> ?<br /> <wsdl:documentation .... /> ?<br /> <xsd:schema .... /> *<br /> </wsdl:types><br /> <wsdl:message name=" ncname" > *<br /> <wsdl:documentation .... /> ?<br /> <part name=" ncname" element=" qname" ? type=" qname" ?/> *<br /> </wsdl:message><br /> <wsdl:portType name=" ncname" > *<br /> <wsdl:documentation .... /> ?<br /> <wsdl:operation name=" ncname" > *<br /> <wsdl:documentation .... /> ?<br /> <wsdl:input message=" qname" > ?<br /> <wsdl:documentation .... /> ?<br /> </wsdl:input><br /> <wsdl:output message=" qname" > ?<br /> <wsdl:documentation .... /> ?<br /> </wsdl:output><br /> <wsdl:fault name=" ncname" message=" qname" >*<br /> <wsdl:documentation .... /> ?<br /> </wsdl:fault><br /> </wsdl:operation><br /> </wsdl:portType><br /> <wsdl:serviceType name=" ncname" > *<br /> <wsdl:portType name=" qname" /> +<br /> </wsdl:serviceType><br /> <wsdl:binding name=" ncname" type=" qname" > *<br /> <wsdl:documentation .... /> ?<br /> <-- binding details --> *<br /> <wsdl:operation name=" ncname" > *<br /> <wsdl:documentation .... /> ?<br /> <-- binding details --> *<br /> <wsdl:input> ?<br /> <wsdl:documentation .... /> ?<br /> <-- binding details --><br /> </wsdl:input><br /> <wsdl:output> ?<br /> <wsdl:documentation .... /> ?<br /> <-- binding details --> *<br /> </wsdl:output><br /> <wsdl:fault name=" ncname" > *<br /> <wsdl:documentation .... /> ?<br /> <-- binding details --> *<br /> </wsdl:fault><br /> </wsdl:operation><br /> </wsdl:binding><br /> <wsdl:service name=" ncname" serviceType=" qname" > *<br /> <wsdl:documentation .... /> ?<br /> <wsdl:port name=" ncname" binding=" qname" > *<br /> <wsdl:documentation .... /> ?<br /> <-- address details --><br /> </wsdl:port><br /> </wsdl:service><br /></wsdl:definitions><br />Ejemplos<br />SOAP:<br />Request<br /><?xml version=" 1.0" ?><br /><soap:Envelope<br />xmlns:soap=" http://www.w3.org/2001/12/soap-envelope" (ESTANDAR W3)<br />soap:encodingStyle=" http://www.w3.org/2001/12/soap-encoding" ><br /> <soap:Body xmlns:m=" http://-URL-/SOAPapp" ><br />   <m:GetData><br /> <m:DataName>IBM</m:DataName><br />    </m:GetData><br /> </soap:Body><br /></soap:Envelope><br />Response<br /><?xml version=" 1.0" ?><br /><soap:Envelope<br />xmlns:soap=http://www.w3.org/2001/12/soap-envelope (ESTANDAR W3)<br />soap:encodingStyle=" http://www.w3.org/2001/12/soap-encoding" > <br /> <soap:Body xmlns:m=" http://-URL-/SOAPapp" ><br /> <m:GetDataResponse><br /> <m:Data>34.5</m:Data><br /> </m:GetDataResponse><br /> </soap:Body><br /></soap:Envelope><br />WDSL ligado a SOAP:<br /><message name=" getTermRequest" ><br /> <part name=" term" type=" xs:string" /><br /></message><br /><message name=" getTermResponse" ><br /> <part name=" value" type=" xs:string" /><br /></message><br /><portType name=" glossaryTerms" > <operation name=" getTerm" > <input message=" getTermRequest" /> <output message=" getTermResponse" /> </operation></portType><br /><binding type=" glossaryTerms" name=" b1" ><br /><soap:binding style=" document" <br />transport=" http://schemas.xmlsoap.org/soap/http" /><br /> <operation><br /> <soap:operation soapAction=" http://example.com/getTerm" /><br /> <input><br /> <soap:body use=" literal" /><br /> </input><br /> <output><br /> <soap:body use=" literal" /><br /> </output><br /> </operation><br /></binding><br />UDDI:<br />Archivo Service.disco<br /><?xml version=" 1.0" encoding=" utf-8" ?><br /><discovery xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=" http://www.w3.org/2001/XMLSchema" xmlns=" http://schemas.xmlsoap.org/disco/" ><br /> <contractRef ref=" http:// -URL-/SiteWebService/Service.asmx?wsdl" docRef=" http://localhost/SiteWebService/Service.asmx" xmlns=" http://schemas.xmlsoap.org/disco/scl/" /><br /> <soap address=" http:// -URL-/SiteWebService/Service.asmx" xmlns:q1=" http://tempuri.org/" binding=" q1:ServiceSoap" xmlns=" http://schemas.xmlsoap.org/disco/soap/" /><br /> <soap address=" http://-URL-/SiteWebService/Service.asmx" xmlns:q2=" http://tempuri.org/" binding=" q2:ServiceSoap12" xmlns=" http://schemas.xmlsoap.org/disco/soap/" /><br /></discovery><br />Archivo Service.discomap<br /><?xml version=" 1.0" encoding=" utf-8" ?><br /><DiscoveryClientResultsFile xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd=" http://www.w3.org/2001/XMLSchema" ><br /> <Results><br /> <DiscoveryClientResult referenceType=" System.Web.Services.Discovery.DiscoveryDocumentReference" url=" http://-URL-/SiteWebService/Service.asmx?disco" filename=" Service.disco" /><br /> <DiscoveryClientResult referenceType=" System.Web.Services.Discovery.ContractReference" url=" http://-URL-/SiteWebService/Service.asmx?wsdl" filename=" Service.wsdl" /><br /> </Results><br /></DiscoveryClientResultsFile><br />Desarrollo<br />SOAP permite dar responses como las que regresa un web server a un servicio (200, 401, 500, 503, etc.), pero entre aplicaciones para poder pasar información entre ellas sin necesidad de implementaciones robustas o dependiendo de la tecnología plenamente.<br />WSDL: Le da forma a SOAP para ser empleado como WebService (XSD: Schema Definition)<br />UDDI: Servicio de registro y búsqueda de otros webServices para las empresas<br />¿Que tan poderoso llegará a ser el webService como recurso? <br />Tanto como vaya creciendo la funcionalidad de SOAP, sobre todo en seguridad.<br />¿Quiénes manejan WebServices?<br />4482465361950MicroSoft .net framework en IIS<br />El IDE de VS es completamente amigable para el desarrollo de webServices. Hace que un webService en realidad suene atractivo y no aterrador, como con otras tecnologías e IDEs, ya que el desarrollo de las aplicaciones completamente a pie: definición del SOAP, definición del WSDL, UDDI aunque este último es opcional; y todo esto y siquiera hemos comenzado con la función en sí!!!<br />El IDE de VS solo genera el archivo que abstractiza la implementación del wervicio (archivos .asmx) ya que este solo tiene una referencia al archivo que contiene el código que se emplea en cada una de las funciones:<br />http://URL/aplicación/servicio.asmx/método<br />Así mismo, a través de los dataSets, la abstractización de los datos en repositorios es sumamente sencilla. Básicamente solo se debe preocupar uno de la aplicación en sí que queremos publicar.<br />De igual forma, a la hora de desarrollar el cliente, solo se tiene que apuntalar a el servicio que se desea consumir, y el IDE genera automáticamente todo el WSDL e incluso los UDDI necesarios para garantizar la buena comunicación con este servicio.<br />Finalmente para emplear el servicio, solo es necesario usar el servicio.método como una clase más dentro de la aplicación.<br />Ejemplo de código Visual Basic .net 2005<br />Imports System.Web<br />Imports System.Web.Services<br />Imports System.Web.Services.Protocols<br />Imports DataSetProducto<br />Imports DataSetProductoTableAdapters<br /><WebService(Namespace:=" http://tempuri.org/" )> _<br /><WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _<br /><Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _<br />Public Class Service<br /> Inherits System.Web.Services.WebService<br /> Dim TAProductos As New ProductosTableAdapter<br /> Dim DTProductos As ProductosDataTable<br /> Dim resultado As String<br /> <WebMethod()> Public Function ConsultaProducto(ByVal IdProducto As System.Int16) As String<br /> DTProductos = TAProductos.GetProducto(IdProducto)<br /> If DTProductos.Rows.Count > 0 Then<br /> resultado = DTProductos.Rows(0).Item(" Descripcion" ).ToString<br /> Return resultado<br /> End If<br /> Return " No existe informacion del Producto" <br /> End Function<br />Apache<br />Actualmente soporta implementaciónes para C++ y Java.<br />La comunidad ha desarrollado varios web services, entre los que destacan:<br />Axis (1.X) - an implementation of the Simple Object Access Protocol (SOAP). <br />Axis2 - a redesign of Axis (1.X) supporting SOAP 1.2/SOAP1.2/REST/and more. <br />WS-Commons - collection of web service related, reusable components. <br />JaxMe - an implementation of JAXB, the specification for Java/XML binding. <br />jUDDI - an implementation of the Universal Description, Discovery, and Integration (UDDI) specification. <br />Kandula - implements WS-Coordination, WS-AtomicTransaction and WS-BusinessActivity protocols based on Apache Axis and Axis2. <br />Muse - an implementation of the WS-ResourceFramework (WSRF), WS-BaseNotification (WSN), and WS-DistributedManagement (WSDM) specifications. <br />Sandesha - WS-ReliableMessaging implementations for Axis and Axis2 <br />Scout - an implementation of the JSR 93 (JAXR). <br />Synapse - a robust, lightweight implementation of a highly scalable and distributed service mediation framework based on Web services specifications. <br />Tuscany - a robust infrastructure that simplifies the development of SOA-based systems, including: Service Component Architecture (SCA), Service Data Object (SDO), and Data Access Service (DAS). <br />Woden - a Java class library for reading, manipulating, creating and writing WSDL documents. <br />WSIF - a simple Java API for invoking Web services, no matter how or where the services are provided. <br />WSS4J - an implementation of the OASIS Web Services Security (WS-Security) from OASIS Web Services Security TC. <br />XML-RPC - a Java implementation of XML-RPC, a popular protocol that uses XML over HTTP to implement remote procedure calls. <br />Ejemplo de la implementación en Server:<br /><service name=" Calculator" provider=" CPP:RPC" description=" Calculator Web Service" > <parameter name=" className" value=" <Apache_Folder>/Axis/webservices/libcalculator.so" /> </service><br />Implementación en el Cliente:<br />#include " Calculator.h" #include<stdio.h> int main()  {   Calculator c;   int intOut;   c.add(20, 40, intOut);   printf(" result is = %d " , intOut);   return 0;  } <br />Ejemplo de un Handler:<br /><service name=" Calculator" provider=" CPP:RPC" description=" Simple Calculator Axis C++ Service" ><br /> <requestFlow name=" CalculatorHandlers" ><br /> <handler name=" ESHHandler" type=" <Axis installation directory>/handlers/custom/echoStringHeaderHandler/libeshhandler.so" ><br /> </handler><br /> </requestFlow><br /> <responseFlow name=" CalculatorHandlers" ><br /> <handler name=" ESHHandler" type=" <Axis installation directory>/handlers/custom/echoStringHeaderHandler/libeshhandler.so" ><br /> </handler><br /> </responseFlow><br /> <parameter name=" allowedMethods" value=" add sub mul div" /><br /> <parameter name=" className" value=" <Axis installation directory>/webservices/libcalculator.so" /><br /></service><br />Implementación de un Handler:<br />if (pIHeaderBlock != NULL) {   const BasicNode* pBasicNode= pIHeaderBlock->getFirstChild();   const AxisChar* pachHeaderValue;   if (pBasicNode != NULL)   {      if((pBasicNode->getNodeType()) == CHARACTER_NODE) {      pachHeaderValue= pBasicNode->getValue();   } else {      pachHeaderValue = " This was not the expected value Ros" ;   }   } else   {     pachHeaderValue = " pBascNode is NULL" ;    }   AxisChar* pachTmpValue = (AxisChar*) malloc(strlen(pachHeaderValue) + 4);   strcpy(pachTmpValue, pachHeaderValue);   pachTemp = " EchoStringHeaderHandlerPr1.id" ;   pIMsg->setProperty(pachTemp, pachTmpValue);   free(pachTmpValue);   } else {   //do some thing   //AxisChar* pachTmpValue = " Default values since no reqeust SOAP header" ;   //pachTemp = " EchoStringHeaderHandlerPr1.id" ;    //pIMsg->setProperty(pachTemp, pachTmpValue);   //free(pachTmpValue);   }<br />Ruby on Rails<br />Modelo<br />Data Source (S3) -> Model -> Controller -> View (RHTML) -> HTML page<br />Ejemplo<br /># bucket_prefix: use this as the prefix for buckets; # will be set from bucket_prefix in aws_keys.yaml if defined; otherwise defaults to aws access key def self.init(config_file, bucket_prefix=nil)  config = File.open(@config_file) { |f| YAML::load(f) }  @aws_access_key = config['aws_access_key']  @aws_secret_access_key = config['aws_secret_access_key']  @ssl = config['use_ssl'] || false  if @ssl   @logger.debug(" SSL is enabled" )  else    @logger.debug(" SSL is disabled" )  end  @bucket_prefix = bucket_prefix || config['bucket_prefix'] || @aws_access_key  @conn = S3::AWSAuthConnection.new(@aws_access_key, @aws_secret_access_key, @ssl) end<br />Implementación rHTML<br /><h2>Your S3 account has <%= @buckets.size %> buckets, viewing <%= @entries.size %></h2><% if @entries.size > 0 %><div class=" left-aligned" >  <p align=" center" >  <% for bucket in @entries %>    <% @count = @count + 1 %>    <% if (@count % 100) == 0 %>      <br><br>    <% end %>    <span id=" bucket_count" >[<%= @count %>]</span>     <span id=" bucket" ><%= link_to bucket.name, :action => 'list_bucket', :bucket_name => bucket.name, :bucket_page => @bucket_page %></span>   <span id=" ops" >    [ <%= link_to 'Public', :action => 'make_bucket_public', :bucket_name => bucket.name %> |       <%= link_to 'Private', :action => 'make_bucket_private', :bucket_name => bucket.name %> |      <%= link_to 'DELETE', { :action => 'delete_bucket', :bucket_name => bucket.name }, :confirm =>       " Are you sure you want to delete '" + bucket.name + " '? All items contained in it will be deleted!" %> ]    </span>    <br >   <% end %>  </p>  </div>  <%= link_to '<< First', { :page => 1 } %>  <%= link_to '< Prev', { :page => @entry_pages.current.previous } if @entry_pages.current.previous %>  <%= link_to 'Next >', { :page => @entry_pages.current.next } if @entry_pages.current.next %>   <%= link_to 'Last >>', { :page => @entry_pages.length } %><% else %>  <p>  <b>You have no Buckets</b> </p><% end %><br />Consumiendo un .net Service en RoR<br />class SomeController < ApplicationController<br />...<br />web_client_api :my_service, :soap, " http://localhost:8080/CrystalReportsService.asmx" , :namespace=>" http://www.mycompany.com" , :driver_options=>{:default_encodingstyle => SOAP::EncodingStyle::ASPDotNetHandler::Namespace }<br />...<br />Conclusión<br />Web Services permiten a aplicaciones web interactuar entre sí sin importar el OS o WebServer en que estén corriendo. Su verdadera implementación se encuentra cuando, por ejemplo, un server IIS no puede acceder a una base de datos Oracle en Linux, y un PHP a un SQL Server en Windows. Simplemente se crean las reglas del juego (SOAP+WSDL) y se hacen los back ends en cada respectivo lado. <br />No podemos comparar cual es mejor, ya que precisamente su implementación fuerte es el poder interconectar webServers de distintas tecnologías y actuar como una gran aplicación. Todavía está en su temprana etapa, pero esperamos ver como crece hacia la centralización de la era de la informática automatizada.<br />Fuentesconsultadas al 14 de Noviembre de 2008<br />Apache <webServices /><br />http://ws.apache.org <br />W3C<br />http://www.w3c.org <br />W3schools<br />http://www.w3schools.com <br />RoR<br />http://developer.amazonwebservices.com/connect/entry.jspa?externalID=608 <br />