Flex与C#的一般处理程序(ashx)通信 一般处理程序应用线程
分类:Flash_Flex_AIR| 发布:camnprbubuol| 查看: | 发表时间:2012/4/23
Flex代码:
C#代码:
- <%@ WebHandler Language="C#" Class="HandlerFlex" %>
-
- using System;
- using System.Web;
- using System.Net;
- using System.Text;
- using System.Threading;
-
- public class HandlerFlex : IHttpHandler {
-
- private HttpContext con;
-
- public void ProcessRequest (HttpContext context) {
- context.Response.ContentType = "text/plain";
-
- con = context;
- this.Start();
- }
-
- public void Start()
- {
- Thread t = new Thread(new ThreadStart(ListenRequest));
- t.Start();
- }
-
- private void ListenRequest()
- {
- HttpResponse response = con.Response;
- string msg = this.getJsonData();
-
- con.Response.Write(msg);
- }
-
- private string getJsonData()
- {
- StringBuilder jsonData = new StringBuilder();
- jsonData.Append("{\"data\":[{\"name\":\"谢刚\",\"sex\":\"男\",\"age\":\"21\",\"email\":\"xiegangthrille@126.com\"}]}");
-
- return jsonData.ToString();
- }
-
- public void RespClient(HttpListenerResponse response, string msg)
- {
- try
- {
- byte[] buffer = Encoding.UTF8.GetBytes(msg);
- response.ContentType = @"text/xml";
- response.ContentLength64 = buffer.Length;
- System.IO.Stream output = response.OutputStream;
- output.Write(buffer, 0, buffer.Length);
- output.Close();
- }
- catch (Exception e)
- {
-
- }
- }
-
- public bool IsReusable {
- get {
- return false;
- }
- }
-
- }
flex工程需要用到的库:https://github.com/mikechambers/as3corelib
来源:http://xiegangthrille.iteye.com/blog/431339