-
18 May 2009 6:54 PM #11
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.
-
18 May 2009 7:13 PM #12
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!
-
19 May 2009 1:14 AM #13
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.
-
19 May 2009 2:15 AM #14
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
-
4 Jun 2009 11:07 AM #15
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>
-
4 Jun 2009 12:33 PM #16
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!
-
14 Jun 2009 11:27 PM #17
Modify Directresponse.cs
Modify Directresponse.cs
Hello,
The sample in "ext-direct-pack.zip" response:
The value of "result" is string.Code:{"type":"rpc","tid":2,"action":"Sample","method":"SaveForm","result":"{\"firstName\":\"4\",\"lastName\":\"4\",\"age\":4}"}
So I modify Directresponse.cs:
replace :Code:return JsonConvert.SerializeObject (response);
The Sample.cs: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); }
replace: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); }
response: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; }
Please tell me if you have any good idea.Code:{ "type": "rpc", "tid": 2, "action": "Sample", "method": "SaveForm", "result": { "firstName": "4", "lastName": "4", "age": 4 } }
-
15 Jun 2009 2:17 AM #18
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!
-
17 Jun 2009 6:10 AM #19
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:
return: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!"; } } }
thx.Code:Ext.app.REMOTING_API_1 = {"type":"remoting","url":"/control/ExtDirectSample2/ExtDirectSample/test.ashx" ,"namespace":"MyApp_1","actions":{"test":[{"name":"SayHello","len":0}]}};
-
17 Jun 2009 2:25 PM #20
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!


Reply With Quote