Difference Between ASP.NET Web API and WCF

Introduction

This article describes the differences between the Web API and Windows Communication Foundation (WCF). And also describes how to choose between WCF and Web API.

What is the ASP. NET  Web API

The ASP. NET Web API is a framework that uses the HTTP services and makes it easy to provide the response to the client request. The response depends on the request of the clients. The Web API builds the HTTP services, and handles the request using the HTTP protocols. The request may be GET, POST, DELETE, PUT. We can also say that the ASP. NET Web API:

  • Is an HTTP service.
  • Is designed for reaching the broad range of clients.
  • Uses the HTTP application. Continue reading

Create Proxy Class For WCF Service Using svcutil.exe & CommandPrompt

There are couple of different options available to create proxy class for a WCF service in .Net. First one is to use “Add Service Reference” option available in visual studio and the second option is to use svcutil.exe utility. Although “Add Service Reference” option also invoke this utility implicitly but you can also go to visual studio command prompt and use this utility to generate proxy code that you can use in your client application. Continue reading

By Sriramjithendra Posted in WCF

WCF or ASP.NET Web APIs?

 

Read full post HERE.

What is the purpose of the WebAPIs?

When WCF was conceived back in its Indigo and .NET 3 days, the main goal was to support SOAP + WS-* over a wide variety of transports. However, over time it became clear that although SOAP is wide spread and supported on many platforms, it is not the only way to go when creating services. There is also a need to also support non-SOAP services, especially over HTTP, where you can harness the power of the HTTP protocol to create HTTP services: services that are activated by simple GET requests, or by passing plain XML over POST, and respond with non-SOAP content such as plain XML, a JSON string, or any other content that can be used by the consumer. Support for non-SOAP services was very much needed in WCF back then, mostly because some clients, such as web browsers, were not that suitable to handle SOAP messages (plenty of XML parsing and DOM manipulation). Continue reading

WCF vs ASP.NET Web API – 1

WCF was originally created to enable SOAP-based services. For simpler RESTful  (think clients like jQuery) ASP.NET Web API should be good choice.

ASP.net Web API is all about HTTP and REST based GET,POST,PUT,DELETE with well know ASP.net MVC style of programming and JSON returnable; web API is for all the light weight process and pure HTTP based components. For one to go ahead with WCF even for simple or simplest single web service it will bring all the extra baggage. For light weight simple service for ajax or dynamic calls always WebApi just solves the need. This neatly complements or helps in parallel to the ASP.net MVC.

Check out the podcast : Hanselminutes Podcast 264 – This is not your father’s WCF – All about the WebAPI with Glenn Block by Scott Hanselman for more information. Continue reading

Method Overloading in WCF: WCF Interview Series #1

 

==>    Original LINK

How to do Method Overloading in WCF?

Method or Operation overloading is one of the most important feature of OOPS. In programming languages like C, C++ and C#, this feature is heavily used by developers. While writing Service definition you may come across when you need to overload operations.

Let us go ahead and write Service with overloaded function as following. In below ServiceContract I am creating two methods and overloading them with different parameters.

1
2
3
4
5
6
7
8
9
[ServiceContract]
 public interface IService1
 {
[OperationContract]
 int Add(int number1, int number2);
 [OperationContract]
 string Add(string text1, string text2);
 }

I implemented service as below,

1
2
3
4
5
6
7
8
9
10
11
12
13
public class Service1 : IService1
 {
public int Add(int number1, int number2)
 {
 return number1 + number2;
 }
public string Add(string text1, string text2)
 {
 return text1 + text2;
 }
 }

I left default EndPoint configuration and hosting. When I ran service I encountered following exception,

image

So clearly by default WCF does not allow you to overload methods in service. However there is one attribute in OperationContract which can allow you to overload method at service end. You need to set Name parameter of OperationContract to manually enable overloading at service side.

image

To achieve overloading at Service side I set Name parameter of both function as follows,

1
2
3
4
5
6
7
8
9
[ServiceContract]
 public interface IService1
 {
[OperationContract(Name="AddNumber")]
 int Add(int number1, int number2);
 [OperationContract(Name="AddString")]
 string Add(string text1, string text2);
 }

Even though we have achieved overloading at Service side at client side method exposed with different name as set in Name parameter. At client side you will get method exposed as following,

image

So on asking you can say that by setting Name parameter value of OperationContract we can achieve Operation or Method overloading in WCF. I hope you find this post useful. Thanks for reading.

How to Implement Message Contract in WCF.

Confuse when you go for Message Contract and when for Data Contract

Data contracts are used to define the data structure and generate the XML for the data you want to pass.
If you want to go for more control on your SOAP Message then you should go for a Message Contract.
Do not mix message contract and data contract.

http://www.c-sharpcorner.com/UploadFile/788083/how-to-implement-message-contract-in-wcf/

By Sriramjithendra Posted in WCF