Objective:
In this article we will explain what are the REST Attributes of WCF service and there usage.
Here WCF Stands for Windows Communication Foundation
WebServiceHost: This is a class which is inherited from ServiceHost Class. ServiceHost class is used to implement Windows Communication Foundation (WCF) REST programming model. WebServiceHost class do some extra tasks like disabling wsdl, Mex End point and prevents meta data publishing. It also creates end points automatically for all contracts. It adds behavior to all end point.
WebHttpBinding: This class is inherited from Binding class. Binding class is used to configure end points for WCF web services which are exposed through HTTP request rather than SOAP. WebHttpBinding is used in web.config file to initialize binding type.
WebHttpBehavior: This attribute provides the correct networking stack for using REST. WebHttpBehavior is the object that causes the URI-plus-verb dispatcher to be used, so the WebHttpBinding and the WebHttpBehavior are almost always used together.
WebOperationContext: This class provides access to contextual properties of Web requests and responses.
Usage: WebOperationContext.Current.OutgoingResponse.ContentType = "application/json";
WebMessageFormat: It specifies the format of the message.
Usage:
a. [WebGet(ResponseFormat= WebMessageFormat.Json)]
b. [WebGet(ResponseFormat= WebMessageFormat.Xml)]
- WebGet: This attribute is sued to define a service operation
Usage :
[WebGet]
public IQueryable GetOrdersByCity(string city)
7 WebInvoke: This is an attribute which ensures that method is called by WCF REST programming model is logically invoke.
Usage :
[WebInvoke]
public IQueryable GetOrdersByCity(string city)
8 UriTemplate: UriTemplate is a class which have methods to match an incoming URI to a template, generate a URI from a template, retrieve a collection of variable names used in the template, determine whether two templates are equivalent, and return the template's string
Usage: UriTemplate t = new UriTemplate("{shoe=1}/{boat=null}");
0 Comment(s)