Before we define WCF REST, lets define REST. REST is an architectural style built on certain principles using the current “Web” fundamentals.
It has five important principle: -
- Everything is a resource.
- Every resource is identified by a unique identifier
- Use simple and uniform interfaces.
- Communication are done by representation.
- Be Stateless.
To implement WCF REST we need to use first enable webhttp bindings in behavior as shown in the below code snippet: -
<endpointBehaviors>
<behavior name="NewBehavior0">
<webHttp />
</behavior>
</endpointBehaviors>
We can then use WebGet or WebInvoke to ensure that our URL is invoked by using HTTP POST or GET: -
[OperationContract]
[WebGet(UriTemplate = "/Students/{id}")]
string getStudents(string id);
Also see our following video on explanation of REST: -
Asked In: Many Interviews |
Alert Moderator