Feeds

Consume .NET services without Silverlight

Adobe Flex comes through

The Power of One eBook: Top reasons to choose HP BladeSystem

Web bling tone Can Adobe Systems' Flex access Microsoft .NET web services? Adobe tends to promote its own ColdFusion or LiveCycle Data Services for use with Flex, but it also has support for SOAP 1.1.

When Microsoft released Silverlight 2 second beta last month, I tested it by building a simple Create, Retrieve, Update, Delete (CRUD) database application, following all the defaults: SQL Server, ASP.NET, Windows Communication Foundation (WCF) web service, and of course Visual Studio 2008 to bring it all together. It wasn't entirely painless, but the problems were largely in getting Microsoft's beta tools to install correctly; in the end it worked well.

I could not resist trying Flex with the same web service. Since I had used the BasicHttpBinding for the WCF service, it should be compatible. How easy would it be? It is a key point for developers on Microsoft's platform who may be eyeing Flex or AIR with interest.

I installed my web service into IIS 7.0 and tested it. It is a simple affair, designed to be the back end for a rudimentary guestbook. There is a GuestItem class, which represents an entry in the book, and a web service with three methods: GetGuestEntries, SaveGuestItem and DeleteGuestItem. I fired up FlexBuilder, created a new Flex web application project, and added a DataGrid and a few other controls that I hoped to populate with my data. Then I chose Import Web Service from the Data menu.

Import WSDL screen grab

Microsoft's web service is sucked into FlexBuilder

FlexBuilder proceeded to generate nearly forty ActionScript files in order to wrap the service. Still, I was in luck: the import worked. Adobe is actually using a modified version of the excellent Apache Axis2, which is encouraging.

The next question was how to talk to the service. I opened GuestBook.as, and was delighted to find comments with code samples, even though they were not quite complete. The basic pattern is this:

1. Create an instance of the web service wrapper class

2. Add a listener that corresponds to the method you will call. The web service is called asynchronously, and the function you supply for the listener will be called when the result is received

3. Add a listener for SOAP faults. This is a kind of exception handler

4. Call the service method

Fortunately these steps only take a few lines of code. Here is the listener function, which binds the list of entries to the DataGrid:


  public function getGuestItemsResult(e:GetGuestItemsResultEvent):void {
        grdGuestBook.dataProvider = e.result;
  }

Here is the code which calls the web service:


   public function refreshGuestList():void {
   var guestService:GuestBook= new GuestBook();
   guestService.addgetGuestItemsEventListener(getGuestItemsResult);
   guestService.addGuestBookFaultEventListener(getFaultResult);
   guestService.getGuestItems();        
   }


Incidentally, the C# method that implements the service looks like this:


[OperationContract]
public List<GuestItem> GetGuestItems()

The ActionScript wrapper represents this as a custom class, ArrayOfGuestItem, which extends ArrayCollection, and this binds nicely to a DataGrid. I just needed to set the dataField attribute of each column in the grid to match the properties of a GuestItem.

HP ProLiant Gen8: Integrated lifecycle automation

More from The Register

next story
Chrome browser has been DRAINING PC batteries for YEARS
Google is only now fixing ancient, energy-sapping bug
HIDDEN packet sniffer spy tech in MILLIONS of iPhones, iPads – expert
Don't panic though – Apple's backdoor is not wide open to all, guru tells us
Do YOU work at Microsoft? Um. Are you SURE about that?
Nokia and marketing types first to get the bullet, says report
Microsoft takes on Chromebook with low-cost Windows laptops
Redmond's chief salesman: We're taking 'hard' decisions
Cheer up, Nokia fans. It can start making mobes again in 18 months
The real winner of the Nokia sale is *drumroll* ... Nokia
EU dons gloves, pokes Google's deals with Android mobe makers
El Reg cops a squint at investigatory letters
Big Blue Apple: IBM to sell iPads, iPhones to enterprises
iOS/2 gear loaded with apps for big biz ... uh oh BlackBerry
prev story

Whitepapers

Reducing security risks from open source software
Follow a few strategies and your organization can gain the full benefits of open source and the cloud without compromising the security of your applications.
Consolidation: The Foundation for IT Business Transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.
Application security programs and practises
Follow a few strategies and your organization can gain the full benefits of open source and the cloud without compromising the security of your applications.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.
Consolidation: the foundation for IT and business transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.