My goal is to retrieve an object of the Product
class as a Json
for a webservice. Despite successfully loading all the values into the object, I encounter an error when trying to return it as Json. Below is my method:
<AllowAnonymous> <HttpGet> _
Public Function GetProduct() As HttpResponseMessage
Try
Dim oProduct As New Product
oProduct = Product.GetProductByID(25)
Dim jsSerializer As System.Web.Script.Serialization.JavaScriptSerializer
jsSerializer = New System.Web.Script.Serialization.JavaScriptSerializer()
Dim sbProduct As New System.Text.StringBuilder()
jsSerializer.Serialize(oProduct, sbProduct)
Dim json As String = sbProduct.ToString()
Return Request.CreateResponse(HttpStatusCode.OK, json)
Catch exc As Exception
Return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc)
End Try
End Function
The response:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Exception has been thrown by the target of an invocation.
</ExceptionMessage>
...
Edit #1 Definition of Product
Public Class Product Inherits AddNew
Public Shared selectedProduct As New Product
Private iProductID As Integer
Public Property ProductID() As Integer
...
Any suggestions on how to resolve this issue?