What is Difference between WCF service and WCF RESTful services ?

Posted by Nandkishorre under WCF on 9/26/2013 | Points: 10 | Views : 76836 | Status : [Member] | Replies : 5
Hi to All,
I know the WCF Services and how to use services. What is the main difference between wcf Service and WCF RESTful Services and Where we use the RESTful services ?
What is the use of the WCF RESTFUL Services ?

if could any one know about this reply me... ?

Regards
Nanda Kishore.CH




Responses

Posted by: Bandi on: 9/26/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
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),

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

Where to Use RESTful WCF Service
There are some scenario’s where we can use RESTful service like
1) Less Overhead because there is no use of SOAP object
2) Testing is very easy
3) Standardization is very nice

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.

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.

More differences:
Web Service is an abstract term encompassing a large variety of data providers for distributed systems. Perhaps you are referring to ASMX web services, which can still be found in the wild but aren't really widely used in new development these days.

WCF Service is Microsoft's implementation of SOAP. There are others implementations or you could roll your own (not recommended).

SOAP is a kind of stateful, session-based, message-based web service. It's good if your service is designed as a set of complex actions.

REST is a stateless, sessionless, resource-based web service. It's good if your service is designed to access data and perform simple CRUD operations on it. SOAP and REST are mutually exclusive. A service cannot be both. There are ways to manipulate vanilla WCF to make is RESTful but these techniques are becoming deprecated. If you want to implement a RESTful web service there are two main choices in the Microsoft world: WCF Data Services and ASP.NET Web API.





Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Nandkishorre, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 9/26/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Dear Nandkishor,

Below is id the different between wcf and WCF Rest.

WCF
1. It is also based on SOAP and return data in XML form.
2. It is the evolution of the web service(ASMX) and support various protocols like 3. TCP, HTTP, HTTPS, Named Pipes, MSMQ.
4. The main issue with WCF is, its tedious and extensive configuration.
5. It is not open source but can be consumed by any client that understands xml.
6. It can be hosted with in the applicaion or on IIS or using window service.

WCF Rest
1. To use WCF as WCF Rest service you have to enable webHttpBindings.
2. It support HTTP GET and POST verbs by [WebGet] and [WebInvoke] attributes respectively.
3. To enable other HTTP verbs you have to do some configuration in IIS to accept request of that particular verb on .svc files
4. Passing data through parameters using a WebGet needs configuration. The UriTemplate must be specified
5. It support XML, JSON and ATOM data format.

Where to use:-

1. In my opinion, SOAP services with SOA architecture are well suited in enterprise applications. SOA architecture includes several key factors like service versioning, scalability, deployment and maintaining of services.
2. REST services are best suited in Internet-facing applications, which can take advantage of HTTP caching and other features.

Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Nandkishorre, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 9/26/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Dear Nandkishor,

Web Service is an abstract term encompassing a large variety of data providers for distributed systems. Perhaps you are referring to ASMX web services, which can still be found in the wild but aren't really widely used in new development these days.

WCF Service is Microsoft's implementation of SOAP. There are others implementations or you could roll your own (not recommended).

SOAP is a kind of stateful, session-based, message-based web service. It's good if your service is designed as a set of complex actions.

REST is a stateless, sessionless, resource-based web service. It's good if your service is designed to access data and perform simple CRUD operations on it. SOAP and REST are mutually exclusive. A service cannot be both. There are ways to manipulate vanilla WCF to make is RESTful but these techniques are becoming deprecated. If you want to implement a RESTful web service there are two main choices in the Microsoft world: WCF Data Services and ASP.NET Web API.

Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Nandkishorre, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nandkishorre on: 9/27/2013 [Member] Starter | Points: 25

Up
0
Down
Mr Chandu,
You said SOAP is stateful. SOAP supports http protocol. but http supports stateless. Then SOAP is Stateless. how SOAP supports stateful... will you kindly explain me ?

Regards
Nanda Kisohre.CH

Nandkishorre, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/27/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
By default, SOAP webservices are stateless
"A stateful SOAP webservice is a web service that maitains state information between message calls"
Session ID is stored in the SOAP header with WS-Addressing (WS-A)
Stateful SOAP works as follows:

   Request by SOAP client
C --> S
SOAP session will be created by SOAP server
Response from SOAP server to SOAP client with Session ID
C <-- S
More interaction between client and server
We can use stateful SOAP in multi-user environment with multiple requests/responses

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Nandkishorre, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response