Reputation: 12132
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...
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! :)
Upvotes: 0
Views: 1743
Reputation: 4262
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.
Upvotes: 1
Reputation: 18965
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 ;))
Upvotes: 1