1. #31
    Sencha User
    Join Date
    Jan 2008
    Location
    Toronto, Canada
    Posts
    481
    Vote Rating
    4
    elishnevsky is on a distinguished road

      0  

    Default


    Let me have a think Although it might be very tricky and not worth the effort. I personally don't see a hude need in passing objects as objects, I am fine with passing them as strings. It the end, passing an object as a string and deserializing it to an object on the server yourself is pretty easy, and also you have full controll over how it is done.

  2. #32
    Ext JS Premium Member
    Join Date
    Nov 2008
    Location
    Warsaw area, Poland
    Posts
    64
    Vote Rating
    1
    nightwatch is on a distinguished road

      0  

    Default


    Quote Originally Posted by elishnevsky View Post
    Let me have a think Although it might be very tricky and not worth the effort. I personally don't see a hude need in passing objects as objects, I am fine with passing them as strings. It the end, passing an object as a string and deserializing it to an object on the server yourself is pretty easy, and also you have full controll over how it is done.
    But then, why did you bother writing all this sophisticated Ext.Direct.MVC library if you can pass everything in a JSon string and decode it manually on the server?

  3. #33
    Sencha User
    Join Date
    Jan 2008
    Location
    Toronto, Canada
    Posts
    481
    Vote Rating
    4
    elishnevsky is on a distinguished road

      0  

    Default


    Quote Originally Posted by nightwatch View Post
    But then, why did you bother writing all this sophisticated Ext.Direct.MVC library if you can pass everything in a JSon string and decode it manually on the server?
    Hmm.. I don't know how exactly to answer your question. If you are ready to throw away this library just because you can't pass complex types as objects, then go ahead, I'm not forcing anyone to use it Maybe you can find an easier way to generate API, parse and route your requests, do batching and so on... And don't forget, you can still use the good old Ext.Ajax.request().

  4. #34
    Ext JS Premium Member
    Join Date
    Nov 2008
    Location
    Warsaw area, Poland
    Posts
    64
    Vote Rating
    1
    nightwatch is on a distinguished road

      0  

    Default


    Hi, I'm sorry if my remarks seemed offensive, didn't mean it - I just wanted to give you some inspiration about future development. Without handling json objects this library is not very useful for me, but as I see all the other implementations of Ext.Direct for .Net listed on this forum have just the same problem (btw, they have very similar source code - a coincidence?). So maybe I'll try to modify your code to handle this case (rather a major refactor), or I'll roll something simple from scratch.
    Best regards
    R

  5. #35
    Sencha User
    Join Date
    Jan 2008
    Location
    Toronto, Canada
    Posts
    481
    Vote Rating
    4
    elishnevsky is on a distinguished road

      0  

    Default


    No problem. You see, to convert an object literal passed with Direct request to a real object on the server, Convert.ChangeType() can be used, but then the class must implement IConvertable interface. If you know an easier way to convert Object to another complex type, I'll be glad to hear about it and can try and implement it in my solution. Meanwhile I'll do some research myself.

  6. #36
    Ext JS Premium Member
    Join Date
    Nov 2008
    Location
    Warsaw area, Poland
    Posts
    64
    Vote Rating
    1
    nightwatch is on a distinguished road

      0  

    Default


    The main problem is that information is lost in deserialization of DirectRequest. If the data array contains Json objects, they are all deserialized as System.Object and all their fields are ignored. This is because Json serializer doesn't know their actual type - it assumes System.Object because DirectRequest.Data is an array of System.Object. If you gave the Json serializer information about actual types of objects in that array it would handle the deserialization correctly. Now this would require getting type information from method parameters before deserialization of Data array, or deserializing everything as Newtonsoft.Json.JObject and later converting it into actual parameter types. I'll do some thinking as well about how to do that.

  7. #37
    Ext JS Premium Member
    Join Date
    Nov 2008
    Location
    Warsaw area, Poland
    Posts
    64
    Vote Rating
    1
    nightwatch is on a distinguished road

      0  

    Default


    To illustrate what I'm talking about, I have made some modifications to your source code to allow the library to handle complex Json types. I don't think it's a good implementation and probably it breaks many things that were working before, but at least handles some of my cases.
    The modifications:
    - added converter attribute to DirectRequest.Data
    - implemented RequestDataConverter for custom deserialization of DirectRequest.Data
    - modified DirectMethodInvoker so it converts JObject to appropriate method argument type
    The implementation is dirty, my custom deserialization code probably will fail in many situations, but it correctly handles two of my test cases:
    DirectRPCController.Execute2 and DirectRPCController.Execute4 (see the post above for details).
    Hope you'll be able to incorporate this idea into your library (or prove it's wrong and offer something better)

    Best regards
    RG
    Attached Files

  8. #38
    Sencha User
    Join Date
    Jan 2008
    Location
    Toronto, Canada
    Posts
    481
    Vote Rating
    4
    elishnevsky is on a distinguished road

      0  

    Default


    Thanks, this looks pretty good to me! I followed your idea and added support for complex types. This will make it easier to pass simple DTOs around between server and client.

    Get the updated version from the first post.

    Please don't ask me to add support for even more complex types such as arrays or dictionaries, 'cause I'm not going to do it It's far more difficult and will result in a big hack for a little problem. Besides, this latest version with support for complex types should satisfy most of people's needs, if not all.

  9. #39
    Ext JS Premium Member
    Join Date
    Nov 2008
    Location
    Warsaw area, Poland
    Posts
    64
    Vote Rating
    1
    nightwatch is on a distinguished road

      0  

    Default


    Hi, I'm glad you liked it. BTW, dictionary support is already there - if the method parameter is a dictionary (not an IDictionary interface but dictionary class) the Json serializer will fill it with data from JObject. I'm not asking you to add array support, but you are small step away from it, besides it would be good for the sake of completeness. Maybe let's wait until someone needs it.

  10. #40
    Ext JS Premium Member
    Join Date
    Jul 2009
    Location
    Seattle, Washington USA
    Posts
    200
    Vote Rating
    0
    geewhizbang is on a distinguished road

      0  

    Default Read entire thread, downloaded code, done some work but still confused

    Read entire thread, downloaded code, done some work but still confused


    I have downloaded your project added the Ext.Direct.Mvc project to my Mvc Project.

    I have done all of the code changes in Web.Config, the project compiles fine, and my existing ExtJS methods work in the way that a previous MVC example I found elsewhere showed me how to do. This is better than my previous two attempts that I eventually abandoned.

    However, I can't tell from your project HOW you implement a method using the Ext.Direct, which I want to test to see if I like it.

    A big source of my confusion is that I don't understand where DirectRouter.ashx is supposed to exist, and what is the format of a method in that if it does exist somewhere?

    I have included my version of the project at box.net:

    http://www.box.net/shared/1h9o0ks0vo