Take the 2-minute tour ×

I have the following web-service which works perfectly as long as it is accessed from a clientside script (javascript, jquery)

<%@ WebService Language="VB" Class="WebService" %>

Imports System.Web.Script.Services
Imports System.Web.Services

<ScriptService()> _
Public Class WebService
    Inherits System.Web.Services.WebService

    Public Class Person
        Public FirstName As String
        Public LastName As String

        Public Sub New(ByVal m_FirstName As String, ByVal m_LastName As String)
            FirstName = m_FirstName
            LastName = m_LastName
        End Sub
    End Class

    <WebMethod()> _
    Public Function GetPersons() As List(Of Person)
        Dim People As List(Of Person) = New List(Of Person)

        People.Add(New Person("firstname_1", "surname_1"))
        People.Add(New Person("firstname_2", "surname_2"))

        Return People
    End Function
End Class

But for some reason it gives me errors if I try to access it directly in the browser


to see the standard web-service service description showing all the operations supported

The error I get is:

WebService.Person cannot be serialized because it does not have a parameterless constructor.
share|improve this question
why not adding a parameter-less constructor then? –  Md Oliya Jul 15 '11 at 12:12
I doubt I would have posted this question if I knew what that was all about. –  oshirowanen Jul 15 '11 at 12:14
VB.NET is so ugly.. –  algiecas Jul 15 '11 at 12:29
add comment

1 Answer

up vote 1 down vote accepted

Add a parameterless constructor for your Person

  Public Class Person
        Public FirstName As String
        Public LastName As String

        Public Sub New()
          'just add this constructor  
        End Sub
    End Class
share|improve this answer
add comment

Your Answer


