There are many methods for flex to access WebService, using"Data/service"The function can automatically generate a proxy class to access WebService. This prevents all data access from being written to the MXML page for reuse. At the same time, you can directly import custom data types to the background, this facilitates parameter passing.
Directly run the code: the WebService Interface
Namespace MyNetWebService {// <summary> // summary of MyWebService /// </summary> [WebService (Namespace = "http://tempuriTemp.org/")] [WebServiceBinding (ConformsTo = WsiProfiles. basicProfile1_1)] [System. componentModel. toolboxItem (false)] // to allow ASP. net ajax calls this Web service from the script. Please cancel the comments to the downstream. // [System. web. script. services. scriptService] public class MyWebService: System. web. services. webService {[WebMethod] public string HelloWorld () {return "Hello World";} [WebMethod] public Model [] GetDetailResult (SearchParameter parmeter, Staff staff) {return ModelHelp. getSaleDetailResult (parmeter, staff );}}}
Add a WebService:
Connection data/service-> Web Service-> wsdl url: Enter the service address (http: // localhost/XXX/MyWebService. asmx? WSDL)
Use"Data/service"Proxy class generated by the function under services:
Imported webService methods and custom types under data/service
Automatically generate a proxy class _ Super_MyWebService.as to access WebService
_serviceControl = operations:Object = = mx.rpc.soap.mxml.Operation(, =] == mx.rpc.soap.mxml.Operation(, =] ==== = = _internal_operation:mx.rpc.AbstractOperation = _serviceControl.getOperation( _internal_token:mx.rpc.AsyncToken = _internal_operation:mx.rpc.AbstractOperation = _serviceControl.getOperation( _internal_token:mx.rpc.AsyncToken =
Flex terminal Temp. mxml
<? Xml version = encoding =?> <Mx: Module xmlns: fx === width = height ==> <fx: Script> <! Function btn_call_clickHandler (: MouseEvent): getresult. token = function getresult_resultHandler (: ResultEvent): (. result! ==. Result> </fx: Script> <! -- Reference css styles --> <fx: Style source =/> <fx: Declarations> <! -- Place non-visual elements (such as services and value objects) Here --> <mywebservice: MyWebService id = showBusyCursor = fault =/> <s: callResponder id = result =/> </fx: Declarations> <s: VGroup width = height = paddingLeft = paddingRight = paddingBottom = paddingTop => <s: HGroup width = verticalAlign => <mx: Text id =/> <common: Cbutton id = label = click =/> </s: HGroup> <s: HGroup width = verticalAlign => <s: Label verticalAlign = styleName = width = id =/> </s: HGroup> </s: VGroup> </mx: Module>
Running result: