title: How to pass a DateTime value to a WebMethod (ASMX)
body: <p>I have a WebMethod with a parameter defined as DateTime. When I call that</p>
  
  <p>webservice, I get this error:</p>
  
  <blockquote>
    <p>at
    System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()
    at
    System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32
    depth) at
    System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32
    depth) at
    System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32
    depth) at
    System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String
    input, Int32 depthLimit,
    JavaScriptSerializer serializer) at
    System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer
    serializer, String input, Type type,
    Int32 depthLimit) at
    System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String
    input) at
    System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext
    context, JavaScriptSerializer
    serializer) at
    System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData
    methodData, HttpContext context) at
    System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext
    context, WebServiceMethodData
    methodData)"</p>
  </blockquote>
  
  <p>This is my WebService:</p>
  
  <pre><code>/// &lt;summary&gt;
  /// Summary description for AgendamentoService
  /// &lt;/summary&gt;
  [WebService(Namespace = "http://tempuri.org/")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  [System.Web.Script.Services.ScriptService]
  public class AgendamentoService : System.Web.Services.WebService
  {
  
      public AgendamentoService()
      {
  
          //Uncomment the following line if using designed components 
          //InitializeComponent(); 
      }
  
      [WebMethod]
      public CompromissoWekCalendarVO[] GetCompromissos(int id_pessoa, DateTime start, DateTime end)
      {
          bo.CompromissoBO compBO = new bo.CompromissoBO();
          return compBO.Get(id_pessoa,start, end).ToArray();
      }
  
  }
  </code></pre>
  
  <p>And here, my client side code:</p>
  
  <pre><code> var params =  '{id_pessoa: "' + id_pessoa + '", start:/Date('+ start.getTime()+')/, end:/Date(' + end.getTime()+')/}';
                      $.ajax(  
                           {  
                               type: "POST",  
                               dataType: "json",
                               contentType: "application/json; charset=utf-8",  
                               url: '&lt;%= this.ResolveClientUrl("~/services/misc/AgendamentoService.asmx/GetCompromissos") %&gt;',  
                               data: params,  
                               success: function (json) {  
  
                                  if ($.isArray(json.d)) {
                                    $.each(json.d, function(key, value) {
                                      value.start = getJsonDate(value.start);
                                      value.end = getJsonDate(value.end);
                                    });
                                  }
  
                                  callback(json.d);                                 
  
                               }  
                           });
  </code></pre>
  
  <p>Where 'start' and 'end' time are two javascript 'Date' objects.</p>