I working on a REST service based on the 'WCF REST Service template' in VS2010. Out-of-the-box, you can have a service return XML or JSON, based on the Accept type specified in the request, but how do I add my own format.... I found an example:
http://msdn.microsoft.com/en-us/library/ee476510.aspx
where you test the Accept header in the method, and return Message based on that type, however I don't really like to implement this in all my service methods.
What I'd really like is a way where I could annotate (attribute) my DataContract with a formatter/serializer for each kind of Content-Type that I want to support, and then framework call my formatter/serialiser when asked for a Content-Type not supported out-of-the-box.开发者_JAVA百科
Are there already some extensionpoints, in the WCF REST Service framework, for doing this??
Any help would be greatly appreciated TIA
Søren
WcfRestContrib should be able to do this via Formatters. It provides set of build in formatters for XML, JSON, URL encoded form posts and it also allows creating custom formatters.
Built in webHttpBinding
in WCF doesn't have this functionality at the moment - it allows only appliation/json
and text/xml
negotiation and other content types can be mapped to these two via custom content type mapper.
"Attributes" for response formatting are only available for syndication where it works little bit differently. Service must always return SyndicationFeedFormatter
and known types allow defining multiple derived formatters for Atom or Rss.
精彩评论