我有一个用vb.net编写的REST Service,默认情况下,除非我设置了ResponseFormat:=WebMessageFormat.Json,否则返回的响应是XML。所以我希望我可以根据用户传入的头来更改ResponseFormat。所以我会这样编写我的<WebGet>代码:
<WebGet(UriTemplate:="UserNames/", BodyStyle:=WebMessageBodyStyle.WrappedResponse)>
Public Function UserNamesList() As List(Of UserNames)
'check the Headers for either XML or Json and then set the ResponseFormat
Return intUserNamesList()
End Function那么,有没有办法在<WebGet>声明之外设置ResponseFormat或等效物呢?
发布于 2016-01-15 19:49:42
我想我已经破解了。我可以在我的函数中使用WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Xml或WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json
https://stackoverflow.com/questions/34810262
复制相似问题