windows communication foundation · 2013-01-17 · windows communication foundation page 5 unified...

44
Windows Communication Foundation Yoon Joong Kim Department of computer Engineering Hanbat National University

Upload: others

Post on 21-May-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Windows Communication Foundation

Yoon Joong Kim Department of computer Engineering

Hanbat National University

Page 2: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Contents

How We Got Here

WCF Contracts - Service / Data / Message

Bindings

Security

Reliability

Declarative

Summary

REST

Examples

Page 2

Page 3: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

From Objects to Services

Page 3

Resuable, Inheritance, Polymorphism

Encapsulation

Application is static

Message-based

Schema + Contract

Binding via Policy

1980s

2000s

Interface-based Dynamic Loading Runtime Metadata. x on scalable distribute software integration

1990s

Object-Oriented

Service-Oriented

Component-Based

Page 4: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

The Challenge Radically Simplifying Distributed Application Development

Page 4

Different programming models for different tasks

Need for security and reliable messaging

Interoperability with applications on other platforms

Productive service-oriented programming model needed

Page 5: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Windows Communication Foundation

Page 5

Unified framework for

rapidly building

service-oriented applications

Page 6: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

What Does WCF Replace?

Page 6

ASMX

WSE

.NET Remoting

COM+ (Enterprise Services)

MSMQ

Page 7: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

UNDERSTANDING WCF

PRINCIPLES

Page 8: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Services and Clients

Page 8

Client Service

Message

Message

Page 9: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Endpoints

Page 9

Client Service

Message Endpoint Endpoint

Endpoint

Page 10: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Address, Binding, Contract

Page 10

Client Service

Message

Address Binding Contract

(Where) (How) (What)

Endpoint

A B C A B C

Endpoints

A B C

Page 11: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

WCF Architecture: Messaging Runtime

Page 11

Transport

Encoder

Protocol(s)

Transport

Encoder

Protocol(s)

Client Dispatcher

Service Contract

and

Behaviors

Binding

Address

Page 12: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

CONTRACTS

The what

Page 13: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Three Types of Contracts

Page 13

Service Contract

Defines Operations,

Behaviors and Communication

Shape

What does your service do

Data Contract

Defines Schema and Versioning

Strategies

What obect data is used

Message Contract

Allows defining application-

specific headers and unwrapped

body content

Allows control over the SOAP

structure of messages

Page 14: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Ways to Talk

Page 14

One Way: - Datagram-style delivery

Request-Reply - Immediate Reply on same logical thread

Duplex - Reply “later” and on backchannel (callback-style)

Client Service

One Way

Request-Reply

Duplex (Dual)

Page 15: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

SERVICE CONTRACTS

What does your service do?

Page 16: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Service Contract

Page 16

using System.ServiceModel;

[ServiceContract]

public interface ICalculate

{

[OperationContract]

double Add( double a, double b);

[OperationContract]

double Subtract( double a, double b);

}

Page 17: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Service Contract: OneWay

[ServiceContract]

public interface IOneWayCalculator

{

[OperationContract(IsOneWay=true)]

void StoreProblem (ComplexProblem p);

}

Page 18: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Service Contract: Duplex Asymmetric

