Demystifying Windows Communication Foundation

51
Keith Elder Microsoft MVP INETA Speaker Blog: http://keithelder.net/blog/ Twitter: http://twitter.com/keithelder Podcast: http://deepfriedbytes.com Demystifying Windows Communication Foundation

description

The purpose of the talk is to get developers interested in WCF by taking out some of the mystery of the new technology. There are a lot of developers still using ASMX to build services and have hesitations of moving to WCF because of the learning curve. Author tried to break down WCF and remove the mystery behind it as well as give a lot of comparisons as to what developers will find different when moving from ASMX services to WCF.Watch a video at http://www.bestechvideos.com/2009/03/18/dnrtv-show-135-keith-elder-demystifies-wcf

Transcript of Demystifying Windows Communication Foundation

Page 1: Demystifying Windows Communication Foundation

Keith Elder Microsoft MVP INETA Speaker Blog: http://keithelder.net/blog/ Twitter: http://twitter.com/keithelder Podcast: http://deepfriedbytes.com

Demystifying Windows Communication Foundation

Page 2: Demystifying Windows Communication Foundation

Originally from Ripley, Ms

1.  Raised on a small farm 2.  Yes I have milked a cow, slopped the

chickens and fed the hogs 3.  Home of the 2nd largest flea market

in the US

Page 3: Demystifying Windows Communication Foundation

Modelled During the 80's

Page 4: Demystifying Windows Communication Foundation
Page 5: Demystifying Windows Communication Foundation

Quicken Loans

$500! Cash!

Page 6: Demystifying Windows Communication Foundation

About Quicken Loans

  Originally founded in 1985 as Rock Financial by Dan Gilbert   Grew to one of the largest independent mortgage banks in

the country   1998 IPO   1999 Launched Rockloans.Com

  1999 Intuit, Inc (makers of TurboTax and Quicken) purchased Rock Financial.

  July 2002 Dan Gilbert purchased Quicken Loans back from Intuit. Retained Quicken Loans branding and marketing initiatives.

  5000 employees   Largest online retail home loan lender

Page 7: Demystifying Windows Communication Foundation

Deep Fried Bytes is an audio talk show with a Southern flavor hosted by technologists and developers Keith Elder and Chris Woodruff. The show discusses a wide range of topics including application development, operating systems and technology in general. Anything is fair game if it plugs into the wall or takes a battery.

http://deepfriedbytes.com

Page 8: Demystifying Windows Communication Foundation

Agenda

  How We Got Here   ASMX vs WCF Throwdown   WCF Contracts

  Service   Data   Message

  Bindings   Security   Reliability   Declarative   Summary

Page 9: Demystifying Windows Communication Foundation

From Objects to Services

Page 10: Demystifying Windows Communication Foundation

The Challenge Radically Simplifying Distributed Application Development

Development of connected systems remains costly and frustrating

  Different programming models for different tasks   Need for security and reliable messaging   Interoperability with applications on other platforms   Productive service-oriented programming model needed

Page 11: Demystifying Windows Communication Foundation

Windows Communication Foundation

Page 12: Demystifying Windows Communication Foundation

What Does WCF Replace?

ASMX

WSE

.NET Remoting

COM+ (Enterprise Services)

MSMQ

Page 13: Demystifying Windows Communication Foundation

DEMO

Page 14: Demystifying Windows Communication Foundation

OUR CURRENT ASMX SERVICES INVESTMENT VS WCF

Page 15: Demystifying Windows Communication Foundation

Smart Client

Java Client

Service

User’sDesktop

Open Form

UserControl

UserControl

Event

Eve

nt

Event

ASMX Challenge

Page 16: Demystifying Windows Communication Foundation

Current ASMX Web Services

Page 17: Demystifying Windows Communication Foundation

What’s So Different About WCF

Page 18: Demystifying Windows Communication Foundation

UNDERSTANDING WCF PRINCIPLES

