user1318951
user1318951

Reputation:

Implement Restful WCF OData Service

I've implemented a WCF OData Service in my project. Right now I need to my services return JsonResult for my clients. How can I implement Restful WCF OData Service? Or is there any alternative approach to return JsonResult in my services?

Upvotes: 2

Views: 431

Answers (1)

Anand
Anand

Reputation: 14915

OData Services natively support JSON. So if in the HTTP Request header you are specifying following header, you would always get JSON

accept: application/json

If you can not control the this, then I suggest you to use $format filter.

For example See http://odata.netflix.com/v2/Catalog/Genres?$Format=json

JSONp and URL-controlled format support for ADO.NET Data Services download from MSDN http://code.msdn.microsoft.com/DataServicesJSONP and add the JSONPSupportBehavior decorator to your DataService class like below.

[JSONPSupportBehavior]
public class SomeService: DataService<ContextType>
{

The other option could be to build ASP.NET Web API. Its an ideal platform for building RESTful applications on the .NET Framework.

Upvotes: 1

Related Questions