例如,当使用 REST 请求对象时,是否可以获取 json 和 xml 格式的响应,或者我是否必须创建类似以下内容的 UriTemplates:
[WebInvoke(UriTemplate="&format=json?user/{id}", ResponseFormat=WebMessageFormat.Json)]
[WebInvoke(UriTemplate="&format=xml?user/{id}", ResponseFormat=WebMessageFormat.Xml)]
我问的原因是因为我可能需要为 Android 手机上的应用程序返回一种格式,并为笔记本电脑上的应用程序返回另一种类型。
另外,这些方法可以具有相同的名称(例如 Register)还是我必须调用一个方法:
RegisterJSON(User user) 和另一个称为 RegisterXML(User user)
开箱即用WCF 4 http://msdn.microsoft.com/en-us/library/ee476510.aspx(.NET 4.0)。查看自动格式选择已启用 http://msdn.microsoft.com/en-us/library/system.servicemodel.description.webhttpbehavior.automaticformatselectionenabled.aspxWebHttpBehavior 的属性。您还可以从配置中设置此属性。我展示了这个例子here https://stackoverflow.com/questions/3719594/return-multiple-response-from-wcf.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)