Page 19: Demystifying Windows Communication Foundation

Services and Clients

Page 20: Demystifying Windows Communication Foundation

Endpoints

Page 21: Demystifying Windows Communication Foundation

Address, Binding, Contract

Page 22: Demystifying Windows Communication Foundation

WCF Architecture: Messaging Runtime

Transport

Encoder

Protocol(s)

Transport

Encoder

Protocol(s)

Contract and

Behaviors

Binding

Address

Page 23: Demystifying Windows Communication Foundation

CONTRACTS The what

Page 24: Demystifying Windows Communication Foundation

Three Types of Contracts

Service Contract

Defines Operations, Behaviors and Communication

Shape

What does your service do

Data Contract Defines Schema and Versioning

Strategies

What obect data is used

Message Contract

Allows defining application-specific

headers and unwrapped body

content

Allows control over the SOAP structure

of messages

Page 25: Demystifying Windows Communication Foundation

Ways to Talk

  One Way:   Datagram-style delivery

  Request-Reply   Immediate Reply on same logical thread

  Duplex   Reply “later” and on backchannel (callback-style)

One Way

Request-Reply

Duplex (Dual)

Page 26: Demystifying Windows Communication Foundation

SERVICE CONTRACTS What does your service do?

Page 27: Demystifying Windows Communication Foundation

Service Contract

usingSystem.ServiceModel;

[ServiceContract]publicinterfaceICalculate{

[OperationContract]doubleAdd(doublea,doubleb);[OperationContract]doubleSubtract(doublea,doubleb);

}

Page 28: Demystifying Windows Communication Foundation

Service Contract: OneWay

[ServiceContract]publicinterfaceIOneWayCalculator{[OperationContract(IsOneWay=true)]voidStoreProblem(ComplexProblemp);}

Page 29: Demystifying Windows Communication Foundation

