introducing wcf

48
Introducing WCF Dhananjay Kumar http://debugmode.ne t DEBUGMODE_

Upload: finna

Post on 06-Jan-2016

61 views

Category:

Documents


4 download

DESCRIPTION

http://debugmode.net. DEBUGMODE_. Introducing WCF. Dhananjay Kumar. From Objects to Services. Object-Oriented. Polymorphism Encapsulation Subclassing. 1980s. Component-Based. Interface-based Dynamic Loading Runtime Metadata. 1990s. Service-Oriented. Message-based Schema+Contract - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Introducing WCF

Introducing WCF

Dhananjay Kumar

http://debugmode.netDEBUGMODE_

Page 2: Introducing WCF

From Objects to Services

PolymorphismEncapsulationSubclassing

Message-basedSchema+ContractBinding via Policy

1980s

2000s

Interface-basedDynamic LoadingRuntime Metadata

1990s

Object-Oriented

Service-Oriented

Component-Based

Page 3: Introducing WCF

WCF

Unified framework for

rapidly building

service-oriented

applications

Page 4: Introducing WCF

WCF

4Microsoft Innovation & Practice Team, MSCoE

Service Oriented programming model to develop connected applications

SDK to develop and deploy services on windows

Unifies the existing suite of .Net distributed technologies into a single programming model.

Page 5: Introducing WCF

Services and Clients

Client Service

Message

Message

Page 6: Introducing WCF

Endpoints

Client Service

MessageEndpoint Endpoint

Endpoint

Page 7: Introducing WCF

End Points

End Point

Binding

AddressContracts

Microsoft Innovation & Practice Team, MSCoE 7

Page 8: Introducing WCF

End Point

8

ADDRESS •Where

BINDING •How

CONTRACT •What

Page 9: Introducing WCF

A+B+C

Client Service

MessageABC A B C

A B C

Address Binding Contract

(Where) (How) (What)

Page 10: Introducing WCF

Address (A)Every service is associated with a unique

address.

10

Location of the

Service

Transport

protocol used

in service

Address of the

Service

Page 11: Introducing WCF

Address (A)

11

Address specifies where the service is residing.

This is an URL( Uniform Resource Locator).

Address URL identifies , location of the service

Address should follow the Web Service Addressing(WS-Addressing) standard.

Page 12: Introducing WCF

Address (A)

12

WS Addressing

Scheme Machine Port Path

Page 13: Introducing WCF

Address (A)

13

•This is top level portion of the address. This is not as same as of protocols.Scheme•This identifies the machine name. This can be a public URL or a local identifierMachine•This is port number. This is an optional part.Port•This is used to locate the path. This gives path of the service.Path

Page 14: Introducing WCF

Address (A)

14

HTTP •http://localhost:8001/Dell•http://localhost/Dell

TCP •net.tcp://localhost:800/Dell•net.tcp://localhost/Dell

MSMQ •net.msmq/private/MyService•Net.msmq/://localhost/Dell

IPC •net.pipe://localhost/MyPipe

Peer network •Net.pipe://localhost.MyService

Page 15: Introducing WCF

Binding (B)

15

Describes how a service communicates.

This specifies which Protocol to be used.

This specifies the encoding method to format the message content.

This specifies the Security requirements

This specifies the message exchange format.

This specifies message session mode.

Developer could create custom Binding also.

Page 16: Introducing WCF

Binding (B)

16

Transport Protocol

Message Encoding

Communication Pattern

Security

Transaction Property

Inter Operability

Page 17: Introducing WCF

Binding (B)

basicHttpBinding

17

This is interoperable binding and commonly used as replacement for earlier web service based on ASMX

This is designed to expose WCF service as legacy ASMX service such that old client can work with.

This also enables WCF client to work with ASMX

It supports HTTP & HTTPS protocols.

It supports MTOM/text encoding.

Page 18: Introducing WCF

Binding (B)wsHttpBinding

18

This is a secure and interoperable binding

This uses SOAP over HTTP.

This supports reliability, transaction and security over Internet.

This supports HTTP/HTTPS protocol.