[ServiceContract(Session=true,

CallbackContract=typeof(ICalculatorResults)]

public interface ICalculatorProblems

{

[OperationContract(IsOneWay=true)]

void SolveProblem (ComplexProblem p);

}

public interface ICalculatorResults

{

[OperationContract(IsOneWay=true)]

void Results(ComplexProblem p);

}

Page 19: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

DATA CONTRACTS

What object data needs to flow back and forth?

Page 20: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Data Contract

[DataContract]

public class ComplexNumber

{

[DataMember] public double Real = 0.0D; [DataMember] public double Imaginary = 0.0D;

public ComplexNumber(double r, double i) { this.Real = r; this.Imaginary = i; }

}

Page 21: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

MESSAGE CONTRACTS

Defines the mapping between the type and a SOAP envelope

Page 22: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Message Contract

[MessageContract]

public class ComplexProblem

{

[MessageHeader] public string operation;

[MessageBody] public ComplexNumber n1;

[MessageBody] public ComplexNumber n2;

[MessageBody] public ComplexNumber solution;

// Constructors…

}

Page 23: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

BINDINGS

Page 24: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Transport

IPC MSMQ

Custom

TCP HTTP

Protocol

Encoders

.NET TX

Custom

Security Reliability

Binding

HTTP TX Security Reliability Text

Text

Binary

Custom

Bindings & Binding Elements

Page 25: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Standard Bindings

Page 26

Binding Interop Security Session TX Duplex

BasicHttpBinding BP 1.1 N, T N N n/a

WSHttpBinding WS M, T, X N, T, RS N, Yes n/a

WSDualHttpBinding WS M RS N, Yes Yes

WSFederationBinding Federation M N, RS N, Yes No

NetTcpBinding .NET T, M T ,RS N, Yes Yes

NetNamedPipeBinding .NET T T, N N, Yes Yes

NetPeerTcpBinding Peer T N N Yes

NetMsmqBinding .NET T, M, X N N, Yes No

MsmqIntegrationBinding MSMQ T N N, Yes n/a

N = None | T = Transport | M = Message | B = Both | RS = Reliable Sessions

Page 26: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Bindings & Behaviors: Security

Service

C B A

C B A

Client

A B C

C B A

Be Be

Bindings Insert Claims in Messages

Behaviors Implement

Security Gates

Page 27: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Feature Overview Security

Claims based end-to-end security

- Secure end-to-end message exchanges

- Secure access to resources

- Record resource access requests

X509, Username/Password, Kerberos, SAML, custom

credentials

Message security

- Confidentiality and integrity

- Transport or message level

Access to resources

- Authentication and authorization

Page 28

Page 28: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

DEMO - BINDINGS

Page 29: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Bindings & Behaviors: Transactions

Service

C B A

C B A

Client

A B C

C B A

Be Be

Bindings Flow Transactions

Behaviors AutoEnlist and AutoComplete

Page 30: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Service

C B A

C B A

Client

A B C

C B A

Bindings provide Session and Guarantees

Bindings & Behaviors: Reliable Sessions

Page 31: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Feature Overview Reliability and Transactions

End-to-end Reliable messaging - In-order guarantees

- Exactly once guarantees

Transport-Independent Sessions - Integration with ASP.NET Sessions in IIS-Hosted compatibility

mode

Transactions - Guaranteed atomic success or failure across services

Page 32: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

CODE VS. CONFIG

Page 33: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Defining Endpoints

<?xml version="1.0" encoding="utf-8" ?>

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

<system.serviceModel>

<services>

<service serviceType="CalculatorService">

<endpoint address="Calculator"

bindingSectionName="basicProfileBinding"

contractType="ICalculator" />

</service>

</services>

</system.serviceModel>

</configuration>

Page 34: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Configuring Bindings

<endpoint address="Calculator" bindingSectionName="basicProfileBinding" bindingConfiguration="Binding1" contractType="ICalculator" />

<bindings> <basicProfileBinding> <binding configurationName="Binding1" hostnameComparisonMode="StrongWildcard" transferTimeout="00:10:00" maxMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" </binding> </basicProfileBinding> </bindings>

Page 35: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Custom Bindings

<bindings>

<customBinding>

<binding configurationName="Binding1">

<reliableSession bufferedMessagesQuota="32" inactivityTimeout="00:10:00" maxRetryCount="8" ordered="true" />

<httpsTransport manualAddressing="false" maxMessageSize="65536" hostnameComparisonMode="StrongWildcard"/>

<textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Default" encoding="utf-8" />

</binding>

</customBinding>

</bindings>

Page 36: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

DEMO – MULTIPLE BINDINGS

Page 37: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

Application

Service Model

Messaging

Hosting Environments

ASP.NET WPF WinForm NT Service COM+

TCP Channel

HTTP Channel

Queue Channel

Secure Channel

Reliable Channel

Instance Behavior

Throttling Behavior

Type Integ. Behavior

Transaction Behavior

Concurrency Behavior

Error Behavior

Metadata Behavior

Binary Encoder

Text/XML Encoder

WAS

WCF Summary

Page 38: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

WCF Summary

WCF is the future of distributed computing

It combines the best of all existing Microsoft distributed computing stacks

It uses WS-* standards for interoperability and integration with existing solutions

WCF is available for Windows Vista, Windows XP SP2, Windows Server 2003, Windows Server 2008

Page 39: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

REST

ROA

- ROA(Service Oriented Architecture) is a web application architecture to

conform 4 principles as follows:

- Addressability(representing all resources with URI).

- Connectedness(connecting them organically and structurally).

- Statelessness(maintaining server without session state).

- Homogeneous Interfaces(utilizing 6 methods consistently).

REST

- REST(REpresentational State Transfer) is a web service design

standard to aim at the above 4 principals.

Page 40

The term representational state transfer was introduced and defined in 2000 by Roy Fielding in his doctoral dissertation

Page 40: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

REST

REST originally refers to a collection of architectural

principles:

- a stateless client/server protocol

- HTTP

- a set of well-defined operations

- GET : to retrieve resource

- PUT,POST : to generate new resource

- PUT : to modify resource

- DELETE : to delete resource

- HEAD : to retrieve metadata

- OPTION : to check method designed to support resource

- a universal syntax for resource-identification

- URL

- the use of hypermedia

- HTML, XML

Page 41

Page 41: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

SOAP and REST

Page 42

Page 42: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

REST vs SOAP Web Services

Advantages of REST web services are:

- Lightweight - not a lot of extra xml markup

- Human Readable Results

- Easy to build - no toolkits required

SOAP also has some advantages:

- Easy to consume - sometimes

- Rigid - type checking, adheres to a contract

- Development tools

Page 43

Page 43: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim

WCF examples

Ex4. An WCF Example - 4.1 WCF Service (default) and Client

- 4.1.1 Serivce : GetData(int)

- 4.2.1 Client

- 4.2 WCF Service and Client

- 4.2.1 Service : SayHellow()

- 4.2.2 Client

- 4.3 WCF Service and Client In DB

- 4.2.1 Service : getDirectorySql(), insertRecord()

- 4.2.2 Client

Ex5. WCF REST Service

- 5.1 REST Service : xmlData(string), jsonData(string),

getPhoneBook(string)

- 5.2 REST Client

- 5.3 How to use Fiddler to check the message content

Page 44

Page 44: Windows Communication Foundation · 2013-01-17 · Windows Communication Foundation Page 5 Unified framework for rapidly building service-oriented applications . Yoon joong Kim What

Yoon joong Kim Page 45

www.wins.or.kr

E-Mail: [email protected]

Conditions