0

To receive entities from database I created the class with virtual members. When I received an entity from database I cant serialize it and I can't send it by web service. Is there any any ways to solve this problem?

Max Kilovatiy
  • 798
  • 1
  • 11
  • 32

1 Answers1

0

Do your typical setup...

public class MyTable
{
    public virtual int ID {get;set;}
    public virtual string Name {get;set;}
}

I have a special response class I wrap my data in when responding to a web service call

using System.Xml.Serialization;
... 

[XmlInclude(typeof(Response))]
[XmlInclude(typeof(MyTable))]
public class Response
{
    public virtual bool Success {get;set;}
    public virtual MyTable MyTable {get;set;}
}

The "[XmlInclude(typeof(Response))]" and "[XmlInclude(typeof(MyTable))]" causes the table "MyTable" to serialize as XML within "Response". If you reference "MyTable" as a list you will need "[XmlInclude(typeof(List))]".

I hope this helps put you on the right track. I had a hard time with the same thing until I found something similar to this.