1. #11
    Sencha User nayato's Avatar
    Join Date
    Mar 2008
    Posts
    15
    Vote Rating
    0
    nayato is on a distinguished road

      0  

    Default How about WCF?

    How about WCF?


    It's always great to see some .net action happening around ExtJS!

    Though I think using async handlers is a bit dated approach. Did you think of writing WCF service for that purpose? It could help a lot in writing server-side code in more focused, service oriented manner.
    It also has JSON support is built in and provides extended possibilities for easy exception handling.

  2. #12
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,908
    Vote Rating
    626
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    Not really, I'm a bit out of the loop as far as .NET is concerned. Could you point me to some relevant examples? FYI the built in JSON support in .NET I found was reasonably poor, which is why I ended up using JSON.NET.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  3. #13
    Ext JS Premium Member Lloyd K's Avatar
    Join Date
    Oct 2007
    Location
    Brighton, United Kingdom
    Posts
    655
    Vote Rating
    1
    Lloyd K is on a distinguished road

      0  

    Default


    WCF is far too heavy and overcomplicated which will put many off imho. Also I agree with Evan in that .NET's JSON support is poor and the Newtonsoft library is probably the best freely available.
    - Lloyd K

    I blog about code from time to time: http://codeology.lloydkinsella.net/

  4. #14
    Sencha User
    Join Date
    Dec 2008
    Location
    Mainz
    Posts
    241
    Vote Rating
    1
    crp_spaeth is on a distinguished road

      0  

    Default


    I agree with evant for using JSON.NET.

    This is much faster and better than the builtin json Support!

    If you had a look at my Implementation of a Direct Router you may have seen that its really easy to let JSON.Net try to deserialize the json data to fit into the defined method parameters. This may shows a small part of the power of JSON.NET

  5. #15
    Ext User
    Join Date
    May 2009
    Posts
    1
    Vote Rating
    0
    Revotion is on a distinguished road

      0  

    Default Feature Request

    Feature Request


    To Start with, I am more of a VB user, so please forgive the fact that this is not in C#. As a feature request, why not create a DirectHandler as an IHTTPHandler that can do all of the work for the user, while grouping related function into a single file (and not having to expose every method in an Application to all pages)

    Examples as follows.....


    The DirectHandler to be added to the DLL (notice that I wrapped the DirectHandler and ApiHandler into one file, and check for the existance of any data. If none found, we assume you are looking for the API Definition).

    Code:
    Imports Ext.Direct
    
    Public Class DirectHandler
        Implements IHttpHandler
    
        Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    
            Dim provider As DirectProvider = Nothing
            Dim cacheKey As String = GetType(Handler1).Name
            Dim cache = DirectProviderCache.GetInstance()
    
            If context.Request.TotalBytes = 0 AndAlso String.IsNullOrEmpty(context.Request("extAction")) Then
    
                context.Response.ContentType = "text/javascript"
    
                If cache.ContainsKey(cacheKey) Then
                    provider = cache(cacheKey)
                Else
                    provider = New DirectProvider("Ext.app." & cacheKey & "_API", context.Request.Path)
                    provider.Configure(New Object() {Me})
                    cache.Add(cacheKey, provider)
                End If
    
                context.Response.Write(provider.ToString())
    
            Else
    
                context.Response.ContentType = "text/javascript"
    
                provider = cache(cacheKey)
    
                context.Response.Write(DirectProcessor.Execute(provider, context.Request))
    
            End If
    
        End Sub
    
        ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
            Get
                Return False
            End Get
        End Property
    
    End Class

    The Handler file that I would add to my application (remember to add the file as a Genric Handler with the ashx extension) ....

    Code:
    Imports Ext.Direct
    
    <DirectAction()> _
    Public Class Handler1
        Inherits DirectHandler
    
        <DirectMethod()> _
        Public Function Echo(ByVal name As String) As String
            Return "Echo: " & name
        End Function
    
    End Class



    And Finally, the HTML code need to use this....

    Code:
        <script type="text/javascript" src="Handler1.ashx"></script>
        
        <script type="text/javascript">
    
            Ext.onReady(function() {
    
                Ext.Direct.addProvider(Ext.app.Handler1_API);
    
                Handler1.Echo("abc", function(result, response) { alert(result) })
    
                })
                    
                
        </script>

  6. #16
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,908
    Vote Rating
    626
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    Wicked suggestions, I've made these changes, as well as

    1) Exception handling
    2) Better date handling

    I'll update the original post.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  7. #17
    Sencha User
    Join Date
    Jul 2007
    Posts
    8
    Vote Rating
    0
    GodKnow is on a distinguished road

      0  

    Default Modify Directresponse.cs

    Modify Directresponse.cs


    Hello,

    The sample in "ext-direct-pack.zip" response:

    Code:
    {"type":"rpc","tid":2,"action":"Sample","method":"SaveForm","result":"{\"firstName\":\"4\",\"lastName\":\"4\",\"age\":4}"}
    The value of "result" is string.

    So I modify Directresponse.cs:
    Code:
    return  JsonConvert.SerializeObject (response);
    replace :
    Code:
                        if (response.Result.GetType().ToString() == "Newtonsoft.Json.Linq.JObject")
                        {
                            JObject o = new JObject(
                                new JProperty("type",response.Type),
                                new JProperty("tid",response.TransactionId),
                                new JProperty("action",response.Action),
                                new JProperty("method",response.Method),
                                new JProperty("result",(JObject)response.Result)
                            );
                            return o.ToString();
                        }
                        else
                        {
                            return JsonConvert.SerializeObject(response);
                        }
    The Sample.cs:
    Code:
            [DirectMethodForm]
            public string SaveForm(HttpRequest request)
            {
                int age = 0;
                int.TryParse(request["age"], out age);
                JObject o = new JObject(
                    new JProperty("firstName", request["firstName"]),
                    new JProperty("lastName", request["lastName"]),
                    new JProperty("age", age));
                return o.ToString(Newtonsoft.Json.Formatting.None);
            }
    replace:
    Code:
            [DirectMethodForm]
            public Object SaveForm(HttpRequest request)
            {
                int age = 0;
                int.TryParse(request["age"], out age);
                JObject o = new JObject(
                    new JProperty("firstName", request["firstName"]),
                    new JProperty("lastName", request["lastName"]),
                    new JProperty("age", age));
                return o;
            }
    response:
    Code:
    {
      "type": "rpc",
      "tid": 2,
      "action": "Sample",
      "method": "SaveForm",
      "result": {
        "firstName": "4",
        "lastName": "4",
        "age": 4
      }
    }
    Please tell me if you have any good idea.

  8. #18
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,908
    Vote Rating
    626
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    I've added something similar, now you can return JArray or JObjects from your methods and have them serialized. Updated the first post.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  9. #19
    Sencha User
    Join Date
    Jul 2007
    Posts
    8
    Vote Rating
    0
    GodKnow is on a distinguished road

      0  

    Default


    Sorry, I have a question:
    In the Router0.4,I need add a class,please tell me how to do that?

    thx.

    I am doing it like this now:
    In the defalut.aspx,add:
    Code:
    <script type="text/javascript" src="test.ashx"></script>

    test.ashx:
    Code:
    namespace ExtDirectSample
    {
        [DirectAction]
        public class test : DirectHandler
        {
    
            public override string ProviderName
            {
                get
                {
                    return "Ext.app.REMOTING_API_1";
                }
            }
    
            public override string Namespace
            {
                get
                {
                    return "MyApp_1";
                }
            }
    
            [DirectMethod]
            public string SayHello()
            {
                return "Hello!";
            }
    
        }
    }
    return:
    Code:
    Ext.app.REMOTING_API_1 = {"type":"remoting","url":"/control/ExtDirectSample2/ExtDirectSample/test.ashx"
    ,"namespace":"MyApp_1","actions":{"test":[{"name":"SayHello","len":0}]}};
    thx.

  10. #20
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,908
    Vote Rating
    626
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    What are you trying to do? Sorry I don't understand.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!