0

I am leaning towards WCF as my main source of service (I may need multiple end-points in the future), and here are the things that I have been stuck at...

  • WCF to CLIENT: How can I make my MVC accept JSON data from WCF service and parse it into C# primitive/complex types?
  • CLIENT to WCF: How can I send JSON formatted data from MVC to WCF and have it parsed to C# primitive/complex types?

  • side question: How can I make WCF use REST as its protocol and transmit JSON format data? Do I use REST starter kit or is it built in on WCF?

Basically, this is my architecture:

WCF === (format: JSON) ===> ASP.net MVC 3 (...and back)

WCF === (format: JSON) ===> misc client (...and back)

code samples would help greatly!

Thanks in advance for the help! :)

2 Answers 2

1

WCF RESTful web services are going to be your friend. In order to force the web service to return JSON take a look at this related answer.

Update: If you have control over both the client and the service it may be worth looking into WCF Data Services as an alternative. Less code = more productivity (in some cases ;))

Sign up to request clarification or add additional context in comments.

4 Comments

i heard that Data Services doesn't support many LINQ features.. how is it in your experience?
Data Services is strongly tied to Linq to Entities. What linq features are you concerned about being left out?
Server side paging can be implemented using: blogs.msdn.com/b/astoriateam/archive/2010/02/02/…, or on the client side: solidcoding.blogspot.com/2007/11/paging-with-linq.html. While I haven't used the standard LINQ paging approach in the past against Data Services I don't see why it wouldn't work.
@JanCarloViray - On second thought, you're talking about consuming a WCF Data Service from an MVC page (presumably using AJAX), so if you are looking for an OData client library for Javascript, take a look at odata.org/developers/odata-sdk. It talks about OData clients for various languages including Javascript. In that case I would probably suggest utilizing server side paging because you don't really have Linq in Javascript to help you out.
1

A RESTful WCF service will work, like M.Babcock said, but you can just use Ajax to call your controller action; you call your controller, which in turn calls your WCF service and returns a JsonResult. Something like this...

Controller:

public JsonResult GetData() 
{
    var result = wcf.GetSomeData();
    return Json(result); 
}

View:

<script type="text/javascript">
    $(function() {
        $('#mybutton').click(function() {
             $.getJSON("/Home/GetData", null, function(data) {
                 alert(data);
             });
          });
    });
</script>

Here's a link to a better tutorial.

1 Comment

hmm.. seems like asp.net MVC as a 'REST service' would be better solution for this one huh.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.