Hi, Last few weeks I spend with doing many experiments with WCF and REST. I know there is a ASP.NET Web API, but it is not stable yet. So, how we can create well designed fast and scalable system with REST and forgot completely 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 Request/Response way and there are four particular operations of it. 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 of most popular HTTP request are GET and POST and that can be created and configured with WebHttpBinding binding. I read about PUT and DELETE operations that there are implemented in ASP.NET Web API, but as I wrote at the beginning it is under develop and in the beta version and I cannot advice use 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 and all of that can be created in simple way with WCF 4.0. Most important for me is that WCF REST is much faster than classical WCF with SOAP. I have not measure performance yet because I worked of 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 beginning, this is only for 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 reference for that assembly and consume any REST application in a very easy way. If anyone is not familiar with NuGet packages I can recommend for beginning NuGet Project Web Page. Most of works with the RestSharp is about RestRequest/RestResponse object and Serialization/Deserialization of the XML/JSON/ATOM. I can recomend to you to find experience with your own experiments because it is 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 application and most of all I wonder about performance advantages. If you can share please feel free to left a comment.