WCF Reliable Messaging makes web services more reliable. It addresses the following problems:
A call to a web service does not make because the networks are not perfectly reliable as they suffer congestion and may drop signals.
OR the service response does not make it back to the client.
If I make multiple calls to the web service and the calls do not reach to the service in the same order that i made them there is a problem.
WCF reliable messaging makes sending messages reliable and ordered over unreliable network.
Client: Hello Service! Service: What may I help you! Client: Message#1 Service: Message#1 received! Client: Message#2
[No response from Service] Client: Message#2 Service: Message#2 received! Client: Good bye! Service: Bye!
Explanation: The Client did not get a response when it send message#2. The reason may be the service did not get the message#2 or the service got the message but the response did not make it back. Whatever the reason, The client tries again and send the Message#2. if the service received the Message#2 twice it will ignore the second message.
A Contract is basically an agreement between the two parties i.e. Service and Client. There are two types of Contracts in WCF.
Service Contract:- Service contract describes the operation that service provide. A Service can have more than one service contract but it should have at least one Service contract. A Service Contract can be define using [ServiceContract].
Public interface IBookOrder
//do some stuff
Operation Contract:- The [OperationContract]attribute declares that a method is an operation in a service contract. Only methods attributed with the [OperationContract]are exposed as service operations.
Fault Contract:- It is used to communicate error information from a service to a client.
Data Contract:- A data contract describes the data that is to be exchanged between client and service. The service and the client do not need to agree on the types, but they do need to agree on the data contract.
Public class BuyStock
Message Contract:- Message contracts provide the ultimate control over the formatting of the SOAP messages. A message contract provides the level of interoperability you would need when you need to communicate with clients or other systems.
Public class BuyStock
Public string Title;
Public decimal Cost;
Bindings in WCF actually defines that how to communicate with the service. Binding specifies that what communication protocol as well as encoding method will be used. Optionally, binding can specify other important factors like transactions, reliable sessions and security.
Different types of bindings available
It is suitable for communicating with ASP.NET Web services (ASMX)-based services.
This binding uses HTTP as the transport and text/XML as the default message encoding.
Security is disabled by default.
It is fairly weak on interoperability.
Defines a secure, reliable, interoperable binding suitable for non-duplex service contracts.
It uses HTTP and HTTPS transport for communication.
Reliable sessions are disabled by default.
This binding is same as that of WSHttpBinding, except it supports duplex service.
WSDualHttpBinding reliable sessions are enabled by default.
This binding is provided by the WSFederationHttpBinding class.
It is a specialized form of WS binding and provides support to federated security.
This binding provides secure and reliable binding environment for .Net to .Net cross machine communication.
It uses TCP protocol for communication be-tween two machines with in intranet.
It encodes the message in binary format. This is faster and more reliable binding as compared to the Http protocol bindings.
It uses NamedPipe protocol and provides full support for SOAP security, transaction and reliability.
By default it creates communication stack with WS-ReliableMessaging for reliability, transport security for transfer security, named pipes for message delivery and binary encoding.
This binding provides secure and reliable queued communication for cross-machine environment.
Queuing is provided by using MSMQ as transport.
This binding provides secure binding for peer-to-peer environment and network applications.
It uses TCP protocol for communication.
It provides full support for SOAP security, transaction and reliability.
Transactions A transaction is a unit of work. A transaction ensures that everything within that transaction either succeeds as a whole or fails as whole. For example, if a transaction contains three items of work to perform, and during the execution of that transaction one of those items fails, then all three fail. The transaction succeeds only if all three statements of work succeed, unless a Checkpoint is issued. You commonly see this in database operations.
WCF incorporates this same transactional processing into its communication. Hosting WCF hosting allows services to be hosted in a handful of different environments, such as Windows NT Services, Windows Forms, and console applications, and well as IIS (Internet Information Services) and Windows Activation Services (WAS).
Hosting a service in IIS has added benefits in that the service can take full advantage of many of the native IIS features. For example, IIS can control the starting and stopping of the service automatically. Security What good would Windows Communication Foundation be without security? Trust me on this, WCF certainly isn’t lacking in this department. Everything from messages to clients and servers get authenticated, and WCF has a feature that ensures messages aren’t messed with during transit. WCF includes message integrity and message confidentiality.
WCF also enables you to integrate your application into an existing security infrastructure, including those that extend beyond the standard Windows-only environments by using secure SOAP messages. Queuing If you are at all familiar with MSMQ (Microsoft Message Queuing), this topic will sound familiar. WCF provides queuing, allowing messages to be safely stored, providing a consistent state of communication. Queuing collects and stores sent messages from a sending application and forwards them on to the receiving application. This provides a safe and reliable message delivery mechanism.