You are on page 1of 33

Introduction To

SOA & WCF


Miguel A. Castro
miguel.castro@idesign.net
Miguel A. Castro

 .NET Architect, Developer, & Trainer


 Microsoft MVP
 ASP Insider
 VSX Insider
 Member of the INETA Speakers Bureau
 Conference Speaker ineta
 In IT business since 1986

miguel.castro@idesign.net
Agenda
• Service Oriented Architecture
• What is WCF?
• Creating & Consuming Services
• Service Components
• Hosting Services
• Configuration
• Best Practices
Service Oriented Architecture

“The decomposition of a
system into autonomous,
discoverable, and secure
units of responsibility and the
interoperable exposure of
said units.”
For a very cool T-Shirt:
Where is that definition from?

A. Martin Fowler’s “Patterns of Enterprise


Architecture”

B. Microsoft Patterns & Practices SOA Guidelines

C. I made it up myself
Service Oriented Architecture
• SOA separates applications into services.
• Services are orchestrators into down-level business
layers.
• Allows connectivity of dissimilar technologies.
• Is NOT a product. It is an architecture and design
paradigm.
• Next evolution of programming paradigms.
Programming Paradigms

Procedural Programming
Applications were developed by continuously calling functions
that housed various areas of functionality.

Problems:
• No reuse outside of application.
• No design analogy to real-world made for
cumbersome development process.
Programming Paradigms

Object Oriented Programming Procedural Programming

Procedural Programming

Applications were developed by continuously calling functions that housed various areas of
functionality.

Applications were built by working with Problems:


• No reuse outside of application.
• No design analogy to real-world made for
cumbersome development process.

various entities that resembled real-world


counterparts, housing both data and
behavior.

Problems:
• No reuse outside of application.
• Required lots of plumbing for
managing ancillary functionality
(reliability, transactions, security, etc.).
Programming Paradigms

Component Oriented Programming


Procedural Programming
Procedural Programming

Objects could now be encapsulated and Applications were developed by continuously calling functions that housed
various areas of functionality.

managed by a common abstraction layer


Problems:
• No reuse outside of application.
• No design analogy to real-world made for
cumbersome development process.

(COM) and housed in separate libraries


(DLLs). Object Oriented Programming
Object Oriented Programming

Applications were built by working

Problems:
with various entities that
resembled real-world counterparts,
housing both data and behavior.
• Ancillary functionality typically Problems:
• No reuse outside of application.

required • Required lots of plumbing for


managing ancillary
functionality (reliability,

external service management transactions, security, etc.).

(MTS, COM+, Corba).


Programming Paradigms
Service Oriented Programming Procedural Programming
Procedural Programming

Applications were developed by continuously calling functions that housed


various areas of functionality.

Objects are managed and encapsulated Problems:


• No reuse outside of application.
• No design analogy to real-world made for

within autonomous services, each with its


cumbersome development process.

own set of responsibilities. Object Oriented Programming


Object Oriented Programming

Applications were built by working


with various entities that
resembled real-world counterparts,

Problems:
housing both data and behavior.

Problems:

• Needs a good “glue” technology to • No reuse outside of application.


• Required lots of plumbing for
managing ancillary

handle cumbersome plumbing for


functionality (reliability,
transactions, security, etc.).

ancillary technologies. Component Oriented Programming

• Requires a technology that


Component Oriented Programming

Objects could now be encapsulated and

accommodates interoperability.
managed by a common abstraction layer
(COM) and housed in separate libraries (DLLs).

Problems:
• Ancillary functionality typically required
external service

Enter WCF !
management (MTS, COM+, Corba).
Service Oriented Architecture
• It is NOT a replacement for Components or Objects.
• Usually incorporate object-oriented engines behind a
service.
• Will not help you fix bad architecture practices.
• Mistakes can still be made behind a service wall
Service Oriented Architecture

Presentation Tier - (Web Browser)


Client Tier
(Desktop Applications, Client
Unmanned Processes) Desktops or
UI (Client) Tier – (IIS)
Browser
applications
Business Client Layer (Service Proxies)

Service Layer

Business/ORM Engine Business/ORM Engine


