Using vs2008 + flash Builder 4
1. Use vs to create a website and add a web service.
File: WebService. asmx
Using system; using system. collections. generic; using system. LINQ; using system. web; using system. web. services; //< summary> // Summary of WebService /// </Summary> [WebService (namespace = "http://tempuri.org/")] [webservicebinding (conformsto = wsiprofiles. basicprofile1_1)] // to allow ASP.. Net Ajax calls this web service from a script. uncomment the following lines. // [System. web. script. services. scriptservice] public class WebService: system. web. services. webService {public WebService () {// If the designed component is used, uncomment the following line // initializecomponent ();} [webmethod] Public String helloworld () {return "Hello World ";}}
Set WebService. asmx as the start page and click Start. Http: // localhost: 52000/WebService. asmx
See
The following operations are supported. For formal definitions, see service description.
Indicates that the Web Service is successfully started.
2. Flash Project
After adding a project, add a button to add a click event
Modify the <FX: declarations> node
<FX: declarations>
<! -- Place non-visual elements (such as services and value objects) Here -->
<Mx: WebService id = "dataservice" WSDL = "http: // localhost: 52000/WebService. asmx? WSDL "useproxy =" false ">
<Mx: Operation name = "helloworld" result = "onsuccess (event)" fault = "onfault (event)"/>
</MX: WebService>
</FX: declarations>
Add three functions,
(Protected function button#clickhandler (Event: mouseevent): void is generated when you click an event)
Internal function onsuccess (EVT: resultevent): void {trace (EVT. result. tostring ();} internal function onfault (EVT: faultevent): void {trace ("failed to access WebService! ");} Protected function button#clickhandler (Event: mouseevent): void {trace (" click "); dataservice. helloworld ();}
Click the button to view the flash builder console.
Click
Hello World
At this point, the Web Service is successfully called.