1

I need to build a service layer. I needs to service an MVC UI layer. And it also needs to service native apps. I want to deliver everything in json because the packet size is small and I don't want multiple protocols to debug.

I like using SOAP however because it lets you easily build references using c#.

So im a bit stuck. Whats the best way to build a service layer to return json and automatically build from some contract? Is there a way?

Exitos
  • 29,230
  • 38
  • 123
  • 178
  • [This question](http://stackoverflow.com/questions/2086666/wcf-how-do-i-return-clean-json) might give you some hints. Or you could also consider building you service with [asp.net web api](http://www.asp.net/web-api) – Manu Clementz Apr 19 '12 at 07:21

2 Answers2

2

You can use simple json-serialization in your WCF operationContract method:

[WebInvoke(Method = "GET",
       RequestFormat = WebMessageFormat.Json,
       ResponseFormat = WebMessageFormat.Json,
       UriTemplate = "myTpl")]
fmgp
  • 1,638
  • 17
  • 17
0

You can enable json by adding setting to your config under endpointBehaviors:

<webHttp defaultOutgoingResponseFormat="Json"/>
Petar Vučetin
  • 3,555
  • 2
  • 22
  • 31