(1) Use get to interact with text data. Asp.net on the server is in HTML format, and resultformat is in text format.
Flex code:
<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml"
Layout = "absolute"
Backgroundcolor = "# ffffff"
Backgroundalpha = "0">
<Mx: SCRIPT>
<! [CDATA [
Import MX. rpc. Events. resultevent;
Import MX. rpc. Events. faultevent;
Import MX. Controls. Alert;
Public Function handleplain (Event: resultevent): void
{
Shippingoptions. Text = event. Result. tostring ();
}
Public Function handlefault (Event: faultevent): void
{
Alert. Show (event. fault. faultstring, "error ");
}
]>
</MX: SCRIPT>
<Mx: httpservice id = "plainrpc"
Url = "http://aspexamples.adobe.com/flex3/exchangingdata/PlainHttpService.aspx"
Result = "handleplain (event )"
Fault = "handlefault (event )"
Resultformat = "text" method = "get">
<Mx: Request>
<Zipcode> {zipcode. Text} </zipcode>
<Pounds> {weight_lb.text} </pounds>
</MX: Request>
</MX: httpservice>
<Mx: Label x = "56" Y = "32"
TEXT = "zip code"
Width = "55" Height = "18"
Textalign = "right"
Fontweight = "bold"/>
<Mx: Label x = "56" Y = "58"
TEXT = "weight"
Width = "55" Height = "18"
Textalign = "right"
Fontweight = "bold"/>
<Mx: textinput id = "zipcode"
X= "130" Y = "32"
Width = "160" Height = "22"/>
<Mx: textinput id = "weight_lb"
X= "130" Y = "58"
Width = "160" Height = "22"/>
& Lt; mx: button x = "130" Y = "95"
Label = "Get Shipping Options"
Click = "plainrpc. Send ()"
Width = "160" Height = "22"/>
<Mx: Text id = "shippingoptions"
X = "56" Y = "150"
Width = "310" Height = "133"
Fontweight = "bold"/>
</MX: Application>
C # code:
<% @ Import namespace = "Quickstart" %>
<Script language = "C #" runat = "server">
Public void page_load (Object sender, eventargs E)
{
Int zipcode;
Double weight;
If (request. requesttype = "Post ")
{
Zipcode = int32.parse (request. Form ["zipcode"]. tostring ());
Weight = double. parse (request. Form ["pounds"]. tostring ());
}
Else
{
Zipcode = int32.parse (request. querystring ["zipcode"]. tostring ());
Weight = double. parse (request. querystring ["pounds"]. tostring ());
}
Shippingcalculator = new shippingcalculator ();
Shippingoption = new shippingoption ();
Arraylist Al = shippingcalculator. getshippingoptions (zipcode, weight );
Stringbuilder ;;
Foreach (Object OBJ in Al)
{
Stringbuilder = new stringbuilder ();
Shippingoption = (shippingoption) OBJ;
Stringbuilder. append (shippingoption. getservice ());
Stringbuilder. append (":");
Stringbuilder. append (shippingoption. getprice ());
Stringbuilder. append ("USD" + "/N ");
Response. Write (stringbuilder. tostring ());
}
}
</SCRIPT>
(2) Use post to interact with XML data. Asp.net on the server is in XML format, and resultformat is in E4X format,
Flex code:
<? XML version = "1.0" encoding = "UTF-8"?>
<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml"
Layout = "absolute"
Backgroundcolor = "# ffffff"
Backgroundalpha = "1">
<Mx: SCRIPT>
<! [CDATA [
Import MX. rpc. Events. resultevent;
Import MX. rpc. Events. faultevent;
Import MX. Controls. Alert;
Public Function handlexml (Event: resultevent): void
{
Shippingoptionsgrid. dataprovider = event. Result. option;
}
Public Function handlefault (Event: faultevent): void
{
Alert. Show (event. fault. faultstring, "error ");
}
]>
</MX: SCRIPT>
<Mx: httpservice id = "XMLRPC"
Url = "http://aspexamples.adobe.com/flex3/exchangingdata/xmlHttpService.aspx"
Result = "handlexml (event )"
Fault = "handlefault (event )"
Resultformat = "E4X" method = "Post">
<Mx: Request>
<Zipcode> {zipcode. Text} </zipcode>
<Pounds> {weight_lb.text} </pounds>
</MX: Request>
</MX: httpservice>
<Mx: Label x = "56" Y = "32"
TEXT = "zip code"
Width = "55" Height = "18"
Textalign = "right"
Fontweight = "bold"/>
<Mx: Label x = "56" Y = "58"
TEXT = "weight"
Width = "55" Height = "18"
Textalign = "right"
Fontweight = "bold"/>
<Mx: textinput id = "zipcode"
X= "130" Y = "32"
Width = "160" Height = "22"/>
<Mx: textinput id = "weight_lb"
X= "130" Y = "58"
Width = "160" Height = "22"/>
& Lt; mx: button x = "130" Y = "95"
Label = "Get Shipping Options"
Click = "XMLRPC. Send ()"
Width = "160" Height = "22"/>
<Mx: DataGrid id = "shippingoptionsgrid"
X = "80" Y = "141"
Width = "262" Height = "92"
Editable = "false"
Enabled = "true">
<Mx: columns>
<Mx: datagridcolumn headertext = "service" datafield = "service"/>
<Mx: datagridcolumn headertext = "price" datafield = "price"/>
</MX: columns>
</MX: DataGrid>
</MX: Application>
Asp.net code:
<% @ Import namespace = "Quickstart" %>
<Script language = "C #" runat = "server" contenttype = "text/XML">
Public String STR = "";
Public void page_load (Object sender, eventargs E)
{
Int zipcode;
Double weight;
If (request. requesttype = "Post ")
{
Zipcode = int32.parse (request. Form ["zipcode"]. tostring ());
Weight = double. parse (request. Form ["pounds"]. tostring ());
}
Else
{
Zipcode = int32.parse (request. querystring ["zipcode"]. tostring ());
Weight = double. parse (request. querystring ["pounds"]. tostring ());
}
Shippingcalculator = new shippingcalculator ();
Shippingoption = new shippingoption ();
Arraylist Al = shippingcalculator. getshippingoptions (zipcode, weight );
Stringbuilder = new stringbuilder ("<Options> ");
Foreach (Object OBJ in Al)
{
Shippingoption = (shippingoption) OBJ;
Stringbuilder. append ("<option> <service> ");
Stringbuilder. append (shippingoption. getservice ());
Stringbuilder. append ("</service> <price> ");
Stringbuilder. append (shippingoption. getprice ());
Stringbuilder. append ("</price> </option> ");
}
Stringbuilder. append ("</Options> ");
STR = stringbuilder. tostring ();
}
</SCRIPT>
<? XML version = "1.0" encoding = "UTF-8"?>
<%
Response. contentencoding = encoding. utf8;
Response. Write (STR );
%>