Professional Documents
Culture Documents
Abans Technologies
Agenda
Introduction
1980s
1990s
2000s
Object-Oriented
Polymorphism Encapsulation Subclassing
Component-Oriented
Location Transparent Tight Coupling Runtime Metadata
Service-Oriented
Message-based Schema+Contract+Policy Broad Interop
Boundaries Are Explicit Services Are Autonomous Share Schema & Contract, Not Class Compatibility Based On Policy
SERVICE ORIENTATION
So Whats new
Unified Capabilities
Extensibility
Service
INTEROPERABILITY
PRODUCTIVITY
SERVICE-ORIENTED DEVELOPMENT
Broad Support for WS* specifications Compatible with existing MS distributed application technologies
Unifies todays distributed technologies Attribute-based development Visual Studio 2005 integration
WCF
The next-generation platform for distributed systems A pillar of the Microsoft.NET Framework 3.0 Build WCF services in Visual Studio 2005 using any .NET Language
Intelligent code editing, IDE Extensions for WCF, debugging, refactoring, code snippets, etc. Microsoft Windows Vista Microsoft Windows XP Microsoft Windows Server 2003
Runs on
Codename Indigo
Client
Service
Overview
What is WCF
Unification of Technologies
Interoperability
Service-Oriented Development
Developer efficiency
AttributeBased Programming
Enterprise Services
MessageOriented Programming
System.Messaging
WSE
HTTP Client
WCF Services
The new way of easily exposing components (WCF):
.NET Component
Service Contract
HTTP Host
TCP Host
ICP Host
MSMQ Host
HTTP Client
TCP Client
ICP Client
MSMQ Client
Security
Transacti ons
Messaging XML
Metada ta
Reliable Messagin g
Messaging (WS-Addressing):- SOAP is the fundamental protocol for web services. WS Addressing defines some extra additions to SOAP headers, which makes SOAP free from underlying transport protocol. One of the good things about Message transmission is MTOM, also termed as Message Transmission Optimization Mechanism. They optimize transmission format for SOAP messages in XML-Binary formant using XML optimized packaging (XOP). Because the data will sent in binary and optimized format, it will give us huge performance gain. Security (WS-Security, WS-Trust, and WS-Secure Conversation):- All the three WS- define authentication, security, data integrity and privacy features for a service. Reliability (WS-Reliable Messaging):- This specification ensures end-to-end communication when we want SOAP messages to be traversed back and forth many times. Transactions (WS-Coordination and WS-Atomic Transaction):- These two specifications enable transaction with SOAP messages. Metadata (WS-Policy and WS-Metadata exchange):- WSDL is a implementation of WSMetadata Exchange protocol. WS-Policy defines more dynamic features of a service, which cannot be expressed by WSDL.
Overall Architecture
Your code
objects behaviours channel channel channel
Metadata
Client
Service
Your code
behaviours channel channel channel
Binding
channel type N
config
encoding
Main Goal
Unification
Unify todays distributed technology stacks Talk on-machine, cross-machine, cross-networks & Internet Codify best practices for building distributed apps Maximize productivity Interoperate with apps running on other platforms Integrate with Microsofts existing technologies
Productivity
Integration
Caller
Service
Endpoints
Caller
Endpoint Endpoint Endpoint
Service
Endpoint
Caller
A C B B B C C
Service
A
A
Address
Where?
Binding
How?
Contract
What?
Creating Endpoints
Caller
A
C B A A A Proxy or ChannelFactory
Service
B
B B
C
C C
Service Host
Service
A
A
WSDL
?
B
B
C
C
app/web.config
proxy.cs
A A
B B
C C
Address
Consists of:
Logical address does not have map to a physical file, except in IIS
Contract
A collection of operations that specifies what the Endpoint communicates to the outside world Identified by Name and Namespace Duplex Contracts Server can call client WSDualHttpBinding Data and Service components There are three types of contracts Service Contracts Describe the operations a service can perform Map CLR types to WSDL Data Contracts Describes a data structure Maps CLR types to XSD Message Contracts Defines the structure of the message on the wire Maps CLR types to SOAP messages
Bindings
Specification of how the client and server will communicate Multiple endpoints possible for a service Predefined Bindings
Custom Bindings
Predefined Bindings
Creating a Service
Contracts
Service Contract
[ServiceContract] public interface ICalculator { [OperationContract] int DoMath(int a, int b, string op); }
[ServiceContract] public interface ICalculator { [OperationContract] int DoMath(int a, int b, string op); // Not exposed as part of the external contract :-) void MethodRequiredForImplementation(bool b);
Operations Types
Parameterized Operations
int DoParamsMath(int a, int b, string op);
Typed Message
MathResponse DoMsgMath(MathRequest msg);
Untyped (Universal)
Message DoXmlMath(Message m);
[ServiceContract(Namespace="http://TechEd.WCF.Intro")] public interface IGreetings{ [OperationContract( Name=SayHello", Action="http://TechEd.WCF.Intro/HelloRequest", ReplyAction="http://TechEd.WCF.Intro/HelloResponse") string Greet(string name);
contd
class GreetingService : IGreetings { public string Greet(string name) { return Hello, " + name; } public void UnrecognizedMessageHandler(Message msg) { Console.WriteLine("Unrecognized message: " + msg.ToString()); }}
[ServiceContract(SessionMode=SessionMode.Required, CallbackContract=typeof(ICalculatorResults)] public interface ICalculatorProblems { [OperationContract(IsOneWay=true)] void DoMath(MathRequest request); } public interface ICalculatorResults { [OperationContract(IsOneWay=true)] void DisplayResults(MathResponse response); }
try{ return n1 / n2;} catch (DivideByZeroException e) { MyMathFault f = new MyMathFault (n1, n2); FaultReason r = new FaultReason("Divide By Zero"); throw new FaultException<MyMathFault>(f, r);}
Data Contract
[DataContract] public enum Position { [EnumMember] Employee, [EnumMember] Manager, [EnumMember(Value = Vendor")] Contractor, NotASerializableEnumeration }
Message Contract
[MessageContract] public class ComplexProblem { [MessageHeader(Name="Op", MustUnderstand=true)] public string operation; [MessageBodyMember] public ComplexNumber n1; [MessageBodyMember] public ComplexNumber n2; [MessageBodyMember] public ComplexNumber solution;
// Constructors }
Bindings
TX
Transport
TCP
HTTP
Encoders
Text Binary Security
Protocol
Reliability
MSMQ
IPC
TX
.NET
Custom
Custom
Custom
Transport selection TCP, HTTP, Named Pipes, P2P, MSMQ, Custom Transport level security, Streaming Encoding Text, Binary, MTOM, Custom End-to-end Security Confidentiality, integrity, authN, authZ, Federation Credentials: X509, User/Pwd, Kerberos, SAML, InfoCard , Custom End-to-end Reliable messaging Transport independent QoS (in order, exactly once) Volatile and durable queues Transactions Shared transactions for synchronous operations Transactional queues for asynchronous operations [Your own feature goes here]
System-Provided Bindings
Binding BasicHttpBinding WSHttpBinding WSDualHttpBinding WSFederationBinding NetTcpBinding NetNamedPipeBinding NetPeerTcpBinding NetMsmqBinding MsmqIntegrationBinding Interop BP 1.1 WS WS Federation .NET .NET Peer .NET MSMQ Security N, T M, T, X M M T, M T T T, M, X T Session N N, T, RS RS N, RS T ,RS T, N N N N TX N N, Yes N, Yes N, Yes N, Yes N, Yes N N, Yes N, Yes Duplex n/a n/a Yes No Yes Yes Yes No n/a
Binding in Config
<?xml version="1.0" encoding="utf-8" ?> <configuration> <system.serviceModel> <services> <service serviceType="CalculatorService"> <endpoint address="Calculator" bindingSectionName="basicProfileBinding" contractType="ICalculator" /> </service> </services> </system.serviceModel> </configuration>
Configuring Bindings
<endpoint address="Calculator" bindingSectionName="basicHttpBinding" bindingConfiguration="UsernameBinding" contractType="ICalculator" /> <bindings> <basicHttpBinding> <binding name="UsernameBinding" messageEncoding="Mtom"> <security mode="Message"> <message clientCredentialType="UserName"/> </security> </binding> </basicHttpBinding> </bindings>
Custom Bindings
<bindings> <customBinding> <customBinding> <binding name="ReliableTCP"> <reliableSession inactivityTimeout="0:0:5 ordered="true"/> <binaryMessageEncoding/> <tcpTransport transferMode="Buffered"/> </binding> </customBinding> </customBinding> </bindings>
Choosing Bindings
WCF ASMX/WSE3 Other Platform
Any Binding
Any Binding
Http/WS Binding
Http/WS Binding
MSMQ COM+/ES
Moniker
MSMQ Binding
WCF
WCF
Attribute capture the codes requirements Infrastructure ensures that all the bindings satisfy these requirements
Following are different ways by which you would like to create WCF instances:
You would like to create new WCF service instance on every WCF client method call. Only one WCF service instance should be created for every WCF client session. Only one global WCF service instance should be created for all WCF clients.
To meet the above scenarios WCF has provided 3 ways by which you can control WCF service instances:
[ServiceBehavior (InstanceContextMode = InstanceContextMode.PerSes sion)] public class Service : IService { private int intCounter; public int Increment() { intCounter++ return intCounter; } }
[ServiceBehavior (InstanceContextMode = InstanceContextMode. Single )] public class Service : IService { private int intCounter; public int Increment() { intCounter++ return intCounter; } }
When should you use per call, per session and single mode?
Per call
You want a stateless services Your service hold intensive resources like connection object and huge memory objects. Scalability is a prime requirement. You would like to have scale out architecture . Your WCF functions are called in a single threaded model. You want to maintain states between WCF calls. You want ok with a Scale up architecture. Light resource references You want share global data through your WCF service. Scalability is not a concern.
Per session
Single
Behaviours
Behaviors
Caller
A
C Be B A A A
Service
B
B B
C
C C Be
Client-Side Behaviors
Service-Side Behaviors
Behaviors: Overview
Behaviors are all local Developers care about some behaviors Concurrency, instancing model, Everything that affects the correctness of the service Deployers care about other behaviors Throttling, Metadata exposure, message routing info, Everything that has to do with the services runtime aspects Anything you can do in config, you can do in code Code is King you can always override the config
Example: Security
Client
A C Be B A B C
Service
A
A
B
B
C
C
Be
Bindings Move Claims in Messages Behaviors Implement Security Gates Behaviors Provide Credentials
Example: Transactions
Caller
A C B A A A B B B C C C Be
Service
Caller
A C B A A A B B B C C C
Service
Behavior Features
Operation timeouts (close, open, idle) Concurrency, Instancing, Thread-Binding Throttling Faults, Exceptions Impersonation, Authorization, Auditing AutoEnlist, AutoComplete, Timeout, Isolation Serialization, MustUnderstand Metadata More
WCF Summary
Address
http://...
Binding
HTTP Transport WS-Security Protocol
Contract
Request/ Response
Behavior
Instancing Behavior Concurrency Behavior
net.p2p://...
Peer Transport TCP Transport NamedPipe Transport MSMQ Transport Custom Transport WS-RM Protocol
net.tcp://...
net.pipe://...
Error Behavior
Transaction Behavior
net.msmq://...
Custom Behavior
Security Behavior
xxx://...
Custom Protocol
Presentation Takeaways
WCF is the future of distributed computing It combines the best of all existing Microsoft distributed computing stacks It uses WS-* standards for interoperability and .NET value-add for performance and integration with existing solutions WCF is available for Windows Vista, Windows XP SP2, Windows Server 2003
Thank You
deepak.singhvi@abanssecurities.com deepak.singhvi@gmail.com