WCF 4.0 OverviewMariano O. Rodriguez
AgendaIntroducciónContratosBindingBehaviorsRESTNuevo en WCF4
ABC de WCFAddress (Donde)Binding (Como)Contract (Que)
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
Contratos
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)
Service Contract
[ServiceContract]public interface ICalculator{ [OperationContract] ComplexProblem Do(ComplexProblem p);}
Service Contract: OneWay[ServiceContract]public interface IOneWayCalculator{ [OperationContract(IsOneWay=true)]
void Do(ComplexProblem p);}
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);}
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);}
Data Contract
[DataContract]public class ComplexNumber{ [DataMember] public double Real;
[DataMember] public double Imaginary { get; set; }
}
Message Contract[MessageContract]public class ComplexProblem{ [MessageHeader] public string Operation { get; set;} [MessageBody] public ComplexNumber Op1 { get; set; } [MessageBody] public ComplexNumber Op2 { get; set; }}
Bindings
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
Binding en Configuracion
<system.serviceModel> <services> <service name="CalculatorService"> <endpoint address=“http://localhost/calculator" binding="basicHttpBinding" contractType="ICalculator" /> </service> </services></system.serviceModel>
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>
Behaviors
Behaviors OverviewImplementan semántica del sistema
Para el desarrollador Concurrencia Instanciación Transacciones Impersonation
Para operaciones Throttling Metadata
InstanciaciónPer CallSingletonSession
Throttling
<behaviors> <behavior configurationName="CalculatorBehavior" > <serviceThrottling maxConcurrentCalls="10" maxConnections="10" maxInstances="10" maxPendingOperations="10" /> </behavior></behaviors>
RESTAcrónimo de REpresentational State TransferEs un estilo de arquitectura
Mejor uso de HTTPMenor complejidadInteroperable
Principios de RESTIdentificar recursos por medio de URIsUso de verbos HTTPLink resourcesPresentación en múltiples formatos
(JSON/POX)Comunicación Stateless
Identifica recursos con URIs
http://myservice/roomshttp://myservice/rooms(3)http://myservice/Colors(red)http://myservice/Transactions(1145001)
Verbos HTTP usadosGet: obtiene la representación de un recursoPut: actualiza un recursoPost: crea un nuevo recursoDelete: elimina un recurso
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>
REST en WCF
REST en WCFBasado en nuevos atributos
WebGet (Get)WebInvoke (Post/Put/Delete)
Permite definir el tipo de SerializacionJSONXML
Soporte de streaming retornando un Stream
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
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/