Você está na página 1de 33

Knowledge Sharing Session

Windows Communication Foundation

Contents
1. 2. 3. 4. 5. 6. 7. WCF Overview Contracts Bindings Hosting Messaging Patterns Security Fundamentals Reliable Messaging

-1-

What is WCF?
Windows Communication Foundation is... a part of the .NET Framework that provides a unified programming model for rapidly building service-oriented applications that communicate across the web and the enterprise.

Part of the Microsoft .NET Framework 3.0

Service-oriented

Introduction to WCF

o Built for service-oriented system design o Simplifies how you approach SOA

Loosely coupled
o Not bound to a particular protocol, encoding format, or hosting environment o Everything is configurable

Interoperable
o Supports core Web services standards o Extensible to quickly adapt to new protocols and updates

Integration
o Integrates with earlier Microsoft stacks
ASMX, MSMQ etc

WCF v/s other technologies

-4-

ServiceContractAttribute o Define service operations OperationContractAttribute o Methods exposed as part of the service contract

Service Contracts

DataContractAttribute o Translation between CLR types and schema DataMemberAttribute o Opt-in members for serialization o Applied to fields or properties Preferred way for DataContractSerializer to work with complex types

Data Contracts

MessageContractAttribute o Greater control over message headers and body elements Supporting attributes: o MessageHeaderAttribute o MessageBodyMemberAttribute Useful for: o Add custom headers o Control signing and encryption

Message Contracts

Uncaught exceptions indicate to the service model a potentially fatal error has occurred Where possible, throw fault exceptions. Create data contracts for service faults. Better for interoperability Eg: FaultException<T>

Fault Contracts

Fault Contracts

-9-

ListService

- 10 -

WCFTestClient.exe
Path-C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\WcfTestClient.exe

- 11 -

WCF Proxy

- 12 -

Svcutil.exe
svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://01hw350029.tcsdcxus.com:8600/ListWCF/ListService.svc /d:D:\Dhana

- 13 -

WCF Client

- 14 -

WCF Client

- 15 -

Bindings are how we configure the communication channel Bindings define the protocols for communication between clients and services: o Transport protocol HTTP,TCP,MSMQ o Message encoding o Security and reliable messaging

What are Bindings?

Standard bindings: o Predefined binding elements o Default settings for communication over HTTP, TCP, named pipes, or MSMQ Custom bindings: o Completely customized set of binding elements o When standard bindings will not do the trick

Binding Selection

BasicHttpBinding WSHttpBinding WSDualHttpBinding WSFederationHttpBinding WebHttpBinding(3.5) NetNamedPipeBinding NetTCPBinding NetPeerTCPBinding NetMsmqBinding MsmqIntegrationBinding

Standard Bindings

Hosting Environments
Self-hosting o Console application, Windows application, Windows service o HTTP, TCP, Microsoft Message Queuing (MSMQ) IIS/Microsoft ASP.NET o HTTP Windows Activation Service o HTTP, TCP, MSMQ

A ServiceHost instance must be initialized to expose endpoints for a service Self-hosting environments manually construct this instance Core methods: o Open() opens channel listeners o Close() closes channel listeners

Self-Hosting

ServiceHost Configuration
Can configure programmatically:

Can initialize with configuration settings:

IIS/WAS Hosting
Requests mapped based on .svc file extension Service type associated by @ServiceHost declaration

Publish Web

- 23 -

Core Security Concepts Mutual Authentication means for sender and receiver to identity one another Authorization determining what the authenticated party has rights to do Confidentiality ensuring only the intended recipient can view information Integrity ensuring that messages are not altered by malicious parties Reliability preventing replay

Transport Security

Secure Sockets Layer (SSL), Transport Layer Security (TLS), IP Security (IPSec) Point-to-point Applies to entire message

Trust Relationship

Sender

Receiver

Message Security Web services security (WS*) Secure to ultimate message receiver o Through proxies, application routers, etc.

Trust Relationship

Sender

Intermediary

Receiver

Protection Level
<netTcpBinding> <binding name="signOnly"> <security> <transport protectionLevel="Sign"/> </security> </binding> </netTcpBinding>

Reliability Distributed, service-oriented systems rely on: o Access to remote application functionality o Predictable execution of functionality o System availability and consistency o Network connectivity WCF provides reliability features: o Reliable sessions o Support for transactions o Durable queued messaging

Reliable Sessions

Makes it possible to overcome transient interruptions in network connectivity Delivery guarantees o Deliver exactly once o Deliver in order (if desired) Independent of transport protocol o End-to-end reliability o Message-based, not transport-based o Based on interoperable protocols

Enabling Reliable Sessions Set <reliableSession> settings for the binding

References
http://msdn.microsoft.com/en-us/library/ms734712.aspx
http://msdn.microsoft.com/library/ee958158.aspx

- 31 -

Thank You

- 32 -

Você também pode gostar