29
WCF 4.0 Overview Mariano O. Rodriguez

WCF 4 Overview

Embed Size (px)

DESCRIPTION

Overview of WCF 4 main features

Citation preview

Page 1: WCF 4 Overview

WCF 4.0 OverviewMariano O. Rodriguez

Page 2: WCF 4 Overview

AgendaIntroducciónContratosBindingBehaviorsRESTNuevo en WCF4

Page 3: WCF 4 Overview

ABC de WCFAddress (Donde)Binding (Como)Contract (Que)

Page 4: WCF 4 Overview

WCF Channel LayerCliente

Protocol Channel 1

Protocol Channel 2

Protocol Channel N

Encoder

Transport

Servicio

Protocol Channel 1

Protocol Channel 2

Protocol Channel N

Encoder

Transport

Page 5: WCF 4 Overview

Contratos

Page 6: WCF 4 Overview

Contratos

Servicio

Datos

Mensaje

Describe las operaciones que el servicio realiza. Mapea tipos CLR

(WSDL).

Describe la estructura de datos. Mapea tipos CLR (XSD).

Define la estructura del mensaje. Mapea tipos CLR (SOAP message)

Page 7: WCF 4 Overview

Service Contract

[ServiceContract]public interface ICalculator{ [OperationContract] ComplexProblem Do(ComplexProblem p);}

Page 8: WCF 4 Overview

Service Contract: OneWay[ServiceContract]public interface IOneWayCalculator{ [OperationContract(IsOneWay=true)]

void Do(ComplexProblem p);}

Page 9: WCF 4 Overview

Service Contract: Duplex[ServiceContract(CallbackContract=typeof(ICalculatorResults)]

public interface ICalculatorProblems{ [OperationContract(IsOneWay=true)] void SolveProblem (ComplexProblem p);}

public interface ICalculatorResults{ [OperationContract(IsOneWay=true)] void Results(ComplexProblem p);}

Page 10: WCF 4 Overview

Service Contracts: Faults[ServiceContract]public interface ICalculator{ [OperationContract] [FaultContract(typeof(DivideByZeroException))] ComplexProblem Do(ComplexProblem p);}

try { return n1 / n2;}catch (DivideByZeroException e) { var f = new DivideByZeroException(“Calc Failure”); throw new FaultException<DivideByZeroException>(f);}

Page 11: WCF 4 Overview

Data Contract

[DataContract]public class ComplexNumber{ [DataMember] public double Real;

[DataMember] public double Imaginary { get; set; }

}

Page 12: WCF 4 Overview

Message Contract[MessageContract]public class ComplexProblem{ [MessageHeader] public string Operation { get; set;} [MessageBody] public ComplexNumber Op1 { get; set; } [MessageBody] public ComplexNumber Op2 { get; set; }}

Page 13: WCF 4 Overview

Bindings

Page 14: WCF 4 Overview

Standard BindingsName Transport Encoding

BasicHttpBinding HTTP/HTTPS Text/MTOM

NetTcpBinding TCP Binary

NetPeerTcpBinding P2P Binary

NetNamedPipeBinding IPC Binary

WSHttpBinding HTTP/HTTPS Text/MTOM

WSFederationHttpBinding

HTTP/HTTPS Text/MTOM

WSDualHttpBinding HTTP/HTTPS Text/MTOM

NetMsmqBinding MSMQ Binary

MsmqIntegrationBinding MSMQ Binary

WebHttpBinding HTTP/HTTPS Text/Binary

Page 15: WCF 4 Overview

Binding en Configuracion

<system.serviceModel> <services> <service name="CalculatorService"> <endpoint address=“http://localhost/calculator" binding="basicHttpBinding" contractType="ICalculator" /> </service> </services></system.serviceModel>

Page 16: WCF 4 Overview

Custom Bindings<bindings> <customBinding> <binding configurationName="Binding1"> <reliableSession bufferedMessagesQuota="32"

inactivityTimeout="00:10:00" maxRetryCount="8" ordered="true" />

<httpsTransport manualAddressing="false" maxMessageSize="65536" hostNameComparisonMode="StrongWildcard"/>

<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Default" writeEncoding="utf-8" />

</binding> </customBinding></bindings>

Page 17: WCF 4 Overview

Behaviors

Page 18: WCF 4 Overview

Behaviors OverviewImplementan semántica del sistema

Para el desarrollador Concurrencia Instanciación Transacciones Impersonation

Para operaciones Throttling Metadata

Page 19: WCF 4 Overview

InstanciaciónPer CallSingletonSession

Page 20: WCF 4 Overview

Throttling

<behaviors> <behavior configurationName="CalculatorBehavior" > <serviceThrottling maxConcurrentCalls="10" maxConnections="10" maxInstances="10" maxPendingOperations="10" /> </behavior></behaviors>

Page 21: WCF 4 Overview

RESTAcrónimo de REpresentational State TransferEs un estilo de arquitectura

Mejor uso de HTTPMenor complejidadInteroperable

Page 22: WCF 4 Overview

Principios de RESTIdentificar recursos por medio de URIsUso de verbos HTTPLink resourcesPresentación en múltiples formatos

(JSON/POX)Comunicación Stateless

Page 23: WCF 4 Overview

Identifica recursos con URIs

http://myservice/roomshttp://myservice/rooms(3)http://myservice/Colors(red)http://myservice/Transactions(1145001)

Page 24: WCF 4 Overview

Verbos HTTP usadosGet: obtiene la representación de un recursoPut: actualiza un recursoPost: crea un nuevo recursoDelete: elimina un recurso

Page 25: WCF 4 Overview

Link Resources

<order self=’http://example.com/orders(1234)’> <amount>23</amount> <product ref=’http://example.com/products(4554)’ />

<customer ref=’http://example.com/customers(1234)’ />

</order>

Page 26: WCF 4 Overview

REST en WCF

Page 27: WCF 4 Overview

REST en WCFBasado en nuevos atributos

WebGet (Get)WebInvoke (Post/Put/Delete)

Permite definir el tipo de SerializacionJSONXML

Soporte de streaming retornando un Stream

Page 28: WCF 4 Overview

Nuevo en WCF 4Simplificación de configuraciónActivación en IIS (.svc opcional)Soporte de WS-Discovery (udp based)Soporte de Router

BridgingRouting por contenido

Mejoras para RESTPagina de ayudaIntegración con rutas de MVCCaching

Page 29: WCF 4 Overview

ReferenciasA Guide to Designing and Building RESTful

Web Services with WCF 3.5http://msdn.microsoft.com/en-us/library/dd203052.asp

xWCF REST Starter Kit

http://aspnet.codeplex.com/releases/view/24644Windows Server AppFabric Training Kit

http://www.microsoft.com/download/en/details.aspx?id=7956

ODatahttp://www.odata.org/