Class serialization issue
I have an error in the the following class, but am unsure where it is. The class will return correctly in my service but does not serialize and return any results. Any help would be greatly appreciated.
Imports System
Imports System.Data.Objects
Imports System.Data.Objects.DataClasses
Imports System.Data.EntityClient
Imports System.ComponentModel
Imports System.Xml.Serialization
Imports System.Runtime.Serialization
' <summary>
'<para>This class is used to load Email objects.</para>
' <para>
' CreateDate: 6-14-2011
' ModifyDate: 6-14-2011
' ModifyDesc: Initial Creation
' </para>
' </summary>
'
#Region "Email"
''' <summary>
''' Email class.
''' </summary>
<DataContractAttribute(IsReference:=True)>
<KnownTypeAttribute(GetType(CompanyLocEmail))>
<KnownTypeAttribute(GetType(CompanyEmail))>
<KnownTypeAttribute(GetType(UserEmail))>
Partial Public MustInherit Class Email
#Region "Declarations"
<DataMemberAttribute()>
Private _IsPreferred As Nullable(Of Global.System.Boolean)
<DataMemberAttribute()>
Private _EmailTypeL As Global.System.String
<DataMemberAttribute()>
Private _EmailTypeS As Global.System.String
<DataMemberAttribute()>
Private _EmailAddress As Global.System.String
<DataMemberAttribute()>
Private _XID As Global.System.Int32
<DataMemberAttribute()>
Private _EID As Global.System.Int32
#End Region
#Region "Primitive Properties"
#Region "IsPreferred"
''' <summary>
''' IsPrefferred.
''' </summary>
Public Property IsPreferred() As Nullable(Of Global.System.Boolean)
Get
Return _IsPreferred
End Get
Set(value As Nullable(Of Global.System.Boolean))
OnIsPreferredChanging(value)
_IsPreferred = value
OnIsPreferredChanged()
End Set
End Property
Partial Private Sub OnIsPreferredChanging(value As Nullable(Of Global.System.Boolean))
End Sub
Partial Private Sub OnIsPreferredChanged()
End Sub
#End Region
#Region "EmailTypeL"
''' <summary>
''' EmailTypeL.
''' </summary>
Public Property EmailTypeL() As Global.System.String
Get
Return _EmailTypeL
End Get
Set(value As Global.System.String)
OnEmailTypeLChanging(value)
_EmailTypeL = value
OnEmailTypeLChanged()
End Set
End Property
Partial Private Sub OnEmailTypeLChanging(value As Global.System.String)
End Sub
Partial Private Sub OnEmailTypeLChanged()
End Sub
#End Region
#Region "EmailTypsS"
''' <summary>
''' EmailTypeS.
''' </summary>
Public Property EmailTypeS() As Global.System.String
Get
Return _EmailTypeS
End Get
Set(value As Global.System.String)
OnEmailTypeSChanging(value)
_EmailTypeS = value
OnEmailTypeSChanged()
End Set
End Property
Partial Private Sub OnEmailTypeSChanging(value As Global.System.String)
End Sub
Partial Private Sub OnEmailTypeSChanged()
End Sub
#End Region
#Region "EmailAddress"
''' <summary>
''' EmailAddress.
''' </summary>
Public Property EmailAddress() As Global.System.String
Get
Return _EmailAddress
End Get
Set(value As Global.System.String)
OnEmailAddressChanging(value)
_EmailAddress = value
OnEmailAddressChanged()
End Set
End Property
Partial Private Sub OnEmailAddressChanging(value As Global.System.String)
End Sub
Partial Private Sub OnEmailAddressChanged()
End Sub
#End Region
#Region "EID"
''' <summary>
''' EID.
''' </summary>
Public Property EID() As Global.System.Int32
Get
Return _EID
End Get
Set(value As Global.System.Int32)
If (_EID <> value) Then
OnEIDChanging(value)
_EID = value
OnEIDChanged()
End If
End Set
End Property
Partial Private Sub OnEIDChanging(value As Global.System.Int32)
End Sub
Partial Private Sub OnEIDChanged()
End Sub
#End Region
#Region "XID"
''' <summary>
''' XID.
''' </summary>
Public Property XID() As Global.System.Int32
Get
Return _XID
End Get
Set(value As Global.System.Int32)
If _XID <> value Then
OnXIDChanging(value)
_XID = value
OnXIDChanged()
End If
End Set
End Property
Partial Private Sub OnXIDChanging(value As Global.System.Int32)
End Sub
Partial Private Sub OnXIDChanged()
End Sub
#End Region
#End Region
End Class
#End Region
#Region "CompanyEmail"
''' <summary>
''' CompanyEmail class.
''' </summary>
<DataContractAttribute(IsReference:=True)>
Partial Public Class CompanyEmail
Inherits Email
#Region "Declarations"
<DataMemberAttribute()>
Private _Company As Company
#End Region
#Region "Factory Method"
''' <summary>
''' Create a new CompanyEmail object.
''' </summary>
''' <param name="emailTypeL">Initial value of the EmailTypeL property.</param>
''' <param name="emailTypeS">Initial value of the EmailTypeS property.</param>
''' <param name="emailAddress">Initial value of the EmailAddress property.</param>
''' <param name="eID">Initial value of the E开发者_JS百科ID property.</param>
''' <param name="xID">Initial value of the XID property.</param>
Public Shared Function CreateCompanyEmail(emailTypeL As Global.System.String, emailTypeS As Global.System.String, emailAddress As Global.System.String, eID As Global.System.Int32, xID As Global.System.Int32) As CompanyEmail
Dim companyEmail As CompanyEmail = New CompanyEmail
companyEmail.EmailTypeL = emailTypeL
companyEmail.EmailTypeS = emailTypeS
companyEmail.EmailAddress = emailAddress
companyEmail.EID = eID
companyEmail.XID = xID
Return companyEmail
End Function
#End Region
#Region "ParentProperties"
<XmlIgnoreAttribute()>
<SoapIgnoreAttribute()>
Public Overridable Property Company() As Company
Get
Return _Company
End Get
Set(value As Company)
_Company = value
End Set
End Property
#End Region
End Class
#End Region
#Region "CompanyLocEmail"
''' <summary>
''' CompanyLocEmail class.
''' </summary>
<DataContractAttribute(IsReference:=True)>
Partial Public Class CompanyLocEmail
Inherits Email
#Region "Declarations"
Private _CompanyLoc As CompanyLoc
#End Region
#Region "Factory Method"
''' <summary>
''' Create a new CompanyLocEmail object.
''' </summary>
''' <param name="emailTypeL">Initial value of the EmailTypeL property.</param>
''' <param name="emailTypeS">Initial value of the EmailTypeS property.</param>
''' <param name="emailAddress">Initial value of the EmailAddress property.</param>
''' <param name="eID">Initial value of the EID property.</param>
''' <param name="xID">Initial value of the XID property.</param>
Public Shared Function CreateCompanyLocEmail(emailTypeL As Global.System.String, emailTypeS As Global.System.String, emailAddress As Global.System.String, eID As Global.System.Int32, xID As Global.System.Int32) As CompanyLocEmail
Dim companyLocEmail As CompanyLocEmail = New CompanyLocEmail
companyLocEmail.EmailTypeL = emailTypeL
companyLocEmail.EmailTypeS = emailTypeS
companyLocEmail.EmailAddress = emailAddress
companyLocEmail.EID = eID
companyLocEmail.XID = xID
Return companyLocEmail
End Function
#End Region
#Region "ParentProperties"
<DataMemberAttribute()>
<XmlIgnoreAttribute()>
<SoapIgnoreAttribute()>
Public Overridable Property CompanyLoc() As CompanyLoc
Get
Return _CompanyLoc
End Get
Set(value As CompanyLoc)
_CompanyLoc = value
End Set
End Property
#End Region
End Class
#End Region
#Region "UserEmail"
''' <summary>
''' UserEmail class.
''' </summary>
<DataContractAttribute(IsReference:=True)>
Partial Public Class UserEmail
Inherits Email
#Region "Declarations"
Private _UserRole As UserRole
#End Region
#Region "Factory Method"
''' <summary>
''' Create a new UserEmail object.
''' </summary>
''' <param name="emailTypeL">Initial value of the EmailTypeL property.</param>
''' <param name="emailTypeS">Initial value of the EmailTypeS property.</param>
''' <param name="emailAddress">Initial value of the EmailAddress property.</param>
''' <param name="eID">Initial value of the EID property.</param>
''' <param name="xID">Initial value of the XID property.</param>
Public Shared Function CreateUserEmail(emailTypeL As Global.System.String, emailTypeS As Global.System.String, emailAddress As Global.System.String, eID As Global.System.Int32, xID As Global.System.Int32) As UserEmail
Dim userEmail As UserEmail = New UserEmail
userEmail.EmailTypeL = emailTypeL
userEmail.EmailTypeS = emailTypeS
userEmail.EmailAddress = emailAddress
userEmail.EID = eID
userEmail.XID = xID
Return userEmail
End Function
#End Region
#Region "ParentProperties"
<DataMemberAttribute()>
<XmlIgnoreAttribute()>
<SoapIgnoreAttribute()>
Public Overridable Property UserRole() As UserRole
Get
Return _UserRole
End Get
Set(value As UserRole)
_UserRole = value
End Set
End Property
#End Region
End Class
#End Region
Interface definition
<OperationContract()> _
Function GetEmail(iID As Integer) As UserEmail
Actual Call
Public Function GetEmail(iID As Integer) As UserEmail Implements InsightDataAPIInterface.GetEmail
Dim ret = (From c In db.Emails Where c.EID = iID Select c).Take(1)
Dim y As UserEmail
For Each x In ret
y = CType(x, UserEmail)
Next x
'Breakpoint here shows correct data in y, so y returns the class
Return y
End Function
This will not be the final iteration of GetEmail, but I am using this in it's current state to try and figure out why I am not getting the class to serialize correctly. If anyone could nudge me in the correct direction I would be greatly in their debt. :)
Try adding a Namespace property in your <DataContract>
declaration. In Visual Basic I've seen many cases where the Root Namespace property of the client / server projects are different (they default to the project name, which are expected to be different) - and the root namespace ends up being used to define the CLR namespace of the classes. if the namespace of a data contract is not explicitly set, then WCF will use the CLR namespace, and if the client / server classes are in different namespaces, you'll see an error like the one you have.
<DataContractAttribute(IsReference:=True, Namespace:="http://my.namespace.com")>
精彩评论