windows communication foundation

35
WINDOWS COMMUNICATION FOUNDATION www.otssolutions.com

Upload: deepika-chaudhary

Post on 24-May-2015

1.091 views

Category:

Technology


3 download

DESCRIPTION

OTS Solutions is a leading Software Development Company; make use of latest technologies like ASP.NET, WCF, Ajax-enabled WCF and REST WCF Services by its skilled Developers.

TRANSCRIPT

Page 1: WINDOWS COMMUNICATION FOUNDATION

WINDOWS COMMUNICATION FOUNDATION

www.otssolutions.com

Page 2: WINDOWS COMMUNICATION FOUNDATION

Agenda

Introduction to WCFWhat is it? Why use it?Architecture Fundamentals and the ABCs of WCFHosting

Tooling Support Handling faults

Page 3: WINDOWS COMMUNICATION FOUNDATION

Introduction to WCF

Page 4: WINDOWS COMMUNICATION FOUNDATION

What is WCF?

Stands for Windows Communication Foundation One of the 4 pillars of .NET 3.0 Microsoft’s unified programming model (the service model) for building Service-Oriented Applications

Page 5: WINDOWS COMMUNICATION FOUNDATION

Different technology combined to form WCF.

Page 6: WINDOWS COMMUNICATION FOUNDATION

WCF Architecture

Page 7: WINDOWS COMMUNICATION FOUNDATION

SOA

ServiceSmall program interacted by well defines

message exchangesAgile, Reliable, Stable, Interoperable, Secure

Four TenetsBoundaries are ExplicitServices are AutonomousServices share schema and contract, not classService compatibility is based upon policy

Page 8: WINDOWS COMMUNICATION FOUNDATION

SOA solutions used

Page 9: WINDOWS COMMUNICATION FOUNDATION

SOA Use for Mobile platforms

Page 10: WINDOWS COMMUNICATION FOUNDATION

Windows Communication Foundation WCF provides:

an SDK for creating SOAa runtime for running Services on

Windows Services send and receive messages All messages are SOAP messages WCF takes care of all the plumbing

Page 11: WINDOWS COMMUNICATION FOUNDATION

Why use WCF?

Interoperable and Standards basedSupports WS-* protocols

Unified Programming ModelUnifies previous models like .NET

Remoting, ASMX web services, COM+ etc Productive Programming Model

Declarative ImperativeConfiguration based

Page 12: WINDOWS COMMUNICATION FOUNDATION

WCF Value Proposition Simplicity Flexibility Maintainability Power

Page 13: WINDOWS COMMUNICATION FOUNDATION

WCF: How does it work?

Page 14: WINDOWS COMMUNICATION FOUNDATION

WCF End points

Page 15: WINDOWS COMMUNICATION FOUNDATION

WCF Endpoints

Every service has Address

Where the service is Binding

How to talk to the service Contract

What the service can do

Page 16: WINDOWS COMMUNICATION FOUNDATION

Address

Combination of transport, server name, port & path

Transport is determined by the bindingExamples

http://localhost:8001net.tcp://localhost:8002/MyServicenet.pipe://localhost/MyPipenet.msmq://localhost/private/MyServicenet.msmq://localhost/MyService

Page 17: WINDOWS COMMUNICATION FOUNDATION

Bindings

Transport HTTP TCP MSMQ

Message formats and encoding Plain text Binary Message Transmission Optimization Mechanism

(MTOM) Communication security

No security Transport security Message security Authenticating and authorizing callers

Page 18: WINDOWS COMMUNICATION FOUNDATION

Out of the box Bindings

BasicHttpBinding WSHttpBinding WS2007HttpBinding WSDualHttpBinding WSFederationHttp

Binding WS2007FederationHttp

Binding

NetTcpBinding NetNamedPipeBinding NetMsmqBinding NetPeerTcpBinding WebHttpBinding MsmqIntegrationBinding

Page 19: WINDOWS COMMUNICATION FOUNDATION

Contracts

Service contracts Defines operations, communications

and behaviours. Data contracts

Defines data entities and parameter types.

Fault contracts Defines error types

Message contracts Defines message formats

Page 20: WINDOWS COMMUNICATION FOUNDATION

Service Contracts

[ServiceContract] – Defines a ‘set’ of operations [OperationContract] – Defines a single method

[ServiceContract]public interface IService{ [OperationContract] string GetData(int value);}

public class ConcreteService : IService{ public string GetData(int value) { ... }

public string OtherMethod() { ... }}

[ServiceContract]public interface IService{ [OperationContract] string GetData(int value);}

public class ConcreteService : IService{ public string GetData(int value) { ... }

public string OtherMethod() { ... }}

Page 21: WINDOWS COMMUNICATION FOUNDATION