This supports text and MTOM encoding.

This is default binding provided by WCF.

This Binding is interoperate with any party that supports WS standards.

Page 19: Introducing WCF

Binding (B)wsFederationHttpBinding

19

This is a secure Binding.

This is interoperable binding.

This supports federated security

This supports Https/Https protocols.

This uses text/MTOM encoding.

This supports Federated Identity.

Page 20: Introducing WCF

Binding (B)webHttpBinding

20

This is a secure Binding.

This is interoperable binding.

It only supports Http/Https protocol

It does not use SOAP style of message .

It uses REST style of message.

It is mainly used for REST enabled services.

Page 21: Introducing WCF

Binding (B)wsDualHttpBinding

21

This supports all the feature of wsHttpBinding

This is mainly used for DUPLEX SERVICE CONTRACTS.

This supports bidirectional communication.

This is not a interoperable binding.

Page 22: Introducing WCF

Binding (B)netTCPBinding

22

This is optimize to use if client is also a WCF machine.

This is a secure Binding.

This is used to send Binary encoded SOAP message from one WCF computer to another.This uses TCP (Transmission Control Protocol) for cross machine communication on the Intranet.

This supports reliability, transaction, security.

This requires both the client and service to use WCF.

Page 23: Introducing WCF

Binding (B)netNamedPipeBinding

23

This is most secure Binding.

This could be used over a single WCF computer.

This sends Binary encoded SOAP message over named pipes.

This uses named pipes as transport for same machine communication.

Page 24: Introducing WCF

Binding (B)netMSMQBinding

24

This is designed to offer support for disconnected queued calls.

This is a queued Binding.

This uses Binary encoded SOAP message

This sends message over MSMQ.

Here communication should occur between two computers.

Page 25: Introducing WCF

Binding (B)netPeerTCPBinding

25

This is a secure Binding.

This uses TCP over peer to peer.

Communication should occur between two or more computers.

Page 26: Introducing WCF

Binding (B)basicHttpContextBinding

26

This Binding is same as of basicHttpBinding with more attributes

It supports HTTP cookies

It enables SOAP headers to exchange context

This binding is mainly used for Durable services.

Page 27: Introducing WCF

Binding (B) Choosing Binding

27

WCF To

WCF

DisconnectedCalls

LegacyASMX

CrossMachine

WS Basic IPC TCP MSMQ

No

Yes

Yes

Yes

Yes

NoNo

No

Page 28: Introducing WCF

Binding (B)Binding Classes

28

Binding Name as of class Transport Encoding Interoperable

BasicHttpBinding HTTP/HTTPS Text,MTOM YesNetTcpBinding TCP Binary NoNetPeerBinding P2P Binary NoNetNamedPipeBinding IPC Binary NoWSHttpBinding HTTP/HTTPS Text,MTOM YesWSFederationHttpBinding HTTP/HTTPS Text,MTOM YesWSDualHttpBinding HTTP Text,MTOM YesNetMsmqBinding MSMQ Binary NoMsmqIntegrationBinding MSMQ Binary Yes

Page 29: Introducing WCF

Binding (B)Configuring Binding

29

<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 30: Introducing WCF

Service Contract (C)

30

A WCF Contract is a collection of Operations

All WCF services exposes contract.

This is a platform neutral and standard way to say , what the service will do.

Defines , what a Service communicates.

Page 31: Introducing WCF

Contract (C)

Types of Contracts

31

31

Service Contract • Describes which operation client can perform on the services.

Data Contract • Defines which Data Type are passed to and from

the services. It provides built-in contract for implicit type.

Fault Contract • Which error raise by service and how service propagates and handles error to its client.

Message Contract • Allow the service to interact directly with the

message . Message contract can be typed or un typed. This can be used for interoperability.

Page 32: Introducing WCF

Contract (C)Service Contract

32

A Service Contract reflects specific business

Describe which operations client can perform

Maps CLR types to WSDL

Page 33: Introducing WCF

Contract (C)Service Contract

33

Interfaces are used to explicitly define a Contract

Classes may also be used to define a Contract.

