How to build WCF for ASP.net MVC (client-side) architecture using JSON format / endpoint as communication method?
I'm leaning towards WCF as my main source of service (may need multiple endpoints in the future) and here's what I'm stuck with ...
- WCF for CLIENT: How can I get my MVC to accept JSON data from WCF service and parse it into C # primitive / complex types?
-
CLIENT for WCF: How to send JSON files from MVC to WCF and parse them into C # primitive / complex types?
-
Question: How can I force WCF to use REST as its protocol and pass JSON data? Am I using the REST starter kit, or is it embedded in WCF?
Basically, this is my architecture:
WCF === (format: JSON) ===> ASP.net MVC 3 (... and vice versa)
WCF === (format: JSON) ===> misc client (... and vice versa)
code examples would help a lot!
Thanks in advance for your help! :)
source to share
WCF RESTful Web Services will be your friend. To get the web service to return JSON, see this linked answer .
Update. If you have control over the client and the service, it might be worth looking into WCF Data Services as an alternative. Less code = more performance (in some cases;))
source to share
A RESTful WCF service will work as 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 that...
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.
source to share