Interfaces de Serviço na Prática
Transcrição
Interfaces de Serviço na Prática
Interfaces de Serviço na Prática Luciano Oliveira Sr. Instructor, Consultant Global Field Services Antes de começarmos… Iniciando do princípio… Interfaces de Serviço da Prática 2 © 2006 Progress Software Corporation Antes de começarmos… Let me tell you a story… Interfaces de Serviço da Prática 3 © 2006 Progress Software Corporation Antes de começarmos… Let me tell you a story… Interfaces de Serviço da Prática 4 © 2006 Progress Software Corporation Antes de começarmos… Interfaces de Serviço da Prática 5 © 2006 Progress Software Corporation Antes de começarmos… Interfaces de Serviço da Prática 6 © 2006 Progress Software Corporation Antes de começarmos… Let me tell you a story… Interfaces de Serviço da Prática 7 © 2006 Progress Software Corporation Agenda Revisão da Arquitetura de Referência OpenEdge® Requisitos para Interfaces de Serviço Interfaces de Serviço na Prática • • • • • OpenEdge GUI WebSpeed® UI .NET™ UI Web services Sonic Interfaces de Serviço da Prática 8 © 2006 Progress Software Corporation Arquitetura de Referência OpenEdge® Serviços Serviços Corporativos Corporativos Serviços Serviços de de Negócio Negócio Acesso Acesso aa Dados Dados Fontes Fontes de de Dados Dados Interfaces de Serviço da Prática 9 Infra-estrutura Comum Comum Infra-estrutura Apresentação Apresentação © 2006 Progress Software Corporation Interfaces de Serviço De um perspectiva funcional… Dispositivos Dispositivos Wireless Wireless Portal Portal Web Web B2C B2C Relató órios Relat Relatórios Corporativos Corporativos Quiosque Quiosque de de Informaç ções B2C Informa Informações B2C Camada Camada de de Servi ços de ócio Serviços de Neg Negócio Aplicaç ções de Aplica Aplicações de Back Back Office Office API API aberta aberta Serviç ços de Servi Serviços de Colaboraç ção B2B Colabora Colaboração B2B Integraç ção A2A Integra Integração A2A Interfaces de Serviço da Prática 10 © 2006 Progress Software Corporation Interfaces de Serviço … a um ponto de vista técnico .NET .NET CF CF usando usando Web Web Services Services OpenEdge OpenEdge WebSpeed WebSpeed Crystal Crystal Xi Xi usando usando proxy proxy .NET .NET OpenEdge OpenEdge AppServer AppServer .NET .NET usando usando proxy proxy .NET .NET GUI GUI OpenEdge OpenEdge Web Web Services Services Sonic Sonic ESB ESB Sonic Sonic MQ MQ Interfaces de Serviço da Prática 11 © 2006 Progress Software Corporation Arquitetura de Referência OpenEdge – Interface de Serviços Interface de serviços e utilitários de ambiente Entidades de Negócio Interfaces de Serviço da Prática Tarefas de Negócio Fluxos de Negócio 12 © 2006 Progress Software Corporation Interface de Serviços - Definição Uma Interface de Serviços é uma API que é exposta ao mundo externo. Esta API serve como uma ponte entre a camada de Serviços de Negócio e as camadas de Apresentação e/ou Integração. Interfaces de Serviço da Prática 13 © 2006 Progress Software Corporation Agenda Revisão da Arquitetura de Referência OpenEdge® Requisitos para Interfaces de Serviço Interfaces de Serviço na Prática • • • • • OpenEdge GUI WebSpeed® UI .NET™ UI Web services Sonic Interfaces de Serviço da Prática 14 © 2006 Progress Software Corporation Chamando a lógica de negócios “Conectar” à lógica de negócios Executar lógica de negócios Interfaces de Serviço da Prática 15 © 2006 Progress Software Corporation Passos adicionais Gerenciamento de sessão Gerenciamento de Contexto Segurança Auditoria Serviço de Diretório Interfaces de Serviço da Prática 16 © 2006 Progress Software Corporation Chamando a lógica de negócios Conecta à lógica de negócios Gerenciamento de sessão Gerenciamento de contexto Verificações de segurança Atividades de auditoria Encontrar/iniciar lógica de negócio Executar lógica de negócio Interfaces de Serviço da Prática 17 © 2006 Progress Software Corporation Responsabilidades do Cliente Conexão ao AppServer™ • É preciso conectar ao AppServer? • Como se conecta ao AppServer? Contexto do cliente • O cliente pode manter informações de sessão, contexto ou segurança? • Podemos controlar e confiar no contexto do lado cliente? Interfaces de Serviço da Prática 18 © 2006 Progress Software Corporation Responsabilidades do Cliente Segurança do cliente • Como os clientes se autenticam? • É possível tomar um token de sessão para validar a identidade ou faz-se necessária a autenticação a cada requisição? • Podemos utilizar credencials de cliente (client principals)? Suporte a ProDataSets • O cliente pode enviar e receber estruturas do tipo DataSet? • O cliente pode enviar dados de tabelas Before/After? Interfaces de Serviço da Prática 19 © 2006 Progress Software Corporation Agenda Revisão da Arquitetura de Referência OpenEdge® Requisitos para Interfaces de Serviço Interfaces de Serviço na Prática • • • • • OpenEdge GUI WebSpeed® UI .NET™ UI Web services Sonic Interfaces de Serviço da Prática 20 © 2006 Progress Software Corporation OpenEdge GUI Conexão direta ao AppServer Pode manter contexto de cliente • Login / ID da sessão • Dados do Contexto Suporta credenciais (principals) do cliente Suporte nativo a ProDataSets Escrito em ABL Capaz de realizar chamadas assíncronas ao AppServer Interfaces de Serviço da Prática 21 © 2006 Progress Software Corporation Interface de Serviços OpenEdge GUI Conecta-se ao AppServer Passa o Id da Sessione e outras informações de contexto Passa parâmetros para a requisição • Pode conter DataSets Recupera sessão/contexto Verifica segurança Retorna resultados ao cliente • Pode conter DataSets Interfaces de Serviço da Prática 22 © 2006 Progress Software Corporation Interface de Serviços OpenEdge: carfetchwhere.p {autoedge/dscar.i} {services/dscontext.i} {services/dsnull.i} DEFINE DEFINE DEFINE DEFINE DEFINE DEFINE INPUT INPUT INPUT-OUTPUT OUTPUT INPUT-OUTPUT OUTPUT PARAMETER PARAMETER PARAMETER PARAMETER PARAMETER PARAMETER pcEntityName AS CHARACTER NO-UNDO . pcOperationName AS CHARACTER NO-UNDO . DATASET FOR dsContext . DATASET FOR dsCar . DATASET FOR dsNull . pcExcStatus AS CHARACTER NO-UNDO . DEFINE VARIABLE hDataset AS HANDLE NO-UNDO. RUN support/proSIgateway.p ( INPUT "Car", INPUT "fetchWhere", INPUT-OUTPUT DATASET dsContext BY-REFERENCE, OUTPUT DATASET-HANDLE hDataset, INPUT-OUTPUT DATASET dsNull BY-REFERENCE, OUTPUT pcExcStatus ) . IF NOT pcExcStatus > "" THEN DO: DATASET dsCar:COPY-DATASET (hDataset) . END. RETURN . Interfaces de Serviço da Prática 23 © 2006 Progress Software Corporation Interface de Serviços OpenEdge GUI /* service interface for customer SaveChanges */ DEFINE DEFINE DEFINE DEFINE INPUT PARAMETER pcEntityName AS CHARACTER NO-UNDO. INPUT PARAMETER pcOperationName AS CHARACTER NO-UNDO. INPUT-OUTPUT PARAMETER DATASET-HANDLE phContext. OUTPUT PARAMETER DATASET-HANDLE phOutputDataSet. /* used for fetching data */ DEFINE INPUT-OUTPUT PARAMETER DATASET-HANDLE phDSCustomer. /* used for updates */ DEFINE OUTPUT PARAMETER pcExcStatus AS CHARACTER NO-UNDO. RUN restoreSessionAndContext (INPUT-OUTPUT DATASET-HANDLE phContext BY-REFERENCE) . RUN checkPermission (INPUT pcEntityName, INPUT pcOperationName, OUTPUT lExecuteAllowed, INPUT-OUTPUT DATASET-HANDLE phContext BY-REFERENCE) . IF NOT lExecuteAllowed THEN LEAVE . Interfaces de Serviço da Prática 24 © 2006 Progress Software Corporation Interface de Serviços OpenEdge GUI RUN getOperationDetails (INPUT pcEntityName, INPUT pcOperationName, OUTPUT hEntity, OUTPUT cProcedureName, OUTPUT lInputOutput) . /* call method with appropriate INPUT-OUTPUT or OUTPUT parameters */ IF lInputOutput THEN DO: RUN VALUE (cProcedureName) IN hEntity (INPUT-OUTPUT DATASET-HANDLE phIODataSet BY-REFERENCE). END. ELSE DO: RUN VALUE (cProcedureName) IN hEntity (OUTPUT DATASET-HANDLE phOutputDataSet). END . RUN errorAndExceptionHandling (OUTPUT pcExcStatus) . RETURN . Interfaces de Serviço da Prática 25 © 2006 Progress Software Corporation OpenEdge WebSpeed Modelo cliente/servidor complexo • Web browser – agente WebSpeed • Código WebSpeed– camada de Serviços de Negócio Datasets • Não suportados em “telas” HTML • Suportados em código WebSpeed Sessão/contexto do cliente (em ambos os “clientes”) • Login / Id da sessão • Contexto do cliente Escrito em ABL Interfaces de Serviço da Prática 26 © 2006 Progress Software Corporation Interface de Serviços OpenEdge WebSpeed Mapeia requisições HTML a ABL • Forms, variáveis de browser, parâmetros de URL, cookies • Pode precisar da criação de Before/After tables para os ProDataSets Conecta-se ao AppServer • Ou executa a lógica de negócios na mesma sessão Recupera sessão/contexto Verifica segurança Mapeia os resultados de volta para HTML Interfaces de Serviço da Prática 27 © 2006 Progress Software Corporation Interface de Serviços OpenEdge WebSpeed RUN setContext (INPUT 'whereString':U, INPUT cWhereString, INPUT '':U). RUN setContext (INPUT 'batchSize':U, INPUT piBatchSize, INPUT '':U). RUN callOperation (INPUT 'Car':U, INPUT 'fetchCar':U, INPUT-OUTPUT DATASET dsContext BY-REFERENCE OUTPUT DATASET dsCar, INPUT-OUTPUT DATASET-HANDLE hNullDataSet ). Interfaces de Serviço da Prática 28 © 2006 Progress Software Corporation Interface de Serviços OpenEdge WebSpeed PROCEDURE callOperation […] RUN checkPermission (INPUT pcEntityName, INPUT pcOperationName, OUTPUT lExecuteAllowed, INPUT-OUTPUT DATASET-HANDLE phContext BY-REFERENCE) . IF (NOT lExecuteAllowed) OR (phContext:ERROR = TRUE) THEN RETURN. RUN getOperationDetails (INPUT pcEntityName, INPUT pcOperationName, OUTPUT hEntity, OUTPUT cProcedureName, /*fetchWhere/SaveChanges*/ OUTPUT lInputOutput) . RUN VALUE (cProcedureName) IN hEntity (INPUT-OUTPUT DATASET-HANDLE phIODataSet). END. ELSE DO: RUN VALUE (cProcedureName) IN hEntity (OUTPUT DATASET-HANDLE phOutputDataSet). END . […] Interfaces de Serviço da Prática 29 © 2006 Progress Software Corporation Open Client .NET Conecta-se ao AppServer através de proxies Sessão/contexto do cliente • Login / Id da Sessão • Contexto do cliente Suporte a Datasets Escrito em C#, J#, VB.NET… • Tipicamente as equipes de desenvolvimento de UI e de backened são separadas Tipicamente Interfaces de Serviço estáticas Interfaces de Serviço da Prática 30 © 2006 Progress Software Corporation Interface Open Client .NET Conecta-se ao AppServer através de proxy Passa Id da sessão e outros dados de contexto Pass parâmetros para a requisição • Pode conter Datasets Recupera sessão/contexto Verifica segurança Retorna resultados ao cliente • Pode conter Datasets Interfaces de Serviço da Prática 31 © 2006 Progress Software Corporation Interface de Serviços UI .NET public void GetCars (string sessionid, string modelid, out dsCarDataSet.eCarDataTable dtResult) { Progress.Autoedge.StrongTypesNS.dsCarDataSet dsCars = null; Progress.Autoedge.StrongTypesNS.dsContextDataSet dsContext = new Progress.Autoedge.StrongTypesNS.dsContextDataSet(); Progress.Autoedge.StrongTypesNS.dsNullDataSet dsNull = new Progress.Autoedge.StrongTypesNS.dsNullDataSet(); string status = string.Empty; dsContext.ttContext.AddttContextRow(string.Empty, "sessionID", sessionid); dsContext.ttContext.AddttContextRow(string.Empty, "wherestring", string.Empty); Proxy.carfetchwhere(string.Empty, string.Empty, ref dsContext, out dsCars, ref dsNull, out status); if (dsCars.eCar.HasErrors == true) Handle(dsCars.eCar.GetErrors()); if (dsCars.eCar.Rows.Count <= 0) throw new InvalidOperationException(); dtResult = dsCars.eCar; } Interfaces de Serviço da Prática 32 © 2006 Progress Software Corporation Cliente Web Services Datasets • Datasets não podem ser expostos a Web Services • Before/After tables não são suportados em Web Services Tipicamente não há conhecimento sobre o cliente • Não há informação de sessão/contexto de cliente • Segurança limitada (e.g. não há login) Cliente normalmente não tem conhecimento sobre backend • Precisa de serviços de granularidade fina, autodocumentados Interfaces de Serviço da Prática 33 © 2006 Progress Software Corporation Interface de Serviços Web Services Conecta-se ao AppServer através do Web Services Adapter Passa informação de login • Valida login Passa informações de contexto/sessão Parâmetros podem ter de ser mapeados em Datasets Datasets devem ser “quebrados” em temp-tables A lógica de negócios é chamada Business logic Interfaces de Serviço da Prática 34 © 2006 Progress Software Corporation Interface de Serviços Web Services PROCEDURE fetchTestDrives : /*-----------------------------------------------------------------------------Purpose: Returns an XML list of Open TestDrives Parameters: INPUT UserId INPUT Password OUTPUT Temp-Table for TestDrives ------------------------------------------------------------------------------*/ DEFINE INPUT PARAMETER pcUserName AS CHARACTER NO-UNDO. DEFINE INPUT PARAMETER pcUserPassword AS CHARACTER NO-UNDO. DEFINE OUTPUT PARAMETER TABLE FOR eTestDriveWS. EMPTY TEMP-TABLE ttContext. CREATE ttContext. ASSIGN ttContext.ContextName = "UserLoginName":U ttContext.ContextValue = pcUserName. CREATE ttContext. ASSIGN ttContext.ContextName = "UserLoginPass":U ttContext.ContextValue = pcUserPassword. RUN serviceinterface/proSIgui2.p (INPUT "TestDriveWS":U, INPUT "fetchOpen":U, INPUT-OUTPUT DATASET dsContext BY-REFERENCE, OUTPUT DATASET-HANDLE hDataset, INPUT-OUTPUT DATASET dsNull BY-REFERENCE, OUTPUT pcExcStatus ) . END PROCEDURE. Interfaces de Serviço da Prática 35 © 2006 Progress Software Corporation Interface de Serviços Web Services public class autoedgeObj : System.Web.Services.Protocols.SoapHttpClientProtocol { […] public autoedgeObj() { this.Url = "http://localhost/wsa/wsa1"; } […] public string CreatePO_webservicesi() { object[] results = this.Invoke("CreatePO_webservicesi", new object[0]); return ((string)(results[0])); } public System.IAsyncResult BeginCreatePO_webservicesi( System.AsyncCallback callback, object asyncState) { return this.BeginInvoke("CreatePO_webservicesi", new object[0], callback, asyncState); } public string EndCreatePO_webservicesi( System.IAsyncResult asyncResult) { object[] results = this.EndInvoke(asyncResult); return ((string)(results[0])); } } Interfaces de Serviço da Prática 36 © 2006 Progress Software Corporation Integração com Cliente Sonic Dataset • Datasets não podem ser enviados em mensagens • Before/After tables não são suportadas Tipicamente não há conhecimento sobre o cliente Normalmente o cliente não tem conhecimento sobre o backend Deve ser apenas uma mensagem publicada • Não há resposta direta Interfaces de Serviço da Prática 37 © 2006 Progress Software Corporation Integração com Cliente Sonic Recebe a mensagem Mensagem pode ter de ser mapeada em Datasets Passa informação de login • Valida login Passa informações de contexto/sessão Chama-se a lógica de negócios Interfaces de Serviço da Prática 38 © 2006 Progress Software Corporation Interface de Serviços Sonic Interfaces de Serviço da Prática 39 © 2006 Progress Software Corporation Em suma… Interfaces de serviço • Conectam diferentes tecnologias • Implementam serviços principais • Devem ser criadas para cada tipo de cliente Interfaces de Serviço da Prática 40 © 2006 Progress Software Corporation Perguntas? Interfaces de Serviço da Prática 41 © 2006 Progress Software Corporation Interfaces de Serviço da Prática 42 © 2006 Progress Software Corporation
Documentos relacionados
Usando ProDataSet™ no OpenEdge® 10
XML representa dados no formato caracter
• Mantém os dados independente do Banco de Dados
• Contexto ou outros dados fora do DB
• XML é um formato padrão para troca de dados
– Web services e outras...