wcf quickstart

Post on 11-Jun-2015

2.750 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

DESCRIPTION

WCF Quickstart presentation from St Louis Day of .NET 2009

TRANSCRIPT

WCF Quick Start with Chris Deweese

.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

Agenda

Why & What of WCF Building a service Lessons Learned

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

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

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

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.

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

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

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

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”

Hosting WCF Services

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

o WAS allows you to host a service on any binding

WCF Architecture

Demo Service – Pizzeria Ivan

Pizzeria Ivan

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

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

If you build it…they will come.

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

Pizzeria Ivan Component Architecture

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!

top related