Introduction WCF Definition WCF Architecture Implementation WCF Demo Overview.

26
  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    249
  • download

    9

Transcript of Introduction WCF Definition WCF Architecture Implementation WCF Demo Overview.

Page 1: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.
Page 2: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

IntroductionWCF DefinitionWCF ArchitectureImplementationWCF Demo

Overview

Page 3: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

Introduction

Page 4: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

Web Services Everywhere…

Page 5: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

Web Services Components

Universal Description Discovery and Integration, example

Web Services Description Language

Define the structure of an XML document, just like a DTD

Simple Object Access Protocol

Page 6: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

Client Invoking a Web Service

Page 7: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

POST SimpleService.asmx/EchoString HTTP/1.1 Host: localhost:1489 User-Agent: Mozilla/5.0 Accept: text/html Content-Type: application/json; Content-Length: 27 ...

XML, JSON, SOAP, AtomPub ...

HTTP Communication

Headers

Data

Verb URL

Page 8: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

POST SimpleService.asmx/EchoString HTTP/1.1 Host: localhost:1489 User-Agent: Mozilla/5.0 Accept: text/html,application/xhtml+xml Content-Type: application/json; Content-Length: 27 ...

{"Age":37,"FirstName":"Eyal",

"ID":"123", "LastName":"Vardi“ }

Headers

Data

Verb URL

<Envelope> <Header> <!–- Headers --> <!-- Protocol's & Polices --> </Header> <Body> <!– XML Data --> </Body> </Envelope>

JSON vs. SOAP

Page 9: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

WCF Definition

Page 10: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

Visual Studio 2008Visual Studio 2008

Clarifying Version Confusion…

.NET Framework 3.5.NET Framework 3.5

.NET Framework 3.0 + .NET Framework 3.0 + SP1SP1

.NET Framework 2.0 + .NET Framework 2.0 + SP1SP1

Windows Windows Presentation Presentation FoundationFoundation

Windows Windows Communication Communication

FoundationFoundation

Windows Windows Workflow Workflow

Foundation Foundation

Windows Windows CardSpaceCardSpace

Page 11: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

• WCF designed to offer a manageable approach to:– Distributed computing.– Broad interoperability.– Direct support for service orientation.

Windows Communication Foundation (WCF)

Page 12: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

A unified development model

WindowsCommunication

Foundation

Many confusing and complicated options

Remoting COMDCOM

COM+MSMQ

WSEASMX

A Unified Programming Model

Page 13: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

WCF Architecture

Page 14: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

Client ServiceWCF

dispatcherProxy

Message EncodingEncoding

Transportchannel

Transportchannel

ChannelChannelChannelChannel

ChannelChannel

Transportchannel

Transportchannel

EncodingEncodingBindingBinding

ChannelChannelChannelChannel

ChannelChannel EndpointsEndpoints

Listen for messages on one or more endpoints.

Proxy object used to send messages to the service.

Proxy hides communications complexity, and makes the remote service appears as local object.

Matching Binding

Sending a WCF Message

Page 15: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

Service

.NET Classesand Interface

ServiceHost

Service Contracts or Metadata Exchange

mex enables communication without prior knowledge of the contract (metadata about the service).

IIS / Standalone Managed Application

Structure of a Service

Page 16: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

Service

Where to find the service

Example: http://localhost:8001/MathService

Where to find the service

Example: http://localhost:8001/MathService

AddressAddress

How to communicate with the service

Example: BasicHttpBinding

How to communicate with the service

Example: BasicHttpBinding

BindingBinding

What the service can do for you

Example: [OperationContract]int Add(int num1, int num2);

What the service can do for you

Example: [OperationContract]int Add(int num1, int num2);

ContractContract

The ABC of Endpoints

Page 17: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

Windows Forms application

Windows Console application

Windows service

WPF application

Hosting a WCF Service in a Self-Hosted Managed Application

Page 18: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

Implementation

Page 19: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

• Contracts for services, data, and messages– A contract is simply an interface declaration

• Service, Data, and Message definitions– Class implementations

• Configurations defined programmatically or declaratively– config files.

• A host process (can be self hosted)– IIS, Windows Executable, Windows Service, or WAS

• .Net Framework (3.5) Classes provide support for all of the above.

Essential Pieces of WCF

Page 20: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

• IService.cs– Interface(s) that define a service, data, or message

contract• Service.cs

– Implement the service’s functionality• Service.svc

– Markup file (with one line) used for services hosted in IIS • Configuration files that declare service attributes,

endpoints, and policy– App.config (self hosted) contains service model markup– Web.config (hosted in IIS) has web server policy markup

plus service model markup, as in App.config

WCF Service Files

Page 21: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

using System;using System.ServiceModel;

namespace ConnectedWCF{ [ServiceContract(Namespace="http://myuri.org/Simple") ] public interface IBank { [OperationContract] decimal GetBalance(string account);

[OperationContract] void Withdraw(string account, decimal amount);

[OperationContract] void Deposit(string account, decimal amount); }

using System;using System.ServiceModel;

namespace ConnectedWCF{ [ServiceContract(Namespace="http://myuri.org/Simple") ] public interface IBank { [OperationContract] decimal GetBalance(string account);

[OperationContract] void Withdraw(string account, decimal amount);

[OperationContract] void Deposit(string account, decimal amount); } Attributes control exposure of types and methods

Example of a Simple Contract

Page 22: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

<system.serviceModel> <services> <service name="ConnectedWCF.BankService"> <endpoint address="BankService" binding="basicHttpBinding" contract="ConnectedWCF.IBank"/> <host> <baseAddresses> <baseAddress baseAddress="http://localhost:8080/Simple"/> </baseAddresses> </host> </service> </services></system.serviceModel>

<system.serviceModel> <services> <service name="ConnectedWCF.BankService"> <endpoint address="BankService" binding="basicHttpBinding" contract="ConnectedWCF.IBank"/> <host> <baseAddresses> <baseAddress baseAddress="http://localhost:8080/Simple"/> </baseAddresses> </host> </service> </services></system.serviceModel>

• Root element is system.serviceModel• WCF-specific elements below this have various properties and sub elements

Identifying WCF Entries in Configuration Files

Page 23: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

ServiceClass

ServiceInterface

ServiceMetadata

Implements

RunningService

ServiceProxy

Implements

ServiceAssembly

ProxyArtifacts

GenerateGenerateGenerateGenerate

GenerateGenerate

ServiceModel Metadata Utility Tool (Svcutil.exe) generates metadataand artifacts

ServiceModel Metadata Utility Tool (Svcutil.exe) generates metadataand artifacts

http://msdn.microsoft.com/en-us/library/aa347733(v=VS.90).aspx

Contracts, Metadata, and Artifacts

Page 24: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

WCF Service HostWCF Service Library

Contract

Implementation

Configuration

WCF solution

Host code

Separation of Concerns in a WCF Service

Best Practices

Best Practices

Page 25: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

WCF Demo

Page 26: Introduction  WCF Definition  WCF Architecture  Implementation  WCF Demo Overview.

WCF Standard Bindings

NameName TransporTransportt

EncodingEncoding InteroInteropp

BasicHttpBindingBasicHttpBinding HTTP/HTTPSHTTP/HTTPS TextText YesYes

NetTcpBindingNetTcpBinding TCPTCP BinaryBinary NoNo

NetPeerTcpBindingNetPeerTcpBinding P2PP2P BinaryBinary NoNo

NetNamedPipeBindingNetNamedPipeBinding IPCIPC BinaryBinary NoNo

WSHttpBindingWSHttpBinding HTTP/HTTPSHTTP/HTTPS Text, MTOMText, MTOM YesYes

WSFederationBindingWSFederationBinding HTTP/HTTPSHTTP/HTTPS Text, MTOMText, MTOM YesYes

WSDualHttpBindingWSDualHttpBinding HTTP/HTTPSHTTP/HTTPS Text, MTOMText, MTOM YesYes

NetMsmqBindingNetMsmqBinding MSMQMSMQ BinaryBinary NoNo

NetIntegrationBindingNetIntegrationBinding MSMQMSMQ BinaryBinary YesYes