[ServiceContract] attribute is being used by interface/class to qualify them as a contract.

ServiceContract are implicitly public.

Page 34: Introducing WCF

Contract (C)Service Contract

34

// Define a service contract. [ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")] public interface IDataContractCalculator { [OperationContract] ComplexNumber Add(ComplexNumber n1, ComplexNumber n2); [OperationContract] ComplexNumber Subtract(ComplexNumber n1, ComplexNumber n2); [OperationContract] ComplexNumber Multiply(ComplexNumber n1, ComplexNumber n2); [OperationContract] ComplexNumber Divide(ComplexNumber n1, ComplexNumber n2); }

Page 35: Introducing WCF

Contract (C)Data Contract

35

These are the contractual agreement about the format and structure of the payload data in message exchange between a service and its consumer.

Defines which Data types are passed to and from the service.

Its specifies CLR type to XML schema.

Page 36: Introducing WCF

Contract (C)Data Contract

36

DataContract are preferred WCF way to enable Serialization.

WCF defines implicit contract for built in types like int and string.

Developer has to explicitly expose complex types as Data Contract.

[DataContract] and [DataMember] attribute are used to define a type as Data Contract.

Page 37: Introducing WCF

Contract (C)Data Contract

37

[DataContract] public class ComplexNumber { [DataMember] public double Real = 0.0D; [DataMember] public double Imaginary = 0.0D; }

Page 38: Introducing WCF

Contract (C)Message Contract

38

It gives control over SOAP message structure on both header and body content.

Developer can designate optional SOAP headers.

It provides additional control over the WSDL generation.

It is used to interoperate with another non- WCF service.

It is used to control security issue at level of message.

Page 39: Introducing WCF

Contract (C)Fault Contract

39

This translates .Net Exception to SOAP fault propagated to consumer

This can be applied to operation only.

This is not Inheritable.

This can be applied multiple times.

This enables developer to declare which faults a given service operation might issue if things goes wrong.

Page 40: Introducing WCF

Creating End Point

40

Could be created declaratively in configuration file.

Could be created imperatively through code.

Any thing done through code can be done with configuration file and vice versa.

It is considered good practice to use configuration file to specify End points. This accommodates changes without recompiling the code.

Page 41: Introducing WCF

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 42: Introducing WCF

Multiple End Point

42

For service exposed to multiple clients ; it makes sense to specify more than one End point.

This enables client to use the endpoint that is most applicable for them.

When creating multiple endpoints each client must have unique address

If two client uses the same address , error will raise at service load time.

Page 43: Introducing WCF

Multiple End Point

43

• <endpoint address="http://localhost:8890/a" binding="wsHttpBinding" contract="HotsingSamples.IService1"/>

• <endpoint address="http://localhost:8000/b" binding="basicHttpBinding" contract="HotsingSamples.IService1"/>

• <endpoint address="net.tcp://localhost:8001/c" binding="netTcpBinding" contract="HotsingSamples.IService1"/>

Page 44: Introducing WCF

Hosting

44

WCF services can not exist in void.

It must be hosted.

WCF services are hosted in windows process called host process.

A single host process can host multiple service.

A same service can be hosted in multiple host process.

Page 45: Introducing WCF

Creating WCF Service

45

Defining .Net service interface to serve as the Service contract

Implement Service Contract in .Net class as Service type and configure its behavior

Configure the End Point where service will expose , by specifying A,B,C

Host Service type in application using WCF hosting infrastructure

At client side ,By using description of target End Point create PROXY. And write code against this Proxy.

Page 46: Introducing WCF

WCF basic task cycle

1. Defining Service

Contract

2. Implementin

g Service Contract

3. Configuring

Services4. Hosting Services

5 . Building Clients

46

Page 47: Introducing WCF

Architecture: Messaging Runtime

Transport

Encoder

Protocol(s)

Transport

Encoder

Protocol(s)

ClientDispatcher

Service Contractand

Behaviors

Binding

Address

Page 48: Introducing WCF

Q & A

Dhananjay Kumar

http://dhananjaykumar.netDEBUGMODE_