Professional Documents
Culture Documents
Basic Concept
Data out
Classification 2/9/2012
WSE
.NET Remoting
ASMX
WCF
MSMQ
Classification 2/9/2012
Message
HTTP
Endpoint Endpoint
Client
Endpoint
Service
TCP/IP Endpoint
Classification 2/9/2012
Message
HTTP
Client
TCP/IP
Service
Classification 2/9/2012
Address
Where s my service? The location of the service on the network where it can be reached. http://localhost/service.svc net.msmq://localhost/private/service net.tcp://localhost:6000/service Set via configuration or through code
Classification 2/9/2012
Contract
What s the functionality? Define what data and operation will be exposed Define Contract is the first step of WCF service life cycle Information conveyed in a Contract
Operations exposed by the service In/Out Data representation Types of errors (faults) Messaging patterns
Service Contract
Describe the operations exposed by the service Defined as a C# interface decorated by the ServiceContract and OperationContract attributes
[ServiceContract] public interface ICalculatoor { [OperationContract] int Add(int a, int b); Functions provided by the service [OperationContract] int Sub(int a, int b); }
Classification 2/9/2012
ata Contract
Describes the shape of the data in the request and response messages Defined as a class decorated with the ataContract and DataMember attributes
[DataContract] public class Employee { [DataMember] public string Name { get; set; } [DataMember] public int Age { get; set; } public int Salary { get; set; } }
Classification 2/9/2012 Copyright 2009 Trend Micro Inc. 13
Serialized
Not Serailized
Message Contracts
Describes the data as a SOAP message Defined as a class decorated with the MessageContract, MessageHeader, and MessageBodyMember attributes
[MessageContract] public class Employee { Leave something unencrypted [MessageHeader] public string Name { get; set; } [MessageBodyMember] Put something sensitive public int Age { get; set; } need to be encrypted }
Classification 2/9/2012 Copyright 2009 Trend Micro Inc. 14
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Header> <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IService/GetEmployee</Ac tion> </s:Header> <s:Body> <GetEmployee xmlns="http://tempuri.org/"> <emp xmlns:d4p1="http://schemas.datacontract.org/2004/07/" xmlns:i="http://www.w3.org/2001/XMLSchemainstance"> <Age>12</:Age> <Name>Lizzie</Name> </emp> </GetEmployee> </s:Body> </s:Envelope> <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Header> <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IService/GetEmployee</Ac tion> <h:Name xmlns:h="http://tempuri.org/">Lizzie</h:Name> </s:Header> <s:Body> <Employee xmlns="http://tempuri.org/"> <Age>10</Age> </Employee> </s:Body> </s:Envelope>
Classification 2/9/2012 Copyright 2009 Trend Micro Inc. 15
Fault Contract
Describes error information for the fault section of the SOAP message Defined using a standard data contract and the FaultContract attribute decorating the operation
[OperationContract] [FaultContract(typeof(ErrorInfo))] int Add(int a, int b); *Turn on includeExceptionDetailsInFaults in service behavior
[DataContract] public class ErrorInfo { [DataMember] public string ErrorMsg{ get; set; } }
Classification 2/9/2012
Binding
How do I connect to the service? Indicates the connectivity requirements like protocol and policies used to connect to the service at it s address.
Message should be sent in binary representation or in textual representation? Should the message be encrypted or not
Responsibilities of a Binding
Defines the transport technology (ex: HTTP, TCP) Defines the message encoding Defines protocol and standards (ex: security, session) Define the communication channel and messaging properties (ex: timeout, maximum message size)
Classification 2/9/2012
Message Pipeline
Reliable Messaging Security Encoding Transport Reliable Messaging Security Encoding Transport
Message move through message pipeline A binding defines which elements will be in the pipeline
Classification 2/9/2012
Binding Element
Each binding in WCF is a combination of a transport element, an encoder element, and zero or more protocol elements.
Binding
HTTP Text Security Reliability Transaction
Transport
TCP HTTP
Encoders
Text Binary
Protocol
Security Reliability
MSMQ Custom
IPC
Transaction Custom
.NET
Custom
Classification 2/9/2012
Channel Stack
Channel is a concrete implementation of a binding element. Channel Stack: Channels stack on top of each other to create the concrete implementation of the binding.
Reliable Messaging Security Encoding Transport Protocol Protocol Encoder Transport Channel Channel Channel Channel
Binding elements
Classification 2/9/2012
Channel stack
Classification 2/9/2012
Classification 2/9/2012
Classification 2/9/2012
WCF Architecture
Contracts Service Runtime Messaging Hosting
Classification 2/9/2012
Classification 2/9/2012
Security
Encrypt message User authentication
Classification 2/9/2012
Classification 2/9/2012
Demo
Build a WCF service using the proxy pattern Consume the WCF service Build an endpoint for RESTFul service Invoke service with HTTP GET
Classification 2/9/2012
And
Message Pattern Security Error handling Hosting Distributed Transaction Instancing and Concurrency Reliability Logging/Tracing/Monitoring
Classification 2/9/2012
DISCUSSION
Classification 2/9/2012
Header
Body
Classification 2/9/2012
RESTful services
Representational State Transfer (REST) is an architectural style for service REST utilizes the HTTP protocol Contract is based on HTTP verbs, input data is written in URIs
GET, POST, PUT, DELETE
Classification 2/9/2012
Classification 2/9/2012
Binding
The Address of the endpoint is affected by the endpoints binding
HTTP: http://xxx TCP: net:tcp://xxx
Classification 2/9/2012
Classification 2/9/2012
Classification 2/9/2012
KnownType Attrbute
P4-53
Classification 2/9/2012