ChatGPT解决这个技术问题 Extra ChatGPT

What is the relationship between WCF, Rest and SOAP?

What is the relationship between WCF and REST&SOAP? Is WCF based on one of those technologies (REST or SOAP) or it is a separate technology?


T
Trevor

WCF is a messaging framework for building distributed systems. Distributed systems is mostly just another word for web services.

What this means is that you can write methods in C# (or any of the .NET languages) and then apply a bunch of configurations to the code that make your code accessible to others and turn your code into a web service.

Those "bunch of configurations" are WCF. WCF allows you to expose your methods to other computers or applications using REST if you set up the WCF configurations around your C# code to expose it as a RESTful service. Or, you can easily take the same C# methods and make them available via the SOAP protocol.

If you have a method called "GetData()", you can set up the WCF configuration to make that method available in a service that is hosted in IIS. When someone calls that service, they can send an HTTP GET request to http://www.yourdomain.com/SomeService/GetData, and the GetData method will receive the message and send back a response. When you make a GET request over HTTP, you're using the REST. REST is pretty much tied to HTTP as the transport protocol. REST also has no standard message format. Whatever you want to send in your HTTP message, and however you want to send it is OK. You can send XML, or JSON, or just plain text. You can use POST, or GET or PUT or any of the HTTP verbs as well.

With SOAP, your messages can be sent to the service using any transport protocol -- you aren't tied to HTTP. SOAP messages are designed to be transport neutral. They are encoded in XML and the XML always has a head and a body node inside of an envelope node. There are lots of web standards around SOAP -- standards for putting security, sessions and other features into the header of the message, for example. Also, with SOAP, you get a WSDL, which I won't go into explaining here, but it makes it a LOT easier for clients to program against. Most programming languages have a method of taking a WSDL and converting it into strongly-typed methods and objects so that your service is easy to call.

REST is very popular on the internet and is as scalable as the internet (i.e. VERY scalable). SOAP is very popular in business-to-business applications.


I think your answer was the best
Data communications existed long before the internet became popular yet young developers describe data communications relative to the internet (such as "Distributed systems is mostly just another word for web services"). Distributed systems existed before the internet became popular and can exist without the internet. I assume that WCF does not require a "web" and if so then this description is misleading.
A little late to the party, but just want to clarify that soap doesn't always have a head, as it's optional for the soap protocol.
This must be selected as the answer of the question.
I Agree this is the better answer. I wish there was a way that I could start a vote or something to have this changed to the accepted answer.
M
Mike C.

WCF isn't automatically REST or SOAP, but you can make it that way. What you need here is a tutorial:

WCF

http://www.codeproject.com/Articles/406096/A-beginners-tutorial-for-understanding-Windows

REST

http://rest.elkstein.org/

Here's some other interesting stuff:

WCF - REST / SOAP

https://msdn.microsoft.com/en-us/library/hh323708(v=vs.100).aspx

WCF and REST

https://msdn.microsoft.com/en-us/library/ee391967.aspx

Or you can do a google/bing/metacrawler/altavista search on your own.....


So, is it true that WCF is a separate technology from a web-service technology, and web-service technology includes REST and SOAP as variations?
In my experience, WCF is synonymous with being a web-service. At work, we might refer to one as a WCF Web Service. The thing about WCF is it supports both REST and SOAP. IT just depends on how you code the service. WCF is just about ABC (Address, Binding, Contract), explained much better in the link I provded.
Just to check that WCF tutorial isn't using SOAP or REST?
@JoshLeeDucks Honestly, I'm not sure. If I had to guess I'd say it's probably using SOAP, but I'd have to run the actual code and see to be sure. The point to make here is just that WCF isn't tied to SOAP or REST, it can use either one. I'll add an interesting article I found to the links.
l
l46kok

From MSDN

The WCF programming model provides various capabilities, such as SOAP services, web HTTP services, data services, rich internet application (RIA) services, and workflow services. SOAP services support interoperability between systems that are built with Java, other platforms, and those that use messaging standards that are supported by Microsoft®. SOAP services also support transports such as HTTP, TCP, named pipes, and MSMQ. Web HTTP services and data services both support REST. Web HTTP services enable you to control the service location, request and response, formats, and protocols. Data services enable you to expose data models, and data-driven logic as services. WCF also includes two programming models: The service model and the channel model. The service model provides a framework for defining data contracts, service contracts and service behaviors. The channel model supports specifying formats, transports, and protocols. Both SOAP and REST services can provide functionality to web applications, and both can be used to exchange information in the web's distributed environment. Each one has its own advantages, and limitations.


That's an important distinction, there, not addressed by other posts (though the other posts are equally important): "SOAP services support interoperability..."
(Had to post another comment as SO wouldn't let me edit after 5 min.): I wonder why that is the case. Can JAVA services not communicate using RESTful-based approaches?
I
Irf

Although, this question has got several good answers, just putting in my 2-cents, in an attempt for newbies to WCF vs SOAP vs REST-full services, to make it a bit easier for them to understand.

We get confusions, whether WCF supports both REST and SOAP ? And, normally, we just see generic definitions about SOAP and REST. So , we need something from Microsoft to make us feel the truth : ) So here's a screenshot from Microsoft MSDN :

https://i.stack.imgur.com/Spm7x.png

So, yes, WCF supports both .

In context with OP:

SOAP services: in WCF programming model support interoperability between systems that are built with Java, other platforms, and those that use messaging standards that are supported by Microsoft®. These also support transports such as HTTP, TCP, named pipes, and MSMQ.

Web HTTP services : in WCF programming model supports REST. [Source: MSDN]