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

Post on 21-May-2020

3 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Windows Communication Foundation

Yoon Joong Kim Department of computer Engineering

Hanbat National University

Yoon joong Kim

Contents

How We Got Here

WCF Contracts - Service / Data / Message

Bindings

Security

Reliability

Declarative

Summary

REST

Examples

Page 2

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

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

Yoon joong Kim

Windows Communication Foundation

Page 5

Unified framework for

rapidly building

service-oriented applications

Yoon joong Kim

What Does WCF Replace?

Page 6

ASMX

WSE

.NET Remoting

COM+ (Enterprise Services)

MSMQ

Yoon joong Kim

UNDERSTANDING WCF

PRINCIPLES

Yoon joong Kim

Services and Clients

Page 8

Client Service

Message

Message

Yoon joong Kim

Endpoints

Page 9

Client Service

Message Endpoint Endpoint

Endpoint

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

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

Yoon joong Kim

CONTRACTS

The 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

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)

Yoon joong Kim

SERVICE CONTRACTS

What does your service do?

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);

}

Yoon joong Kim

Service Contract: OneWay

[ServiceContract]

public interface IOneWayCalculator

{

[OperationContract(IsOneWay=true)]

void StoreProblem (ComplexProblem p);

}

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);

}

Yoon joong Kim

DATA CONTRACTS

What object data needs to flow back and forth?

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; }

}

Yoon joong Kim

MESSAGE CONTRACTS

Defines the mapping between the type and a SOAP envelope

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…

}

Yoon joong Kim

BINDINGS

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

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

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

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

Yoon joong Kim

DEMO - BINDINGS

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

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

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

Yoon joong Kim

CODE VS. CONFIG

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>

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>

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>

Yoon joong Kim

DEMO – MULTIPLE BINDINGS

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

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

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

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

Yoon joong Kim

SOAP and REST

Page 42

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

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

Yoon joong Kim Page 45

www.wins.or.kr

E-Mail: yjkim@hanbat.ac.kr

Conditions

top related