Now that you see how to make a basic web service and how to test it, let's take it a step further and bring the data into Flash.
We will begin working with the XML object to bring the data in, and finally move over to using the WebServiceConnector component.
Using the XML Object
We went over the basics of the XML object back in Chapter 24, "XML and Flash." Now we are going to use it to consume the web service that we have created.
To absorb a web service with the XML object, when you load it in, use the path to the web service, followed by a slash, and then the name of the web method being called, like this:
And after it is loaded, you will have to parse the data as an XML document.
This example uses the web service we have already created to bring in the phrase "hello world" and put it in a dynamic text field on the stage.
The preceding code first creates an XML object to absorb the web service. It then sets the ignoreWhite property to true. After that, it creates the event callback for the XML object, so that when it receives data back, it will send the result to the text field. Finally, it loads the web method.
Test the movie and you will see that the phrase "hello world" has appeared in the text field.
If you are running certain versions of the .NET framework, the preceding code may not work correctly by default. If this is the case, add this to the web.config file located on c:\:
<webServices> <protocols> <add name="HttpGet"/> </protocols> </webServices>
Add the preceding code before the </system.web> closing tag, and then restart your computer.
That example demonstrated how to absorb a web service with the XML object, but there is a much better way to do it using Flash Remoting.