0
votes

I am creating an ASP.NET MVC 4 application that relies on a WCF service for its BL.

The WCF reference file that was created holds all the data contracts with the service.

I would like to expose the data contracts to the end clients of my MVC application.

Should I use the data contracts in my controllers instead of creating models?

My end client needs JSON format responses. How can I decorate the data contract references with JSON attributes so it will get serialized the way I want it?

2

2 Answers

0
votes

Decorate your data contract with [DataContract] and decorate your operation contract for example with

[WebGet(UriTemplate='...', ResponseFormat=WebMessageFormat.Json]

The last part will make WCF use the JSON serializer.

0
votes

I think we have found a solution to the problem, our front end team is now sharing contracts with backend WCF service this is actually replacing our models in the MVC application (not all of theme but most of theme). We can decorate our contracts as we like and we take the benifit of both worlds. @Suhani Mody