Is there an advantage to using WCF to facilitate AJAX calls?

I am currently reading a sentence where this person suggests using WCF services to facilitate AJAX calls in a web application. It is said that WCF can serialize data more efficiently. I personally never thought about that. I always liked calling MVC controllers using jQuery AJAX, and this was never a problem.

Now there is a suggestion to use WCF for AJAX, and I'm a little skeptical. I would like to save and open my mind. For me, this seems to add another layer that unnecessarily complicates things. Is it worth it?

+4
source share
6 answers

As a side note, ASP.Net MVC currently uses the JavaScriptSerializer (although it was flagged as an obsolete .Net 3.5 post) to serialize JSON data, where WCF uses the DataContractJsonSerializer.

Thus, in terms of the efficiency of JSON serialization, MVC will be more efficient since the JavaScriptSerializer is much easier (everything will be quick and dirty) than the DataContractJsonSerializer.

NTN

+3
source

+1 I am also a little skeptical. I don’t think the average player sends large amounts of data through Ajax / jQuery, and if they, I think they need to reorganize a bit.

So, if that is the case, then what potential gain could you get from using WCF over the normal mvc function when you serialize (maybe) 2 or 3 k data. I think even 2k is sent via Ajax.

Using WCF in the code behind would be a good idea, but for ajax serialization, dunno about that.

+2
source

I would not worry about another layer, especially not WCF, to facilitate AJAX calls. If you already use MVC, JsonResult will do its best (and, according to Jason Fox above, more efficient).

If you do not need a web service for operations that require web services (i.e., interaction over the Internet), why bother? The MVC has always done this job without annoying overhead.

+2
source

This would be useful if you were showing the same services on additional endpoints with different bindings, but if you just use AJAX, I would go with an MVC controller that returns JsonResult. You can still serialize the parameters using action filters.

If there are no special features that only WCF provides, then MVC will be simpler. You do not have to worry about contracts, bindings, configuration, WCF JSON formatting, etc.

+1
source

It sounds interesting in concept, but at the end of the day, you still won't get Json back? Maybe something is missing me, but how can Json be returned by WCF more optimized than the Json returned by WCF? Does it look like my XML is more optimized than yours? This is not how WCF can return binary data to the browser β€” you won’t be able to use that data ... (Or can it be?) I suppose the WCF serializer can be faster than MVC, but the bottleneck is always getting these data on wires.

Of course, this is all pure speculation - we need you to read the offer in order to give an accurate opinion. And it depends a lot on how much data you send through Ajax.

+1
source

WCF has its own serializer, which (IIRC) is binary, and which processes graphs of objects that cannot serialize XML. It should also not contain the detailed overhead of XML. As Grigie noted, this is probably an overwhelming concern about optimization.

Is WCF more efficient than JSON? I don’t know, I’m not sure that it is so important.

In coding there will be a thin service level and ASP.NET hosting that will add additional service data. Regardless of whether this affects performance, this is a separate issue; it’s just overhead, which can be seen compared to the service data of the .asmx or MVC controller for processing services.

I do not think that you really get any of the other WCF features in this case. Using WCF for ASP.NET Hosted Web Services limits you to a specific binding protocol.

EDIT: Looking at a project where I used WCF for web services, this is HttpBinding web. As noted in the comments, this will be JSON. On the other hand, if you use the ASP.NET ScriptManager tag, it dynamically creates a proxy server that includes data analysis, so you never know how the data is serialized.

-one
source

All Articles