I am specifically looking for an example which use a) WCF & REST. After a long googling, though I got some but they are beyond my understanding.
Could some one please give me a very simple example say "Hallow World" or Summation of 2 numbers which will give me a clear insight about how to write a server, and also how to consume the same from the client end.
Also if any good link that explains this kind of example in simple terms kindly tell me that.
Thanks
You can create an WCF REST web service by configuring your endpoint to use a
webHttpBinding
as seen in this in-depth tutorial:http://www.west-wind.com/weblog/posts/310747.aspx
Here is another open source web services framework that simplifies creating XML and JSON REST web services without requiring any extra configuration.
Edit: Added link to good article articulating the spirit of REST:
http://tomayko.com/writings/rest-to-my-wife
Link to blog post comment explaining common misconceptions of REST:
http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven
In Microsoft Web Developer, you can use the Online Template "WCF REST Service." It will set up a project for you with the correct web.config and global.asax files.
If you really want to do ReST then use a web framework that will lead you down the right path. See OpenRasta.
It is not impossible to do WCF to do ReST, it is just very difficult to learn how to do Rest with a framework that will frequently get in your way and lead you in the wrong direction.
REST in WCF is not that hard once you figure it out.
First you must define your interface.
Here is an example.
You can see in the WebGet you define the final URL. So it depends on where you bind it, but say you bind the endpoint to www.example.com/rest
QueueInteraciton would be www.example.com/rest/interaction/queue?s=SomeSite
Where {stie} or {parameterName} is replaced with the name of the parameter.
The implemetion is just a simple class, I am going to assume you know how to implement an interface. If you need help just leave a comment.
Now binding the endpoint. In the end it is not that hard, you can do it all in the config.
Now the code to start the service and bind it. YOu can do it in anything, for example a console app.
This should be enough to get started.
msdn article An Introduction To RESTful Services With WCF with code example at msdn code gallery. Also check out this codeproject article
David Basarab's response is correct, but there's a much simpler way to do this without all the manual wire-up. Especially if you've used to classic ASMX web services and don't have a lot of WCF experience, the following method is dirt simple.
System.ServiceModel.Web
.[ServiceContract]
attribute on your class, fill in the Namespace string parameter with whatever you want.[WebGet()]
attributes to your web methods. Add one to DoWork() and verify everything functions for you.So, to call the DoWork() method, you'd hit this in your browser: http://localhost/MyAjaxEnabledService.svc/DoWork
Let's add a new HelloWorld() method now that shows some parameters and output.
VB:
C#:
Now you can visit:
http://localhost/MyAjaxEnabledService.svc/HelloWorld?name=MattMc3
There's a lot of crappy and confusing documentation out there about WCF, especially for those who crave the simplicity of the old .ASMX style. Hopefully this helps someone get started with WCF. There's a lot more you can do with it than the old ASMX-style, but it's hard to ramp up and not get discouraged with MS for their poor help with the transition from ASMX. You can read more about quick-and-dirty RESTful WCF services here.