Invoke a ASP.NET WebService from Flex
Here, I used a basic WebService created with ASP.NET. Below is a basic hello world functionality we get when creating a new WebService with Visual Studio.
using System.Web.Services; [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Service : System.Web.Services.WebService { public Service () { } [WebMethod] public string HelloWorld() { return "Hello World - This is Praveen"; } }
Below is the basic mxml code which will show you text from WebService:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; private function result(event:ResultEvent):void { Alert.show(event.result.toString()); } private function fault(event:FaultEvent):void { Alert.show(event.toString()); } private function invokemethod(event:MouseEvent):void { ws.HelloWorld(); } ]]> </mx:Script> <mx:WebService id="ws" wsdl="http://localhost/FlexWSTest/Service.asmx?WSDL"> <mx:operation name="HelloWorld" resultFormat="object" result="result(event)" fault="fault(event)" /> </mx:WebService> <mx:Button x="236" y="177" label="Button" click="invokemethod(event)" /> </mx:Application>
No related posts.
Pingback: Twitted by sknutti