C# – constructor not showing up in the WCF client, serialization problem

cserializationwcf

I have a simple class in my WCF service that doesn't seem to be showing up properly for the client that accesses my WCF.

My class has 4 public properties that are of type string.

I marked the class with [DataContract()] and each member with [DataMember].

Why is my constructor not visible? Is there a special [attribute] for constructors?

Best Answer

Data contracts do not have anything to do with constructors. So, when you create your proxy on the client, you will only get a class that implements the data contract.

If you want to add a similar constructor on the client side (assume the type generated is named SomeDataItem), you can add it using a partial class:

public partial class SomeDataItem
{
    public SomeDataItem(int a, int b)
    {
        A = a;
        B = b;
    }
}
Related Topic