Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA...

Post on 23-Dec-2015

219 views 0 download

transcript

Getting Started with Windows Communication Foundation 4.5

Ed Jones, MCT, MCPD, MCTSConsultantRBA Inc.

Welcome to TechFuse!

• Objective: To give you enough information to get started at building a WCF solution!

• To get the most out of this session, you need to know…– .NET Programming (all samples in C#)– Simple configuration (.config files)

Overview

• TechFuse Suites: our sample application• What does it mean to be SOA?• Contracts and Service Implementation• Bindings and Behaviors• Hosting the Service• Consuming WCF Services• What’s New in WCF 4.5?

TechFuse Suites• A simple service that allows one to make, alter, or cancel a

reservation at TechFuse Suites.• The reservation system is available to any client regardless of

type of code, native OS, etc.• Architecture

– The reservation system is a WCF 4.5 Service– The service is hosted in a Windows Service over http and netTcp– The database is SQL Server 2012– Supports multiple clients:

• Windows Forms• Java-Based (we’ll use the SOAP UI tool)

• Sample Code and Database available at: http://sdrv.ms/13ZU79u

Service Oriented Architecture and Principles

What is service orientation?

• Service-Oriented Architecture (SOA) is a set of principles and methodologies for designing and developing software in the form of interoperable services. These services are well-defined business functionalities that are built as software components (discrete pieces of code and/or data structures) that can be reused for different purposes. SOA design principles are used during the phases of systems development and integration.

-Wikipedia, “Service-Oriented Architecture”

Or better yet…

• A loosely-coupled architecture designed to meet the business needs of the organization.

SOA Design Principles

• Boundaries Are Explicit• Services Are Autonomous• Services Share Schema & Contract, Not Class• Service Compatibility Is Based Upon Policy

What is WCF?

• Windows Communication Foundation (WCF) is a framework for building service-oriented applications.

• It is a runtime and a set of APIs for creating systems that send messages between services and clients.

• WCF is the foundation for other distributed technologies by Microsoft, such as Azure, AppFabric, and BizTalk

How it works: A WCF Overview

WCF Contracts

Building out service and data contracts

WCF Contracts

• Contracts determine what data and operations are exposed

• Service contracts define operations• Data contracts define data (duh!)• And you’ve got other contracts, too– Message Contracts– Fault Contracts

A Contract Is Just a Schema…

Service Contracts

Data Contracts

TechFuse Suites: Contracts and Implementation

Configuring the Service

Bindings

• The binding controls the messaging details (what happens on the wire) for that endpoint.

• Common bindings are common recipes as to how WCF will configure the underlying channel stacks.

• There are countless extensibility points found throughout the WCF channel layer

Sample Binding (older WCF)

ABC’s: Address, Binding, Contract

TechFuse Suites: Configuration

Hosting the Service

Hosting the Service• A WCF Service is a library, it has no life of its

own• The host brings the WCF service to life by

providing the process in which it operates.• Most of the time, WCF services will run in a

ready-made host environment such as Internet Information Server (IIS) or Azure

• A lot of things require a host!

Creating the Host

• Create references to:– System.Runtime.Serialization– System.ServiceModel– Your WCF service assembly

• Create an instance of the ServiceHost class (System.ServiceModel.ServiceHost), passing in a reference to your own service class

• Call ServiceHost.Open() to start your service and ServiceHost.Close() to stop it.

• Configure the server settings in the .config file for the Host application.

TechFuse Suites: Host Application

Using a WCF Service

Creating a Client

Consuming a service

• Because WCF exposes service functionality through open standards, such as SOAP, you can use almost any type of client to consume the service.

• Allowing a .NET client to consume the service is as easy as creating a service reference or generating a proxy through a command-line utility (svcutil.exe)

• Non-.NET clients would typically use SOAP to consume a WCF Service

Creating the Client

• Create a proxy class by using svcutil.exe or creating a service reference.

• Configure the client settings in the .config file for the client application

• Call the open method on the proxy to establish a connection to the service and the close method to end it.

• Call the operations on the service as you would any method

A TechFuse Suites Client

Other Things You Can Do with WCF

• Secure Services• RESTful Services• Routing• Streaming• Discovery• Web Sockets• …and much, much, more

What’s New in WCF 4.5

• Config File Tootips, IntelliSense• Contract-First Generation• Generate Classes from Sample XML• ASP.NET compatibility mode defaults to “true”• WCF Configuration Validation• Streaming Improvements• Single WSDL• ChannelFactory Caching• UDP Support• HttpClient Class

Review

• What does it mean to be SOA?• Contracts and Service Implementation• Bindings and Behaviors• Hosting the Service• Consuming WCF Services• What’s New in WCF 4.5?

References• Wikipedia – “Service-Oriented Architecture”

http://en.wikipedia.org/wiki/Service-oriented_architecture• Stefan Tilkov, “10 Principles of SOA”

http://www.infoq.com/articles/tilkov-10-soa-principles• John Spacey, “The 9 Principles of Service Oriented Design”

http://simplicable.com/new/the-9-principles-of-soa-design • MSDN, “How to: Host a WCF Service in a Managed Windows Service”

http://msdn.microsoft.com/en-us/library/ms733069.aspx• MSDN, “What’s New in Windows Communication Foundation 4.5”

http://msdn.microsoft.com/en-us/library/dd456789.aspx • MSDN, “Basic WCF Programming” http://

msdn.microsoft.com/en-us/library/ms731067.aspx • MSDN, “Chapter 1: Service Oriented Architecture” http://

msdn.microsoft.com/en-us/library/bb833022.aspx

Thank You!

• Ed Jones,MCT, MCPD (Web, Azure), MCTS (WCF, BizTalk)– Email: ed.jones@rbaconsulting.com– Blog: http://talentedmonkeys.wordpress.com– LinkedIn: http://www.linkedin.com/in/edjjones/

http://www.rbaconsulting.com