Business
Service Layer
Data Access Layer Data Access Layer communi-
cates with
Business
Client Layer
Database Tier Database Tier
Service Oriented Architecture
• What is a service?
• Encapsulated units of responsibility.
• Atomic
• Durable
• Secure
• Always leave a system in a consistent state
• Services are rock-solid at handing their unit of
responsibility.
• Services are typically an orchestration layer atop one
or more fine-grain business engines.
Enter WCF
• Windows Communication Foundation
• The artist formerly known as Indigo
• Provide a unified communication model.
• Web Services
• Remoting
• Sockets
• Enterprise Services
• MSMQ
Enter WCF
• Enforces an SOA approach.
• More than ASMX anyway.
• Provides a declarative and pseudo-aspect-oriented
model for managing functionality.
• Transactions
• Security
• Durability
• Etc.
• Provides ability to concentrate on service logic
• Despite transport
• Not always the case (i.e. MSMQ & REST)
WCF Breakdown
• System.ServiceModel
• Assembly & Namespace
• Data Contracts
• Service Contracts
• Services
• Service Host
• Client Proxy
• Configuration
Service Contracts
• Interfaces that define service operations which work
with single types or data contracts.
• Interface decorated with [ServiceContract]
• Operations decorated with [OperationContract]
Data Contracts
• Defines the data that is to be received and/or returned
by a service.
• Not necessary if said data are single types.
• Must be serializable using the new [DataContract].
• System.Runtime.Serialization
• Opt-In serializer
Service Classes
• Classes that provide the service implementation.
• Can implement one or more service contract.
• Implementation includes anything necessary to build
and return the data contract.
Service Hosting
• Can take three shapes:
• IIS
• Self-Hosting
• WAS
Service Hosting
• IIS can host only HTTP services.
• Self-Hosting can be ANY application.
• WAS can host any protocol.
• Uses IIS for administration.
• Available in Vista and Server 2008

Create the contracts, service, and self-host


Configuring Your Service
<system.serviceModel>
<services>
<service name=“{service type}”>
{endpoint goes here}
</service>
</services>
</system.serviceModel>
Endpoint Configuration
• <endpoint> config section.
• The ABCs or WCF
• address
This defines the
• Defines where clients can find your service.
service’s EndPoint
• binding
• Defines the transport protocol.
• contract
• Defines what operations service will expose.

Configure the host


Accessing the Service
• Clients communicate by way of a proxy class.
• Proxy class opens channel to service.
• Makes calls to service operations.
• Proxy expects to find client configuration.
• Can also be done programmatically.
• Proxies need access to the service contracts and data
contracts.
• NOT the services themselves.
Proxy Classes
• Derivative of System.ServiceModel.ClientBase<T>
• T is the service contract interface.
• Class also implements the service contract.
• Methods make similar calls to methods of Channel.
Configuring Your Client
<system.serviceModel>
<client>
{endpoint goes here}
</client>
</system.serviceModel>

Create proxies, client, and configure client


Choosing a Binding

Inside
YES Firewall NO
and
.NET-.NE
T?
NO
Local
Only?
YES Support
NO Legacy? YES
Need to
Disconnect?
NO YES

NetTcp NetMsmq NetNamedPipe WsHttp BasicHttp


Binding Binding Binding Binding Binding
Additional Technologies
• Transactions
• Throttling
• Instancing
• Concurrency
• Tracing & Logging
• Queuing
• Version Tolerance
• Callbacks
Benefits of WCF Services

All WCF-based classes (services) benefit from:

• Encrypted Calls • Durability


• Authentication • Error Masking
• Identity Propagation • Fault Isolation
• Authorization • Channel Faulting
• Security Audits • Buffering
• Transaction Propagation • Throttling
• Transaction Voting • Versioning
• Call Timeout • Synchronization
• Reliability • Remotability
• Tracing • Interoperability
• Logging • Queuing
• Instance Management
Benefits to SOA
• Location independence
• Interoperability across platforms
• API-like development paradigm
• Better organization than object distribution
• Loose Coupling
• Services exposed across the enterprise
• Security
• With WCF, lots of feature from which to benefit
Summary
• WCF provides a unified and robust model for
developing service oriented applications.
• The WCF runtime provides further management of
classes written in regular C#/VB.
• WCF encapsulates classes and provides many
enterprise management features
• WCF enforces SOA.
• Binding options provide many levels of accessibility
and security.
• Hosting options allow for many creative scenarios.
References
• Learning WCF
• O’Reiley - Michele Lereux-Bustamante (IDesign)
• Programming WCF
• O’Reiley - Juval Lowi (IDesign)
• Pro WCF
• Apress - Chris Peiris & Dennis Mulder
• Essential WCF
• Addison-Wesley – Chris Bowen, et. al.
• IDesign WCF Master Class
• www.idesign.net
Stay in touch…

Miguel A. Castro

miguel.castro@idesign.net

@miguelcastro67

www.dotnetdude.com

You might also like