MieJowo.NET

Web Programming, SEO, and Anything On The Web.  

Calling .NET Web Service from Flex 2.0 Apps

Friday, November 03, 2006

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:

  1. http://livedocs.macromedia.com/flex/2/langref/mx/rpc/soap/mxml/WebService.html
  2. http://www-128.ibm.com/developerworks/webservices/library/ws-macroflex/

Happy coding!!!


Comments:
I'm standard, have just used DotNetNuke.

 
DNN? eh?

 
Post a Comment

Subscribe to Post Comments [Atom]





<< Home

Archives

October 2006   November 2006   December 2006   June 2007   February 2008  

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]