【发布时间】:2015-08-02 22:28:08
【问题描述】:
我遇到了对 Web API 调用的 XML 响应问题。 具体来说,我有一个函数“GetValue”调用,当我应该基于 id 或类“Cellulare”或类“Televisore”以 XML 格式返回时。
问题是,如果我从浏览器发出请求,则会出现以下错误:
<Message>An error has occurred.</Message>
<ExceptionMessage>
The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'.
</ExceptionMessage>
这是一个例子:
Public Class Cellulare
Public Property Colore As String
Public Property SistemaOperativo As String
End Class
Public Class Televisore
Public Property Colore As String
Public Property Marca As String
End Class
Public Function GetValue(ByVal id As Integer) // ' As Cellulare
If Id = 1 Then
Dim MyTelevisore As New Televisore
MyTelevisore.Colore = "grigio"
MyTelevisore.Marca = "lg"
Return MyTelevisore
Else
Dim MyCellulare As New Cellulare
MyCellulare.Colore = "nero"
MyCellulare.SistemaOperativo = "android"
Return MyCellulare
End If
End Function
谁能帮我解决这个问题???
提前致谢 你好 多纳托
【问题讨论】:
标签: asp.net xml vb.net asp.net-web-api