Danh mục

Using the WebServiceConnector Component

Số trang: 11      Loại file: pdf      Dung lượng: 39.72 KB      Lượt xem: 9      Lượt tải: 0    
Jamona

Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Sử dụng phần WebServiceConnector Thông qua việc sử dụng các thành phần WebServiceConnector, một bộ phim Flash có thể kết nối với một dịch vụ web và tải thông tin từ nó. Một dịch vụ Web là một ứng dụng phía máy chủ chấp nhận dữ liệu, thực hiện một dịch vụ trên cơ sở đó, dữ liệu và trả về kết quả. Ví dụ, một dịch vụ Web có thể cho phép bạn để nuôi nó một mã zip và, như một kết quả, trở về thời tiết trong khu vực quy định. Một dịch vụ Web có...
Nội dung trích xuất từ tài liệu:
Using the WebServiceConnector Component < Day Day Up >Using the WebServiceConnector ComponentThrough the use of the WebServiceConnector component, a Flash movie can connect to aWeb service and load information from it. A Web service is a server-side application thataccepts data, performs a service based on that data, and returns a result. For instance, aWeb service might allow you to feed it a zip code and, as a result, return the weather inthe specified area. Another Web service could find all the spelling mistakes in a string oftext fed to it, correct the spelling errors, and return the modified text.To send data to a Web service, the data must be formatted in XML. More precisely, theXML must meet the SOAP (Simple Object Access Protocol) standard. Fortunately, youdont need to learn this standard. The WebServiceConnector component handles theprocess of converting data to XML (the data you send to the Web service) in theappropriate format, sending it to the Web service as well as receiving and parsing theresponse. This means that you can communicate with Web services without having toworry about formatting the request properly or figuring out how to interpret the returnedXML. The WebServiceConnector component handles everything.The WebServiceConnector component has five parameters: • WSDLURL. This parameter is the URL for the file that defines the Web service operation. When this parameter is entered, the Flash authoring environment automatically attempts to load the destination file. This allows the authoring environment to display information related to the Web service in the Schema tab of the Component Inspector, which will be discussed later in this lesson. • operation. After the file located at WSDLURL is loaded, the operation parameter allows you to select from a drop-down list the operation that you want to execute. Many Web services provide only one operation, such as getPrice, whereas other Web services may provide several types of operations, such as SendICQmessage, SendMSNmessage, and SendAIMmessage. • multipleSimultaneousAllowed. This is a drop-down list in which you can choose true or false. The default value is true. If true is selected, the component makes Web requests to the Web service whenever it is asked to do so, even if it hasnt received a response from a previous request. If false, it wont make any more requests until a response to the current request has been received. • suppressInvalidCalls. You can select either true or false from a drop-down list for this parameter. The WSDL file loaded via the WSDLURL parameter specifies what type of data is required to process the request. If suppressInvalidCalls is set to true and your Web services request doesnt contain the specified type of data, the request is not sent. If suppressInvalidCalls is set to false, the request is sent, no matter what type of data is entered. • timeout. This parameter is optional. It expects either nothing or a number. If a number is entered, the WebServiceConnector component cancels the request for the service if a response is not received before the number of seconds in the timeout parameter is reached.As mentioned a moment ago, the Schema tab of the Component Inspector is dynamicallypopulated based on the file at the WSDLURL property and the value of the operationproperty. It defines what information you should send and what information you shouldexpect as a result. For example, there is a Web service that will give you the physicaldistance between two zip codes. If you enter its WSDLURL into the component andselect the getDistance operation, the Schema table updates to show the following image:There are two main areas in the schema: params and results. The params propertycontains the variables that you should send with the Web service request, which in thiscase consist of two zip codes. The results property is usually just a string.You use the params property on the Schema tab to learn what information you shouldsend to the Web service. You then create an array in the component instance calledparams and assign it values in the order in which they appeared in the params property onthe Schema tab. For example, if we gave the WebServiceConnector component aninstance name of zip_ws, we would add the params array like this:zip_ws.params = [27609, 90210];The first zip code in the array corresponds to the first property in the Schema, fromZip.The second one corresponds to the second property in the Schema, toZip.To get the component instance to perform the service request, you must invoke thetrigger() method. For example:zip_ws.trigger();The trigger() method tells the component to take the params property, format a request,send the request, and wait for a response. The response fires an event called the resultsevent. You must add a Listener to capture that event. For example:function distanceReceived (ev:Object) { var distance:String = ev.target.results;}zip_ws.addEventListener(result, distanceReceived);This code adds a Listener to the zip_ws WebServiceConnector component and calls thedistanceReceived function when the results event is fired.TIPhttp://www.xmethods.com contains an extensive listing of Web services you can use inyour applications.In the following exercise, you will get a chance to use everything introduced in thissection. You will use a language translation Web service to create an application thatenables you to translate English into a number of other languages.NOTEThe WebServiceConnector component uses XML.sendAndLoad to communicate withthe Web service; therefore, it is subject to the same security restrictions found whenloading data onto ...

Tài liệu được xem nhiều: