[CLOSED] Problem with dates

Page 2 of 3 FirstFirst 123 LastLast
  1. #11
  2. #12
    As you can read in this thread: http://social.msdn.microsoft.com/For...ed-on-timezone

    The problem is that I don't care about time, just want the date (short date i.e. 5/31/2011). In my case the date is stored as 5/31/2011 0:00:000.00 in SQL. When my web service is called from a timezone that is -3 hours from the servers timezone, the client's date becomes 5/30/2011 9:00 PM and the client code is using the short date part only so 5/31/2011 is now 5/30/2011. This is obviously causing problems.
    This guy has the same problem as you. So his solution was:

    turn the date into a string on the service side. This string will use the server's timezone. And since now it is merely a string, the client will see it as is. You can do that inside your service. You don't need to modify the database.
    Try to apply it. If it will not work please try to test using our databases from Examples.
    Last edited by Baidaly; Jul 26, 2013 at 3:54 AM.
  3. #13
  4. #14
    Is the grid empty at all or the DATAHORA column only?

    Please try to replace
    { name: 'DATAHORA', type: 'date', dateFormat: "MS" }
    with
    { name: 'DATAHORA', type: 'date', dateFormat: "c" }
  5. #15
    No! All grid is empty... No records loaded in grid!

    Thanks
  6. #16
    Quote Originally Posted by supera View Post
    You tell me that:
    We (Ext.NET) don't affect how a WebService deserialize a response
    I still do not understand the issue... the problem is that the ASP.NET serializes the paging object or is another lib of Ext.net that does this???
    ASP.NET WebService deserializes it and we cannot affect it. You are not confined to use the Paging class, but you will get the same result without it.

    This is also not a solution
    Return Ext.Net.JSON.Serialize(paging)
    because an AjaxProxy's Reader gets just a string this way, not an array of records.

    I think the following could be a solution.
    [WebMethod]
    public object GetData()
    {
        return new 
        {
            data = JSON.Serialize(data), // not a Paging instance here. In your case it should be "list.AsEnumerable" which you passed to the Paging constructor in the DataTableToPaging method
            total = 2
        };
    }
    Here is a full example.

    Page
    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:GridPanel ID="GridPanel1" runat="server">
                <Store>
                    <ext:Store runat="server">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="test" />
                                    <ext:ModelField Name="date" Type="Date" />
                                </Fields>
                            </ext:Model>
                        </Model>
                        <Proxy>
                            <ext:AjaxProxy Url="WebService1.asmx/GetData" Json="true">
                                <ActionMethods Read="POST" />
                                <Reader>
                                    <ext:JsonReader Root="d.data" TotalProperty="d.total" />
                                </Reader>
                            </ext:AjaxProxy>
                        </Proxy>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server">
                    <Columns>
                        <ext:Column runat="server" Text="Test" DataIndex="test" />
                        <ext:DateColumn runat="server" Text="Date" DataIndex="date" />
                    </Columns>
                </ColumnModel>
            </ext:GridPanel>
        </form>
    </body>
    </html>
    WebService
    using System;
    using System.Web.Services;
    using Ext.Net;
    
    namespace Work2
    {
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        [System.Web.Script.Services.ScriptService]
        public class WebService1 : System.Web.Services.WebService
        {
            [WebMethod]
            public object GetData()
            {
                return new 
                {
                    data = JSON.Serialize(new object[] 
                    { 
                        new 
                        { 
                            test = "test1", 
                            date = DateTime.Today
                        },
                        new 
                        { 
                            test = "test2", 
                            date = DateTime.Today.AddDays(1)
                        }
                    }),
                    total = 2
                };
            }
        }
    }
    This way this setting should affect.
    Ext.Net.JSON.GlobalSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local
    By the way, you could avoid such problems using, for example, an ASHX handler instead of a WebService.
    http://localhost:51297/#/GridPanel/P...rting/Handler/

    Is there a specific reason why you picked up a WebService?
    Last edited by Daniil; Jul 26, 2013 at 1:53 PM.
  7. #17
    Daniil! Thanks a lot for your help!!! I think that expensive for you show me a trail! Thanks again!

    No reason for webservices... I belived it was the right way to integrate client and the server...

    Why I could avoid such problems using ASHX handler instead of a WebService?

    Excuse me for being so stupid in this matter!
  8. #18
    Quote Originally Posted by supera View Post
    No reason for webservices... I belived it was the right way to integrate client and the server...
    Well, using WebServices is good to wire up server and client. Unless you run into such issues.

    Quote Originally Posted by supera View Post
    Why I could avoid such problems using ASHX handler instead of a WebService?
    Well, an ASHX handler doesn't serialize the things automatically. You will be forced to serialized it manually. So, more room for flexibility. And JSON.Serialize() is nice to use for that.
  9. #19
    Ok!

    I will follow the trail that you showed to me!

    Thanks a lot, Daniil!!!
  10. #20
    Quote Originally Posted by supera View Post
    No reason for webservices... I belived it was the right way to integrate client and the server...

    Why I could avoid such problems using ASHX handler instead of a WebService?
    Sorry I am very late to this thread. The other thing to bear in mind is that ASMX WebServices uses the DataContractJsonSerializer, not Json.NET. I remember stumbling onto this while writing the book. Here's what I wrote (sorry, not plugging the book, just remembered it was in there!)

    p.147:
    If we looked at the result, we would see something odd-looking, for example, /Date(1335752521448)/.

    If the response from the server was a string, or a number, there'd be no problems here. Dates from ASMX Web Services, however, are a bit more involved.

    Unfortunately, JSON doesn't specify a standard way to represent dates, while strings and numbers are fine. The JSON serialization used by ASMX services (DataContractJsonSerializer) creates a date using a pattern that was initially designed to be consumed by its own client-side AJAX library.

    However, we are using Ext.NET and Ext JS, so we would have to handle this difficult-to-debug format manually. We can use Ext JS's client-side Date formatting API, for example, Ext.Date.parseDate("/Date(1335752521448)/", 'MS') which will give you back a JavaScript date object.

    Alternatively, you could configure your service to return the date as a string that can be parsed when needed. Unfortunately, there is still no one way for JSON to agree and handle dates but at least there are some options here.
    It is for reasons like this that I personally prefer to use ASHX or an MVC Controller for DirectMethods instead of ASMX, for example.

    Hope that helps.
Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. [CLOSED] Specify how object is serialized in DirectMethod
    By jchau in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Jan 12, 2013, 7:18 PM
  2. [CLOSED] Dates & Json & ComboBoxes
    By PhilG in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: May 24, 2012, 2:45 PM
  3. Replies: 10
    Last Post: Aug 01, 2011, 1:58 PM
  4. Replies: 3
    Last Post: May 11, 2010, 4:47 AM
  5. Problem with disable dates, when using culture setting
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Feb 26, 2009, 9:25 AM

Posting Permissions