RESTful WCF Services
Hi friends,
I have already discussed REST ful services in earlier Post .But today in this article I am discussing details of RESTful Services
I am covering following topics in this article
1. Introduction
2. Differnce between normal WCF service and RESTful WCF Service
3. Where to Use RESTful WCF Service
4. Creation of RESTful WCF Service
5. Testing RESTful WCF Service
6. Summary
1. Introduction
WCF means Window communication Foundation which is introduced in .net framework 3.0. Before WCF there is webservice is famous for communication.
RESTful Service means Representational State Transfer (REST),
2. Differnce between normal WCF service and RESTful WCF Service
There is no more difference between WCF service and REST service only main difference is that How Client accesses our Service.
Normal WCF service runs on the SOAP format but when we create REST service then client can access your service in different architecture style like JSON
REST uses4 HTTP methods to insert/delete/update/retrieve information which is below:
- GET - Retrive a specific representation of a resource
- PUT - Creates or updates a resource with the supplied representation
- DELETE - Deletes the specified resource
- POST - Submits data to be processed by the identified resource
3. Where to Use RESTful WCF Service
There are some scenario’s where we can use RESTful service like
- Less Overhead because there is no use of SOAP object
- Testing is very easy
- Standardization is very nice
4. Creation of RESTful WCF Service
Step1.
Create a new WCF project in VS 2008/20010
Step 2:
Delete a Service Model node from Web.config
Step 3.
Step 3.
Build the Solution then Right click on the svc file and Click on View Markup button
And add following code to the markup
Factory="System.ServiceModel.Activation.WebServiceHostFactory"
Step 4
Add following references to the WCF Service Application project, if you are using VS2010
Microsoft.Http.dll
Microsoft.Http.Extension.dll
System.ServiceModel.Web.dll
Step 5
[ServiceContract]
public interface IService1
{
[OperationContract(Name = " AddTwoNumber ")]
[WebInvoke(UriTemplate = "/", Method = "POST")]
int AddTwoNumber(int i, int j);
[OperationContract(Name = " SubTwoNumber")]
[WebGet(UriTemplate = "/")]
int SubTwoNumber(int i, int j);
}
Add your code in your service like here I have created 2 methods like AddTwonumber which takes two parameter I and j
In the above code we use
WebInvoke :- means invoke web method
Webinvoke takes Two parameters like
1. Method Type there are 4 types of method
a.Post C.Invoke
b.Get d.Delete
2. UriTemplate = "/ADD” tells what would be URI for this particular method
Like this we can create RESTful service .
In the above article we studied all the basic details of restful service .
In the next article I will tell you details for Restful service
Thanks friends.
Very nice Article..!
ReplyDeleteGood article
ReplyDelete-Sachin
Thanks all my friends
ReplyDelete