3.14.2014

Difference between WCF Fault Exception and normal .NET Exception


S.No
WCF Fault Exception
.NET Exception
1 What is WCF Fault Exception ?
If we use a raise a fault exception as shown in the below code, our WCF clients will see the complete clear error rather than a generic error as shown in .NET Exception example.
 
 
Our WCF client will now see a better error description as shown in the WCF Fault example.

Example is provided at the bottom of the table
What is .NET Exception ?
If we throw a normal .NET exception from a WCF service as shown in the below code snippet.
 
Our WCF client will get a very generic error with a message as shown in the .NET Exception example. Now this kind of message can be very confusing as it does not pinpoint what exactly the error is

Example is provided at the bottom of the table

Example for WCF Fault Exception:


Example for generic .NET Exception:







3.11.2014

Difference between WCF and ASP.NET Web API


S.No
WCF
ASP.NET Web API
1 What is WCF ?
WCF is Microsoft’s unified programming model for building service-oriented applications. It enables developers to build secure, reliable, transacted solutions that integrate across platforms and interoperate with existing investments.
What is ASP.NET Web API ?
ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework.
2 Protocol Support:
HTTP, TCP, UDP, and custom transports.

i.e., Enables building services that support multiple transport protocols (HTTP, TCP, UDP, and custom transports) and allows switching between them.
Protocol Support:
HTTP only.

i.e, Provides first-class programming model for HTTP.More suitable for access from various browsers, mobile devices etc enabling wide reach.
3 Message Exchange Patterns:
Request-Reply, One-Way & Duplex
Message Exchange Patterns:
By default Request-Reply only.But additional message exchange patterns can be supported through SignalR and WebSockets integration.
4 Hosting:
Self Hosting, IIS Hosting & Windows Activation Service.
Hosting:
Self Hosting & IIS Hosting
5 Open Source or Licensed ?
It is not an open source .Ships with the .NET framework. It can be consumed by any client that understands xml.
Open Source or Licensed ?
Ships with .NET framework but is open-source and is also available out-of-band as independent download.
6 How to describe WCF services ?
WCF SOAP services can be described in WSDL allowing automated tools to generate client proxies even for services with complex schemas.
How to describe ASP.NET Web API ?
There is a variety of ways to describe a Web API ranging from auto-generated HTML help page describing snippets to structured metadata for OData integrated APIs.
7 Whether it supports MVC features ?
WCF does not support the MVC features such as routing, controllers, action results, filter etc.,
Whether it supports MVC features ?
ASP.NET Web API supports the MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection, unit testing that makes it more simple and robust.
8 Support for higher level protocols:
Supports building services with WS-* standards like Reliable Messaging, Transactions, Message Security.

Support for higher level protocols:
There is no support for higher level protocols such as Reliable Messaging or Transactions. ASP.NET Web API uses only basic protocol and formats such as HTTP, WebSockets, SSL, JQuery, JSON, and XML.

9 Encoding Support:
Text, MTOM, and Binary
Encoding Support:
Supports UTF-8 encoding format by default .Also, we can add any format as a MediaTypeFormatter.
i.e., Responses are formatted by Web API’s MediaTypeFormatter into JSON, XML.
10 When to go for WCF ?
Choose WCF when we want to create a service that should support special scenarios such as one way messaging, message queues, duplex communication etc.

Choose WCF when we want to create a service that can use fast transport channels when available, such as TCP, Named Pipes, or may be even UDP (in WCF 4.5), and we also want to support HTTP when all other transport channels are unavailable.

When to go for ASP.NET Web API ?
Choose Web API when we want to create a resource-oriented services over HTTP that can use the full features of HTTP (like URIs, request/response headers, caching, versioning, various content formats).

Choose Web API when we want to expose our service to a broad range of clients including browsers, mobiles, iphone and tablets.

Programming WCF ServicesProfessional WCF Pogramming