Today I feel like doing some flex apps and .NET webservice. Surprisingly, when I was trying to find an example of calling .NET webservice from flex, most of the example is either for flex 1.5 or not present at all. So I decided to post it here, and hoping that google engine will crawl my blog and spread this code to whoever needs it.
The Flex' mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Panel width="346" height="87" layout="absolute" title="Calling .NET Web Service from Flex Application" backgroundColor="#000000" horizontalAlign="center" verticalAlign="top">
<mx:Button x="89.5" y="15" label="Call .Net Web Service" click="{WebService.HelloNet.send()}" color="#ffffff"/>
</mx:Panel>
<mx:WebService id="WebService" wsdl="http://localhost:4364/FlexService/Service.asmx?WSDL" showBusyCursor="true" result="showResult(event.result)">
<mx:operation name="HelloNet">
</mx:operation>
</mx:WebService>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
function showResult(result):void
{
Alert.show(result);
}
]]>
</mx:Script>
</mx:Application>
The .NET Web Service:
[WebMethod]
public string HelloNet() {
return "Hello Flex, this is now: " + DateTime.Now.ToString(); ;
}
Reference:
Happy coding!!!
October 2006 November 2006 December 2006 June 2007 February 2008
Subscribe to Posts [Atom]