因Flex使用Web Service有很多種方法,打算全部整理起來~~
第一步 要知道Web Service在哪? wsdl在哪?
以下是使用VS建立一個簡單的Web Service
namespace WebServices { [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] public class Service1 : System.Web.Services.WebService { [WebMethod] public string HelloWorld(String echo) { return echo; } } } |
該Service Name為 Service1
有一個operation 叫做 HelloWorld 參數是字串 echo
該service的wsdl假設在http://localhost:3722/Service1.asmx?wsdl
到此已經有充足的資訊,以下顯示如何使用Flex Builder 3 產生Service proxy!
以下簡介一下,所產生的元件的意義,暫時沒空翻譯,大家先看看吧!
Generated file | Description |
---|---|
BaseServiceName.as | A base implementation of the web service. This class contains the internal code that maps the operations from the WSDL file to Flex WSDLOperation instances and sets the corresponding parameters. |
IServicename.as | The service interface that defines all of the methods that users can access. |
Servicename.as | The concrete web service implementation. |
BaseServicenameSchema.as | A file containing the XSD schema of the web service as an ActionScript custom type. |
OperationnameResultEvent.as | For each web service operation, Flex Builder generates a strongly typed event type class. You can use these classes to benefit from strongly typed results. |
Operationname_request.as | For each web service operation that passes parameters to the server operation, Flex Builder generates a request wrapper class with the parameters as members. The request object is intended for use with the MXML tag syntax. |
Type.as | For each complex type defined in the WSDL file, Flex Builder generates a class with the same name as the complex type or with the same name as the enclosing element. |
以下的範例是單純使用Flex Tag來呼叫~~
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:myws="generated.webservices.*"> <myws:Service1 id="myservices"> <myws:helloWorld_request_var> <myws:HelloWorld_request> <myws:echo> Hubert </myws:echo> </myws:HelloWorld_request> </myws:helloWorld_request_var> </myws:Service1> <mx:Button x="127" y="271" label="Get Data" id="btn_GetData" click="{myservices.helloWorld_send();}"/> <mx:TextArea x="127" y="85" width="274" height="149" id="lb_data" text="{myservices.helloWorld_lastResult}"/> </mx:Application> |
下一篇我們將使用ActionScript來使用~~