开发者

Optional data format in WCF uri, but NOT in query string params

Problem: I have the f开发者_Python百科ollowing requirement while developing in WCF 4: Data format to return should be requested in uri template at the end BEFORE any possible query string. Example: /resource1/resoursce2.xml This url should result in data returned in xml format. If ".xml" is omitted from the url (/resource1/resoursce2) then data should be returned in Json format. Futhermore, I need to do it with one operation contract (one uri template). Question: does WCF 4 have any support for this? Thank you.


It's possible. You need to do it using WCF Rest framework. You can set up following pathes

  1. /resource1/resource2/format/xml url that will return xml
  2. /resource1/resource2/format/json url that will return json

My advice is to use route table for this

See this link how to implement it http://msdn.microsoft.com/en-us/library/cc668201.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