introduction wcf definition wcf architecture implementation wcf demo overview

Post on 19-Dec-2015

273 Views

Category:

Documents

9 Downloads

Preview:

Click to see full reader

TRANSCRIPT

IntroductionWCF DefinitionWCF ArchitectureImplementationWCF Demo

Overview

Introduction

Web Services Everywhere…

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

Client Invoking a Web Service

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

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

WCF Definition

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

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

Windows Communication Foundation (WCF)

A unified development model

WindowsCommunication

Foundation

Many confusing and complicated options

Remoting COMDCOM

COM+MSMQ

WSEASMX

A Unified Programming Model

WCF Architecture

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

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

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

Windows Forms application

Windows Console application

Windows service

WPF application

Hosting a WCF Service in a Self-Hosted Managed Application

Implementation

• 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

• 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

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

<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

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

WCF Service HostWCF Service Library

Contract

Implementation

Configuration

WCF solution

Host code

Separation of Concerns in a WCF Service

Best Practices

Best Practices

WCF Demo

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

top related