INTRODUCTION• The latest Service Oriented Technology.• Interoperability is the fundamental characteristic.• Provides common platform for all .NET communication.• Successor to all message distribution technologies.• Used by developers to build Service Oriented Applications.
WCF vs. WEBSERVICE Features Web Service WCF It can be hosted in IIS, windows activationHosting It can be hosted in IIS service, Self-hosting, Windows service One-way, Request- Response are the One-Way, Request-Response, Duplex areOperation different operations supported in web different type of operations supported in service WCF XML 1.0, MTOM(Message TransmissionEncoding XML 1.0, MTOM, Binary, Custom Optimization Mechanism), DIME, Custom Can be accessed through HTTP, TCP,Transports Can be accessed through HTTP, TCP, Custom Named pipes, MSMQ,P2P, CustomProtocols Security Security, Reliable messaging, Transactions
END POINT• WCF exposes collection of end points.• End point is a portal for communicating with the world.• End point consists of three components (ABC – Address(where?)-Binding(how?)-Contract(what?)). Address – It is a unique URL identifies the location of the service. http://localhost:8080/ServiceSamples/MyService [Transport]:// [Machine or Domain]: [Port number]/ [Path] Binding – It specifies the protocol to access the service and also an encoding method used to format the message contents. E.g. basicHttpBinding, wsHttpBinding . . etc. Contract - Collection of operation that specifies what the endpoint will communicate with outside world.
END POINT USINGCONFIG FILE:• WCF Endpoint can be created using configuration file.
END POINT USINGCODE:• WCF Endpoint can be created using code.
BINDING• Binding will describe how client will communicate with service.• There are 9 standard bindings in WCF Name Transport Encoding Interoperable BasicHttpBinding HTTP/HTTPS Text, MTOM Yes NetTcpBinding TCP Binary No NetPeerTcpBinding P2P Binary No NetNamedPipeBinding IPC Binary No WSHttpBinding HTTP/HTTPS Text, MTOM Yes WSFederationHttpBinding HTTP/HTTPS Text, MTOM Yes WSDualHttpBinding HTTP Text, MTOM Yes NetMsmqBinding MSMQ Binary No MsmqIntegrationBinding MSMQ Binary Yes
CHOOSING A BINDING:• Have to know about client(WCF or NON-WCF) and service(WCF or NON-WCF) to choose binding.
BINDING CONFIGURATION USING CONFIG FILE:• We have to add bindingConfiguration tag tothe end point section.• We have to name a customized section in thebinding section of the config file.
CONTRACTS• Defines the Structure and Behavior of WCF Service.• The 3 core contracts are: 1. Service Contract - Describe the operation that service can provide. 2. Data Contract - Describes the custom data type which is exposed to the client. 3. Message Contract – Describes the message format for communication during runtime.
SERVICE CONTRACT• Services are group of operations, both classes and interfaces are used for grouping operations.• Operations are defined by creating a method and marking it with OperationContractAttribute attribute.• Service contract is defined by marking a class or interface that group operations(methods) withServiceContractAttribute attribute.DATA CONTRACT• It defines the data types that are passed to and from the WCF service.• It defines how data is serialized and deserialized.• By using Data Contracts we can make client to aware of custom created data types.
MESSAGE CONTRACT • Message is the packet data which contains information. • Message Contract is used to customize the message as per the requirement. • WCF uses SOAP(Simple Object Access Protocol) Message format for communication. • Message contract can be applied to type using MessageContract attribute. • Custom Header and Body can be included to message using MessageHeader and MessageBodyMember‘ attribute.FAULT CONTRACT • WCF provides the option to handle and convey the error message to client from service using SOAP Fault contract. • Fault Contract provides documented view for error accorded in the service to client. • service defines its fault contracts using the FaultContractAttribute.
HOSTING A WCFSERVICE• WCF service cannot exist on its own, it has to be hosted using a host process.• There are mainly four different ways of hosting the WCF service. 1. IIS Hosting 2. Self Hosting 3. Windows Activation Service 4. Windows Service
IIS HOSTING SELF HOSTING WAS WINDOWS SERVICE IIS automatically launches WCF provides the user to Windows Activation WCF Service starts whenthe host process when it host the service in any service is a system the system starts. Allgets the first client application. service available with versions of windowsrequest. Windows vista and support WCF hosting. windows server 2008, It is also available with IIS 7.0It uses the IIS features Developer is responsible Hosting WCF in Process life time of thesuch as process recycling, for providing and Activation service takes service can be controlledidle shutdown, process managing the life cycle of many advantages such by Service Controlhealth monitoring and the host process. as process recycling, Manager for windowsmessage based activation. isolation, idle time service management and common configuration system.It will only support HTTP It will support almost all It supports Http, TCP It will support almost allprotocol. types of protocols. and named pipes. types of protocols.