Custom Object i WebService
Hej,Er for første gang begyndt at lege lidt med webservices. Jeg har nu et lille problem. Jeg skal returnere mit eget object. Når jeg gør det, og køre en test, får jeg denne fejl:
System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: Kaje cannot be serialized because it does not have a parameterless constructor.
at System.Xml.Serialization.TypeDesc.CheckSupported()
at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference, Boolean throwOnError)
at System.Xml.Serialization.TypeScope.GetTypeDesc(Type type)
at System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeException(Type type)
at System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name, String ns, Object o, Boolean xsiType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write1_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write2_ArrayOfAnyType(Object o)
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayListSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)
at System.Web.Services.Protocols.XmlReturnWriter.Write(HttpResponse response, Stream outputStream, Object returnValue)
at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
---
Mit object ser sådan ud:
Public Class Kaje
Implements IComparable
Private _kaje As String
Private _point As Integer
Public Sub New(ByVal kaje As String, ByVal point As Integer)
MyBase.New()
_kaje = kaje
_point = point
End Sub
Public ReadOnly Property Kaje() As String
Get
Return _kaje
End Get
End Property
Public ReadOnly Property Point() As Integer
Get
Return _point
End Get
End Property
Public Function CompareTo(ByVal o As Object) As Integer Implements IComparable.CompareTo
Dim mo As Kaje = CType(o, Kaje)
If _point = mo._point Then
Return _kaje.CompareTo(mo._kaje)
Else
Return _point - mo._point
End If
End Function
End Class
-----