Reputation: 1317
How can I get the overloaded constructors on my classes passed on to the WCF client/consumer?
Basically, WCF thinks there is only the default, no argument/empty constructor for my B class. How can I enable the client to call the overloaded constructors?
public class A
{
public string MyField { get; set; }
}
public class B : A
{
public List<C> MyList { get; set; }
// when called on the WCF client side, MyList is null (so this constructor is not being called)
public B()
{
MyList = new List<C>();
}
// not available on WCF client side
public B(A a) : this()
{
base.MyField = a.MyField;
}
// not available on WCF client side
public void DoSomething()
{
// do stuff
}
}
Upvotes: 0
Views: 492
Reputation: 9499
A constructor is a class only construct that a wcf client is not aware of. The boundaries are different.
The client just knows about a proxy class. And the WCF infrastructure creates the proxy class with the default constructors. Independent of the constructors at the server side, because they don't mean anything from the WCF perspective.
Only Service Contracts, Operation COntracts and Data Contracts matter.
if you want additional functionality in your proxy class, you can always add a partial class with the same name on your client side and add code to it. (overloaded constructors etc.) be aware that the server doesn't really care about this.
Upvotes: 2