Service Contract: Duplex Asymmetric [ServiceContract(Session=true,CallbackContract=typeof(ICalculatorResults)]publicinterfaceICalculatorProblems{[OperationContract(IsOneWay=true)]voidSolveProblem(ComplexProblemp);}

publicinterfaceICalculatorResults{[OperationContract(IsOneWay=true)]voidResults(ComplexProblemp);}

Page 30: Demystifying Windows Communication Foundation

Service Contract: Duplex Symmetric

[ServiceContract(Session=true,CallbackContract=typeof(IChat)]publicinterfaceIChat{[OperationContract(IsOneWay=true)]voidTalk(stringtext);}

Page 31: Demystifying Windows Communication Foundation

DEMO – SERVICE CONTRACT

Page 32: Demystifying Windows Communication Foundation

DATA CONTRACTS What object data needs to flow back and forth?

Page 33: Demystifying Windows Communication Foundation

Data Contract

[DataContract]publicclassComplexNumber{[DataMember]publicdoubleReal=0.0D;[DataMember]publicdoubleImaginary=0.0D;

publicComplexNumber(doubler,doublei){this.Real=r;this.Imaginary=i;}}

Page 34: Demystifying Windows Communication Foundation

MESSAGE CONTRACTS Defines the mapping between the type and a SOAP envelope

Page 35: Demystifying Windows Communication Foundation

Message Contract

[MessageContract]publicclassComplexProblem{[MessageHeader]publicstringoperation;[MessageBody]publicComplexNumbern1;[MessageBody]publicComplexNumbern2;[MessageBody]publicComplexNumbersolution;

//Constructors…}

Page 36: Demystifying Windows Communication Foundation

BINDINGS

Page 37: Demystifying Windows Communication Foundation

Bindings & Binding Elements

Transport

IPC MSMQ

Custom

TCP HTTP

Protocol Encoders

.NET TX

Custom

Security Reliability

Binding HTTP TX Security Reliability Text

Text

Binary

Custom

Page 38: Demystifying Windows Communication Foundation

Standard Bindings

Binding Interop Security Session TX Duplex

BasicHttpBinding BP 1.1 N, T N N n/a

WSHttpBinding WS M, T, X N, T, RS N, Yes n/a

WSDualHttpBinding WS M RS N, Yes Yes

WSFederationBinding Federation M N, RS N, Yes No

NetTcpBinding .NET T, M T ,RS N, Yes Yes

NetNamedPipeBinding .NET T T, N N, Yes Yes

NetPeerTcpBinding Peer T N N Yes

NetMsmqBinding .NET T, M, X N N, Yes No

MsmqIntegrationBinding MSMQ T N N, Yes n/a

N = None | T = Transport | M = Message | B = Both | RS = Reliable Sessions

Page 39: Demystifying Windows Communication Foundation

Bindings & Behaviors: Security

Service

C B A

C B A

Client

A B C

C B A

Be Be

Bindings Insert Claims in Messages

Behaviors Implement

Security Gates

Page 40: Demystifying Windows Communication Foundation

  Claims based end-to-end security   Secure end-to-end message exchanges   Secure access to resources   Record resource access requests

  X509, Username/Password, Kerberos, SAML, custom credentials

  Message security   Confidentiality and integrity   Transport or message level

  Access to resources   Authentication and authorization

Feature Overview Security

Page 41: Demystifying Windows Communication Foundation

DEMO - BINDINGS

Page 42: Demystifying Windows Communication Foundation

Bindings & Behaviors: Transactions

Service

C B A

C B A

Client

A B C

C B A

Be Be

Bindings Flow Transactions

Behaviors AutoEnlist and AutoComplete

Page 43: Demystifying Windows Communication Foundation

Service

C B A

C B A

Client

A B C

C B A

Bindings provide Session and Guarantees

Bindings & Behaviors: Reliable Sessions

Page 44: Demystifying Windows Communication Foundation

  End-to-end Reliable messaging   In-order guarantees   Exactly once guarantees

  Transport-Independent Sessions   Integration with ASP.NET Sessions in IIS-Hosted

compatibility mode

  Transactions   Guaranteed atomic success or failure across

services

Feature Overview Reliability and Transactions

Page 45: Demystifying Windows Communication Foundation

Code vs. Config

Page 46: Demystifying Windows Communication Foundation

Defining Endpoints

<?xmlversion="1.0"encoding="utf‐8"?><configurationxmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"><system.serviceModel><services><serviceserviceType="CalculatorService"><endpointaddress="Calculator"bindingSectionName="basicProfileBinding"contractType="ICalculator"/></service></services></system.serviceModel></configuration>

Page 47: Demystifying Windows Communication Foundation

Configuring Bindings

<endpointaddress="Calculator"bindingSectionName="basicProfileBinding"bindingConfiguration="Binding1"contractType="ICalculator"/>

<bindings><basicProfileBinding><bindingconfigurationName="Binding1"hostnameComparisonMode="StrongWildcard"transferTimeout="00:10:00"maxMessageSize="65536"messageEncoding="Text"textEncoding="utf‐8"</binding></basicProfileBinding></bindings>

Page 48: Demystifying Windows Communication Foundation

Custom Bindings

<bindings><customBinding><bindingconfigurationName="Binding1"><reliableSessionbufferedMessagesQuota="32"inactivityTimeout="00:10:00"maxRetryCount="8"ordered="true"/><httpsTransportmanualAddressing="false"maxMessageSize="65536"hostnameComparisonMode="StrongWildcard"/><textMessageEncodingmaxReadPoolSize="64"maxWritePoolSize="16"messageVersion="Default"encoding="utf‐8"/></binding></customBinding></bindings>

Page 49: Demystifying Windows Communication Foundation

DEMO – MULTIPLE BINDINGS

Page 50: Demystifying Windows Communication Foundation

Secure Channel …

WCF Summary

Page 51: Demystifying Windows Communication Foundation

WCF Summary

  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, Windows Server 2008