23
WCF Quick Start with Chris Deweese

Wcf Quickstart

Embed Size (px)

DESCRIPTION

WCF Quickstart presentation from St Louis Day of .NET 2009

Citation preview

Page 1: Wcf Quickstart

WCF Quick Start with Chris Deweese

Page 2: Wcf Quickstart

.NET Architecto Specialties: SOA, Xml, Distributed Messagingo Primarily work on System Integration &

Information Sharing projects 2009 Microsoft MVP, Solutions Architect Twitter @cdeweese – use #stldodn for conference http://christopherDeweese.com/ Avid Xbox player (when kids are sleeping)

About Chris Deweese

Page 3: Wcf Quickstart

Agenda

Why & What of WCF Building a service Lessons Learned

Page 4: Wcf Quickstart

Why Services?

Encapsulation of business capabilities. o “Unit of work exposed to the world”

– Juval Lowy Support multiple front-ends with one

service Exposes data model using contracts (Schema,

WSDL)o Improves interoperability and automation

Page 5: Wcf Quickstart

What is WCF?

Framework for building service-oriented applications

Separates the logic of services from the channels they communicate on

Messages based on Simple Object Access Protocol (SOAP)

Support for REST & Plain-old Xml (POX) in .NET 3.5

Page 6: Wcf Quickstart

Why WCF?

Evolution of service oriented thinking Remoting, Message Queuing, and

ASMX were designed on different stacks WCF unifies the programming model for exposing

services through different channels (Web, Message Queues, Sockets, In-Process)o Service logic and function is not dependent on

the channel or transport

Page 7: Wcf Quickstart

Key Concepts

Service – Unit of work exposed to the world. Endpoint – the collection of the services address,

binding, and contract. Address – The network location of the service

(e.g., http://localhost/home/home.svc) Binding – How you interact with the service at the wire

level. Channel – The transport mechanism that moves the

message between service and client. Dispatcher – Manages execution of service code by

routing messages to the appropriate service instance and method.

Behavior – How you control the local execution of a service.

Page 8: Wcf Quickstart

WCF Extensibility

WCF built for extensibility Base classes & interfaces provided which are the

gateway to extending WCFo Leverages dependency injection principle and

factories to hook your extensions into the framework at runtime

Support for building custom channels, bindings, etc

Lots of “knobs and switches” to tweak WCF through configuration or code attributes

Page 10: Wcf Quickstart

Address

“Dude where’s my service?” The location of the service on the

network where it can be reached.o http://localhost/pizza.svco net.msmq://localhost/private/pizzaserviceo net.tcp://localhost:6000/pizzaservice

Set via configuration or through code

Page 11: Wcf Quickstart

Binding

“How do I talk to this thing?” The protocol and policies used to connect to the

service at it’s address. WCF Provided Bindings

o Http(BasicHttp, WsHttp, WsDualHttp, WsFederation)o NetMsmqo MsmqIntegrationo NetNamedPipeo NetTcpo NetPeerTcp

Set via configuration or through code

Page 12: Wcf Quickstart

Contract

“What’s it going to do for me?” Defines the operations, inputs, outputs,

and message exchange patterns of the service.

Defined using an Interface; wired into WCF by using the ServiceContract attribute. Methods use the OperationContract attribute. Classes use the DataContract attribute and members use the DataMember attribute.

WCF Serialization is “Opt-In”

Page 13: Wcf Quickstart

Hosting WCF Services

In Process Windows Service Web Service (IIS) Windows Activation Services

o WAS allows you to host a service on any binding

Page 14: Wcf Quickstart

WCF Architecture

Page 15: Wcf Quickstart
Page 16: Wcf Quickstart
Page 17: Wcf Quickstart

Demo Service – Pizzeria Ivan

Page 18: Wcf Quickstart

Pizzeria Ivan

Pizzeria Ivan has an existing application they want to service enable.

Using WCF, build a service interface around the Pizzeria Ivan application

Page 19: Wcf Quickstart

If you build it…they will come.

Page 20: Wcf Quickstart

Some Opinion, Your Mileage May Vary

The default WCF Service project is a good starto Placing the contracts and service implementation in the

same project creates some amount of couplingo Following the Web Service Software Factory guidance a

recommended practice is to separate the contracts and implementation

Separating the host project leaves you open to target different hosting environments, Web, Windows Service, Windows Activation

Page 21: Wcf Quickstart

Pizzeria Ivan Component Architecture

Page 22: Wcf Quickstart

Lessons Learned

Configuration complexity increases when using multiple services and clients in one applicationo .NET 4.0 WCF is touting less configuration.

One-way and two-way bindings require different contracts.o One-way operations must have a void return (Sub in

VB.Net) Very extensible but requires knowledge of WCF stack and

careful implementationo Example: Message handlers can corrupt messages if

used improperly Out of the box you still have to do some work to build

a properly scalable and maintainable service – WCF is not “drag & drop”o To an architect this is not a bad thing!

Page 23: Wcf Quickstart