getting started with windows communication foundation 4.5 ed jones, mct, mcpd, mcts consultant rba...

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

Upload: kory-oneal

Post on 23-Dec-2015

221 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

Getting Started with Windows Communication Foundation 4.5

Ed Jones, MCT, MCPD, MCTSConsultantRBA Inc.

Page 2: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA 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)

Page 3: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

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?

Page 4: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

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

Page 5: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

Service Oriented Architecture and Principles

Page 6: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

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”

Page 7: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

Or better yet…

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

Page 8: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

SOA Design Principles

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

Page 9: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

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

Page 10: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

How it works: A WCF Overview

Page 11: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

WCF Contracts

Building out service and data contracts

Page 12: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

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

Page 13: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

A Contract Is Just a Schema…

Page 14: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

Service Contracts

Page 15: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

Data Contracts

Page 16: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

TechFuse Suites: Contracts and Implementation

Page 17: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

Configuring the Service

Page 18: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

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

Page 19: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

Sample Binding (older WCF)

Page 20: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

ABC’s: Address, Binding, Contract

Page 21: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

TechFuse Suites: Configuration

Page 22: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

Hosting the Service

Page 23: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

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!

Page 24: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

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.

Page 25: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

TechFuse Suites: Host Application

Page 26: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

Using a WCF Service

Creating a Client

Page 27: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

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

Page 28: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

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

Page 29: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

A TechFuse Suites Client

Page 30: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

Other Things You Can Do with WCF

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

Page 31: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

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

Page 32: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

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?

Page 33: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

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

Page 34: Getting Started with Windows Communication Foundation 4.5 Ed Jones, MCT, MCPD, MCTS Consultant RBA Inc

Thank You!

• Ed Jones,MCT, MCPD (Web, Azure), MCTS (WCF, BizTalk)– Email: [email protected]– Blog: http://talentedmonkeys.wordpress.com– LinkedIn: http://www.linkedin.com/in/edjjones/

http://www.rbaconsulting.com