title: SOAP deserialization of DateTime object with value "0000-00-00" fails
body: <p>I have a simple application that gets data records via SOAP. The SOAP webservice was added via "service references" to the project. The calls work fine. I just have a problem when the data holds the value <code>0000-00-00</code> for a date which the reference code will store into an <code>DateTime</code>-object. The <code>DateTime</code> class has foreseen a minimal value of <code>0001-0-01</code> which will ultimately lead to the error upon deserializing the response from a SOAP call.</p>
  
  <p>The code that gets executed to pull the data via SOAP is the following:</p>
  
  <pre><code>TopixSOAP.TOPIXRPCClient soap = new TopixSOAP.TOPIXRPCClient();
  soap.GetProjekt(out error_code, out start_date, out end_date, instance, user, passwd, project_number);
  </code></pre>
  
  <p>So I provide the neccessary information to the SOAP call and it performs well if the start_date and end_date are => <code>0001-01-01</code>. But since the data sometimes contains values for the dates of <code>0000-00-00</code> the application crashes naturally on deserializing the the value into an <code>DateTime</code> object.</p>
  
  <p>I tried to wrap all the out parameters into a separate class called TopixProject:</p>
  
  <pre><code>public class TOPIXProject
  {
  
      public TOPIXProject()
      {
      }
      public string ErrorCode
      {
          get
          {
              return ErrorCode;
          }
          set
          {
              ErrorCode = value;
          }
      }
  
      public DateTime StartDate
      {
          get
          {
              return StartDate; 
          }
          set
          {
              StartDate = DateTime.MinValue;
          }
      }
  
      public DateTime EndDate
      {
          get
          {
              return EndDate;
          }
          set
          {
              EndDate = DateTime.MinValue;
          }
      }
  </code></pre>
  
  <p>Here the modified call:</p>
  
  <pre><code>soap.SOAP_GetProject(out p.ErrorCode, out p.StartDate, out p.EndDate, instance, user, passwd, project_number);
  </code></pre>
  
  <p>The class should set the value to <code>DateTime.MinValue</code> so I don't get the error anymore. It dosn't work as I intended to: The members of the class <code>TOPIXProject</code> can't be used as out or ref parameters for a function.</p>
  
  <p>If i provide "raw" out variables that I declare before the SOAP call, it works if the dates are in the valid range (=> <code>0001-01-01</code>) of the <code>DateTime</code> class definitions:</p>
  
  <pre><code>string error_code = "";
  DateTime start_date, end_date;
  soap.GetProjekt(out error_code, out start_date, out end_date, instance, user, passwd, project_number);
  </code></pre>
  
  <p>But I have a lot of data records where the date is <code>0000-00-00</code> and it can't be changed (it's an internal marking of unterminatable projects).
  So what do I need to do to get valid SOAP responses?</p>
  
  <ul>
  <li>mainly if the date of the data set is <code>0000-00-00</code> I want to get a <code>DateTime.MinValue</code></li>
  <li>Or can I tell the service reference to interpret everything as a string? (Because the service reference builds the code itself and tries to parse the xsd:date type to DateTime, which is in my case pretty bad)</li>
  </ul>
  
  <h2><strong>Edit:</strong></h2>
  
  <p>I now use part of the SOAP calls from the service reference (basically all where no dates are passed back). For the rest I implemented a SOAPHelper class which provides the necccessary calls to the SOAP endpoint and returns mostly strings or XML. Code example <a href="https://stackoverflow.com/a/2435843/526709">here</a></p>