title: WCF returns object with only default values
body: <p>I have a test class <code>CustObject</code> which has <code>DataContract</code> and <code>DataMember</code> attributes. When I return this to the client, however, all values are the default value.</p>
  
  <p>Service Side:</p>
  
  <pre><code>[DataContract]
  public class CustObject
  {
      [DataMember (IsRequired = true)]
      public int n1;
      [DataMember (IsRequired = true)]
      public int n2;
  
      [DataMember]
      public int val1 = 552;
  
      [DataMember]
      public int? val2 = 88;
  
      [DataMember]
      int val3 = 11;
  
      [DataMember]
      string val4 = "hello world";
  
  
      public CustObject()
      {
          n1 = 1;
          n2 = 2;
      }
  
      private int nprivate = 18;
  
  
  
  }
  
  
  
      public class CalculatorService : ICalculator
  {
  
      public CustObject Foo()
      {
          Console.WriteLine();
          CustObject test =  new CustObject();
          Console.WriteLine("Should read that n1 = {0} and n2 = {1}", test.n1, test.n2);
          return test;
      }
  }
  
  [ServiceContract]
  public interface ICalculator
  {
      [OperationContract]
      CustObject Foo();
  }
  </code></pre>
  
  <p>Client side:</p>
  
  <pre><code>    public static void Main ()
      {
          CalculatorClient client = new CalculatorClient(
                                        new WSHttpBinding(SecurityMode.None),
                                         new EndpointAddress("http://localhost:8000/ServiceModelSamples/Service/CalculatorService"));
  
  
  
          CustObject custObj = client.Foo();
          Console.WriteLine(custObj.val1 + ", " + custObj.val2 + ", " + custObj.val1 + ", " + custObj.val2 + ", " +
                            custObj.val3 + ", " + custObj.val4);
  
          //Step 3: Closing the client gracefully closes the connection and cleans up resources.
          client.Close ();
  
  
          Console.WriteLine ();
          Console.WriteLine ("Press &lt;ENTER&gt; to terminate client.");
          Console.ReadLine ();
      }
  }
  </code></pre>
  
  <p>And the output is just <code>0, 0, 0, 0, 0,</code> (the last value is an empty string)</p>
  
  <p>I have read a ton of stuff to try to figure out this problem. It seems that even though the values are initialized, the xml conversion is just giving every field a default value. I can't figure out why.</p>
  
  <p>I used svutil to create the proxy file.</p>