Data Contracts

[DataContract] – Specifies type as a data contract [DataMember] – Members that are part of

contract

[DataContract]public class CustomType{ [DataMember] public bool MyFlag { get; set; }

[DataMember] public string MyString { get; set; }

}

[DataContract]public class CustomType{ [DataMember] public bool MyFlag { get; set; }

[DataMember] public string MyString { get; set; }

}

Page 22: WINDOWS COMMUNICATION FOUNDATION

Alternative – DataContract

DataContract: created specifically for WCF to serialize typesAttribute contains Name and Namespace

properties DataMember is needed to specify which

properties/fields will form part of the contractContains EmitDefaultValue, IsRequired,

Name, Order properties

Page 23: WINDOWS COMMUNICATION FOUNDATION

Metadata Exchange

Service can also expose endpoint for Metadata Exchange (MEX)

It provides a mechanism for clients to find out about:Address of other end pointsBindings that are usedContracts used – Service, Operation, Data,

etc

Page 24: WINDOWS COMMUNICATION FOUNDATION

Hosting

IISHTTP only

WAS (Windows Activation Service)Can use any transportVista and Windows Server 2008 only

Self hostingCan use any transportCan be hosted within Console, WinForms,

etc Applications

Page 25: WINDOWS COMMUNICATION FOUNDATION

Tooling Support

Page 26: WINDOWS COMMUNICATION FOUNDATION

Tooling Support

Visual StudioSeparate projects for WCF“Add Service reference” menuWCF Configuration EditorWCF Service HostWCF Test Tool

SvcUtil – To generate proxies SvcTraceViewer – To view logs

Page 27: WINDOWS COMMUNICATION FOUNDATION

Handling Faults

Page 28: WINDOWS COMMUNICATION FOUNDATION

SOAP Faults

Three main kinds of Exceptions can occur:Communication errorsUnexpected error on the serviceErrors thrown by the service on purpose

.NET Exceptions are technology specific All Exceptions come across the wire as SOAP

Faults

Page 29: WINDOWS COMMUNICATION FOUNDATION

Faults

In WCF, SOAP faults are passed in as FaultException objects

Rather than throwing Exceptions, services should throw FaultExceptions

Or better still FaultException<T> Throwing FaultExceptions will not fault the

proxy and the channel

Page 30: WINDOWS COMMUNICATION FOUNDATION

FaultContracts

Specifies what kind of Exceptions, an operation can throw

[ServiceContract] public interface IEmployeeService { [OperationContract] [FaultContract(typeof(ValidationException))] public void AddEmployee(Employee e); }

[ServiceContract] public interface IEmployeeService { [OperationContract] [FaultContract(typeof(ValidationException))] public void AddEmployee(Employee e); }

Page 31: WINDOWS COMMUNICATION FOUNDATION

Advantage Its made of a lot of different components, so you can

create new components for security, transport, authentication.

In WCF, there is no need to make much change in code for implementing the security model and changing the binding. Small changes in the configuration will make your requirements.

Its faster than ASMX Its Interoperability, for java, and more. WCF is interoperable with other services when

compared to .Net Remoting, where the client and service have to be .Net

WCF services provide better reliability and security in compared to ASMX web services.

Page 32: WINDOWS COMMUNICATION FOUNDATION

Disadvantage WCF is Microsoft's implementation of SOA and

hence its APIs are solely controlled by MS which makes interoperability a bit difficult.

To deploy WCF apps, need more underlying hardware resources on the platform on which the WCF applications will be running, since there is an additional layer of abstraction to deal with.

Page 33: WINDOWS COMMUNICATION FOUNDATION

Summary

WCF provides a runtime for creating Service Oriented Apps Provides a productive programming model. Takes care of:

Messaging and Exchange formats All Plumbing: Transaction, Reliability, Security, etc

Supports Declarative (via attributes), Imperative (via code) and Configuration based (via config files) programming model

ABCs of Endpoints Address: Where to go? Binding: How to get there? Contract: What to do?

Hosting IIS, WAS, Self-hosting

Page 34: WINDOWS COMMUNICATION FOUNDATION

Thank You

http://www.otssolutions.com/

Page 35: WINDOWS COMMUNICATION FOUNDATION

http://www.otssolutions.com/

India Gurgaon ( Haryana ) 795, Udyog Vihar, Phase-V Gurgaon(Haryana) India Ph: +91 124 4101350 +91 124 4748100Write to us at: [email protected]

United kingdom88 Wood Street 10th Floor London EC2V 7RSPh: +44 208 099 1660

Write to us at: [email protected]

USA 4433 Merlin Way , Soquel CA 95073United StatesPh: +1 408 540 0001

Write to us at: [email protected]