Hi, Last few weeks I spend with doing many experiments with WCF and REST. I know there is an ASP.NET Web API, but it is not stable yet. So, how can we create a well-designed, fast, and scalable system with REST and forget about SOAP? Answer is very simple, it can be done with WCF 4.0 with the WebHttpBinding binding and the WebHttpBehaviour behaviour.
But, starting from the beginning. I found very nice and practical article An Introduction To RESTful Services With WCF by Jon Flanders. As most of you probably know REST protocol example is HTTP. The HTTP protocol works in a Request/Response way and has four particular operations. There are GET, POST, PUT and DELETE. The HTTP protocol works without any session state. That means that one operation is atomic and cannot be split. Two popular HTTP requests are GET and POST, which can be created and configured with WebHttpBinding binding. I read about PUT and DELETE operations implemented in ASP.NET Web API, but as I wrote at the beginning, it is under development and in the beta version. I cannot advise using it for production.
In mentioned article wrote by Jon Flanders you can find very simple solutions for prepare and setup WCF REST XML service. There are also JSON and ATOM rest services, which can be created simply with WCF 4.0. Most important for me is that WCF REST is much faster than classical WCF with SOAP. I have not measured performance yet because I worked on a performance test for that technology, and my experiments are not finished yet. Simple code example from MSDN magazine looks like this.
ServiceHost sh = new ServiceHost(typeof(MSDNMagazineServiceType)); string baseUri = "http://localhost/MagazineService"; ServiceEndpoint se = sh.AddServiceEndpoint(typeof(IMSDNMagazineService), new WebHttpBinding(), baseUri); se.Behaviors.Add(new WebHttpBehavior()); sh.Open();
And when you create WCF service like that you can use GET and/or POST operations to interact with the service. But this is only the beginning; this is only for the server side. And you may wonder about how to consume this RESTfull service by the .NET/C# program. And for that the RestSharp from NuGet packages for Visual Studio is a very good solution. We can download references for that assembly and consume any REST application very easily. If anyone is not familiar with NuGet packages I can recommend for beginning NuGet Project Web Page. Most of the work with RestSharp is about RestRequest/RestResponse object and Serialization/Deserialization of the XML/JSON/ATOM. I can recommend to you to find the experience with your own experiments because it is a very interesting and funny process.
I started about four weeks ago experiments with WCF REST and I can say that technology has a great future in my opinion. I wonder about your experience with RESTfull applications, and most of all, I wonder about performance advantages. If you can share, please feel free to leave a comment.