One of the dynamic interactions between flex httpservice and ASP. NET

Source: Internet
Author: User

Currently, Ria technology is popular on the Internet. Adobe has flex and Microsoft has silver. Now it can be said that there is a benefit, but as the most popular flash on the internet, I think its support rate is obvious to all. Although yinguang is good, but it also requires a maturity in Year 12.

I used to search for flex articles on cnblogs and found few articles. I remember that most of them were implemented using WebService or WCF, there are few methods to implement httpservice. Maybe you would like to use webserivce.

First, I will introduce what is httpservice and the HTTP service communication method in flex. To put it bluntly, we use the get and post methods for data transmission, which is no different from the form submission method we usually use. The httpservice object is located in MX. RPC. it is mainly used to send http get or POST requests. I will not talk about the difference between post and get. I think most of them are clear. The biggest advantage of this method is its high versatility, whether it is Php, ASP, JSP, or my favorite ASP.. Net can process and return data submitted by Flex.

In the flex program, it is very convenient to use the httpservice object. The format is as follows:

<Mx: httpservice id = "userregform" url = "useradd. aspx" method = "GET | Post">

The above is the simplest way to write data. Another method is to write data in XML. For more information, see the following:

   1:      <mx:HTTPService showBusyCursor="true"
   2:                      id="getuser" result=""
   3:                      url="http://localhost:6666/Default.aspx">
   4:          <mx:request>
   5:              <username>
   6:   
   7:              </username>
   8:              <userpassword>
   9:   
  10:              </userpassword>
  11:          </mx:request>
  12:      </mx:HTTPService>
Many Attributes may not be very clear here. I will explain them one by one:
The showbusycursor attribute indicates whether a request is busy when it is submitted.
ID is the identifier of the httpservice request.
Result refers to the callback method after a request. After sending a request, you must obtain a result.
The URL is the sent address.
<Mx: Request> mainly sends some request parameters, which can be understood as well.
With these foundations, we can write the simplest flex interaction program. First, we can create a flex interface. The style of the interface is as follows:
 
Specific Code:
   1:  <?xml version="1.0" encoding="utf-8"?>
   2:  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 
width="320" height="219">
   3:      <mx:HTTPService showBusyCursor="true"
   4:       id="getuser" result="getuserproc();"
   5:        url="http://localhost:6666/Default.aspx">
   6:          <mx:request>
   7:              <username>
   8:                  {this.txtUserName.text}
   9:              </username>
  10:              <userpassword>
  11:                  {this.txtUserPassWord.text}
  12:              </userpassword>
  13:          </mx:request>
  14:      </mx:HTTPService>
  15:      <mx:Script>
  16:          <![CDATA[
  17:          import mx.controls.Alert;
  18:          
  19:              public function getuserproc():void
  20:              {
  21:                  var returnValue:String=getuser.lastResult.Result.chu888;
  22:                  if(returnValue=="ok")
  23:                  {
24: Alert. Show ("You have successfully logged on", "prompt message", alert. OK, this, null, null, alert. Yes );
  25:                  }
  26:                  else
  27:                  {
28: Alert. Show ("Your Logon Failed", "prompt message", alert. OK, this, null, null, alert. Yes );
  29:                  }
  30:              }
  31:          ]]>
  32:      </mx:Script>
  33:      <mx:Panel id="UserRegPanel" x="9.15" y="9.05" width="302" 
  34:                height="204" layout="absolute">
35: <mx: Label x = "10" Y = "22" text = "username:" id = "lblusername"
  36:                    enabled="true" fontSize="15"/>
37: <mx: Label x = "10" Y = "64" text = "Password:" id = "lbluserpassword"
  38:                    enabled="true" fontSize="15"/>
  39:          <mx:TextInput x="83" y="22" fontSize="15" id="txtUserName"/>
  40:          <mx:TextInput x="83" y="63" fontSize="15" id="txtUserPassWord"/>
41: <mx: button x = "96.45" Y = "108" label = "login" width = "89" Height = "36"
  42:                     fontSize="15" enabled="true" click="getuser.send()">
  43:              <mx:icon>@Embed(source='../libs/001_54.png')</mx:icon>
  44:          </mx:Button>
  45:      
  46:      </mx:Panel>
  47:  </mx:Application>
Process processing:
 
Next, we will create a default. aspx page. The page content is very simple and the code is as follows:
   1:  namespace WebApplication4
   2:  {
   3:      public partial class _Default : System.Web.UI.Page
   4:      {
   5:          protected void Page_Load(object sender, EventArgs e)
   6:          {
   7:              if (Request.QueryString["username"].Equals("chu888"))
   8:              {
   9:                  Response.Write("<Result>");
  10:                  Response.Write("<chu888>ok</chu888>");
  11:                  Response.Write("</Result>");
  12:              }
  13:              else
  14:              {
  15:                  Response.Write("<Result>");
  16:                  Response.Write("<chu888>error</chu888>");
  17:                  Response.Write("</Result>");
  18:              }
  19:          }
  20:      }
  21:  }
Next, you can release the flex content and append it to the ASP. NET program. Here, we need to note that every time the ASP. NET File Server generates
The port is different. You need to fix the port, or your program will not be able to find the program.
 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.