modulo 3. serviços com back-end services middle tier clients front-end clients wcf soap services...

Post on 18-Apr-2015

108 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

WCF Services com Windows Server AppFabric Waldemir CambiucciArquiteto de SoluçõesMicrosoft Brasilhttp://blogs.msdn.com/wcamb/

Modulo 3

Agenda

− Apresentar os principais recursos para monitoração e administração de serviços WCF com o Windows Server AppFabric.

WCF SOAP SERVICESServiços com

Opções de serviços− Entre Web

Services SOAP e serviços workflows, diferentes fatores devem ser avaliados na aplicação.

Back

-End S

erv

ices

Middle Tier Clients

Front-End Clients

WCF SOAP Services• Definido através de código• Modelos de serviços por entidades

Call

Dir

ect

ly

WCF Workflow Services• Definição visual (gráfica)• Suporte para processos de longa duração • Modelo de serviços por tarefas.

WCF SOAP Services• Definido através de código• Modelos de serviços por entidades

Arquitetura WCF

Channel ModelFormats

(Atom, JSON, XML,…)

Transports(HTTP, TCP, …)

Protocols(SOAP, HTTP, Open Data Protocol,…)

Service Model

Data Contract Service ContractService Behavior

Programming Model

SOAPServices

Web HTTP

Services

Data Services

RIA Services

Workflow Services

ASMX é limitado− HTTP-only hospedado em IIS− Alto acoplamento entre

interface e implementação− Sem suporte para

segurança, garantia de entrega, transação, serialização binária

− Cenários avançados exigem modelos híbridos

− Altamente configurável e extensível

− Suporta o que o ASMX não suporta

− Suporta um modelo unificado através de todos os protocolos de transporte

− Suporta diversos formatos de dados e serialização

WCF é o modo de construção de serviços no .NET Framework

WCF é poderoso

Somente WCF pode aproveitar AppFabric!

ASMX é um modelo básico de implementação de serviços.

WCF 4 suporta modelos avançados e sofisticados de soluções com serviços.

Windows Communication Foundation 4− O WCF é um framework unificado

para a construção de aplicações distribuídas de forma segura, confiável e interoperável.− ASMX Web Services− .NET Remoting− Enterprise Services− MSMQ− WSE

− Facilita a administração de protocolos e bindings pelas equipes de infraestrutura.

Windows Communication Foundation 4

Cliente

Serviço

MensagemABC

A B C

A B C

Metadata

Bv

Bv

Bv

Bv

Proxy

ServiceHost<T>()Address

Binding

Contract

(Onde) (Como) (O quê)

Endpoint

Endpoint

Windows Communication Foundation 4− Framework para comunicação de sistemas,

serviços e processos.

MSDN: Web Services Protocols Interoperability Guidemsdn.microsoft.com/en-us/library/ms734776.aspx

• ASMX, WSE, .NET Remoting, COM+, MSMQProtocolos Unificados

• SOAP (1.1 e 1.2), WS-Addressing, MTOM, WSDL, WS-MetadataExchange, WS-Policy

Messaging e Metadados

• WS-Security, WS-SecureConversation, WS-Trust, WS-Reliable Messaging, WS-Coordination, WS-AtomicTransaction

Segurança, Confiabilidade e

Transações

• POX, REST, JSON, RSS, ATOM, ATOMPubWeb 2.0

Criando um serviço WCF SOAP Service equivalente ao ASMX

Definir o Serviço

Hospedar no AppFabric

Testar com WCF Test

Client

Poucas opções de configuração e suporte limitado para protocolos!

Criando um “típico” WCF SOAP Service

Definir contrato de

serviço e entidades

Implementar o serviço

Configurar o serviço

Host no IIS & AppFabric

Testar com WCF Test

Client

Host

(IIS

| A

pp

Fab

ric)

Service Configuration (web.config)

Service Endpoint

Address (http://localhost/MyCalc.svc)

Binding(basicHttp)

Service Contract (ICalculator)

Conceitos principais para o serviço WCF− Host

− Service Implementation

− Service Contract

− Data Contract

− Service Endpoint (Address, Binding Contract)

− Service Behavior

Service Contract (ICalculator)Operations (signatures)double Add(double a, double b)double GetArea(Rectangle r)

Service Implementation (MyCalc: ICalculator)

Operations (implementation)double Add(double a, double b)double GetArea(Rectangle r)

Service Behaviors (Metadata)

Data ContractRectangle double width, double height

WCF SOAP SERVICESCriando um “típico”

Criando um “típico” cliente de serviço

Criar uma Aplicação

Cliente

Add Reference para o “Data

Contract Assemblies” (opcional)

Adicionar a “Service

Reference”

Instanciar o Proxy

Chamar os métodos via

Proxy

Principais conceitos para o cliente WCF

− Proxy− Endpoints− Messages − Service Instance

Clie

nt

Service Instance

Proxy Instance (MyCalcClient)

Client Configuration (app.config)

Client Endpoint

Address (http://localhost/MyCalc.svc)

Binding(basicHttp)

Service Contract (ICalculator)

proxy.Add(5,2

)

Send M

ess

age

Add(5,2)

Rece

ive M

essa

ge

7

CalculatorClient proxy = new CalculatorClient();

Try

{proxy.Add(1,5);proxy.Close();

}Catch (Exception ex)

{proxy.Abort();throw;

}

Melhores práticas para uso de Proxy

Encapsular a chamada através de try/catch,

tratando a exceção com proxy.Abort()

WCF SERVICES

Usando o AppFabric para monitorar

AppFabric Dashboard – WCF Call History

Tracked Events Normal Operation:

− ServiceHost events− Aggregates for

Operations− Completed Calls

Troubleshooting:

− Throttling− Service Exceptions− User Defined Errors

Failed Calls− Faulted Calls

19

Gerenciamento de Endpoints

Gerenciamento de Serviços

21

Emitindo erros definidos pelo usuário− Obter o ETW Provider ID

− Criar um novo Event Provider para um ID

− Definir um event descriptor

− Escrever o evento

− Veja um exemplo que encapsula todos os tratamentos, abaixo:

DiagnosticSection config = (DiagnosticSection) WebConfigurationManager.GetSection("system.serviceModel/diagnostics");providerId = new Guid(config.EtwProviderId);

myEventProvider = new EventProvider(providerId);

errorDescriptor = new EventDescriptor(ErrorEventId, Version, Channel, ErrorLevel, Opcode, Task, Keywords);

myEventProvider.WriteEvent(ref errorDescriptor, title, serviceName, errorMessage);

WCFUserEventProvider eventWriter = new WCFUserEventProvider();eventWriter.WriteErrorEvent(“AddOperation”, “An error occurred.”);

RESUMO

Resumo

− O Windows Server AppFabric oferece diversos recursos para o gerenciamento de serviços WCF.

− Através do AppFabric Dashboard, é possível monitorar o histórico de chamadas de serviços WCF.

LAB 03 – SERVIÇOS WCF SERVICES SOBRE O WINDOWS SERVER APPFABRIC

© 2011 Microsoft Corporation. All rights reserved. Microsoft, MSDN, the MSDN logo, and [list other trademarks referenced] are trademarks of the Microsoft group of companies.  The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation.  Because Microsoft must respond

to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. 

MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED, OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

top related