WCF/WF - Web Host is not instantiating DataMember properties of defined types

Asked By Corey on 05-Jun-13 12:16 PM
I have a business, service and web projects in my solution.  Services is WCF library referencing the business layer and web host references Services and inherits my WCF service contracts.

In my unit test project I'm referencing the Web host which pulls in all the classes, methods, etc.  when I setup my NewApplication request object it is not instantiating the user defined properties.

[DataContract]
public class NewApplication{
 
  private CustomerAddress _customerAddress;
 
  public NewApplication()
    {
      _customerDetailData = new CustomerDetail();
    }
 
    [DataMember]
    public CustomerDetail PrimaryCustomerData
    {
      get { return this._customerDetailData; }
      set { this._customerDetailData = value; }
    }
}
 
[TestMethod]
public void TestNewApplication{}
{
  NewApplication _newApp = new NewApplication();
 
  _newApp.PrimaryCustomerData.Address1  //THIS IS NULL, PrimaryCustomerData
} What am I doing wrong here?
Robbe Morris replied to Corey on 05-Jun-13 01:32 PM
Your constructor doesn't get executed nor does any logic exist in these DataContract classes when instantiated client side.  That includes any logic you might embed in get/set statements.  They'll work server side in your WCF app because you have the original class.  When your client(s) make reference to the WCF service, Visual Studio .NET is creating shell classes based on the structure of the DataContract.  But, it has no concept of any code logic that exists in the class the contract is based on.
Corey replied to Robbe Morris on 05-Jun-13 03:32 PM
Thanks again Robbe, I realized this several minutes after.