Search code examples
wcfdatacontract

WCF DataContract ToString function


Can you override the ToString function in a WCF DataContrat? Right now I have:

[DataContract]
public class Keyword
{
    public int ID { get; set; }
    public string Name { get; set; }

    public override string ToString()
    {
        return Name;
    }
}

But it doesn't seem to work. Anyway to get this working?


Solution

  • Remember too that if you own both the server and the client, that often you can use a shared library for data contracts rather than generating a client proxy. If you do that, then you can have the same method on both the server and client as they're exactly the same type.