1

I have a current application where a client-side ClickOnce app hits up an ASMX web service for various information. It works fine, but is a bit slow. Part of the problem is that it returns large objects, when broken down to SOAP turns what was a large object into an unholy mess of XML tags that blow up the size of the payload by a huge factor.

Anyway, to fix this, I was thinking of rewriting this setup with something more lightweight using technologies I've heard a lot about, but never really used for more than a "Hello World" app.

So I was thinking of doing a REST api that returns JSON objects. Giving that JSON is a much more compact format, that should alleviate the size of the message problems. And, unless there is something I don't know, it's not more intensive to parse than SOAP XML.

Questions:

  1. Are my assumptions sound?
  2. What technologies should I use to implement REST and JSON? I've heard of WCF Web API, but it looks like it's not even complete. What are my options?
  3. Is there something nasty about WCF, REST and JSON that I should know before I embark upon this?
AngryHacker
  • 54,471
  • 90
  • 289
  • 523

2 Answers2

2

REST is an architectural style leveraging HTTP, so I'd recommend an HTTP listener for services.

JSON is JavaScript Object Notation, so you'll need a JSON parser on the server side. You can stream JSON right the client for the response; the MIME type is application/json.

I don't know about any nasty surprises in WCF, but I don't see any for HTTP.

Community
  • 1
  • 1
duffymo
  • 293,097
  • 41
  • 348
  • 541
1

You can use DataContractJsonSerializer for the serialization process.

I would not use WCF to create JSON restful webservices. imho you can a much nicer structure if you use ASP.NET MVC3 instead. Much easier to follow the code and it's easier to create RESTful routes.

To return JSON you just return your viewmodel like this (fetch it by using http://mydomain.com/user/view/10):

public ActionResult View(int id) 
{
    var user = _repository.Get(id);
    var viewModel = AutoMapper.Map<UserViewModel, User>(user);
    return Json(viewModel);
}
jgauffin
  • 95,399
  • 41
  • 227
  • 352