Feeds

Consume .NET services without Silverlight

Adobe Flex comes through

Securing Web Applications Made Simple and Scalable

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.

Bridging the IT gap between rising business demands and ageing tools

More from The Register

next story
NO MORE ALL CAPS and other pleasures of Visual Studio 14
Unpicking a packed preview that breaks down ASP.NET
Cheer up, Nokia fans. It can start making mobes again in 18 months
The real winner of the Nokia sale is *drumroll* ... Nokia
DARPA-derived secure microkernel goes open source tomorrow
Hacker-repelling, drone-protecting code will soon be yours to tweak as you see fit
Put down that Oracle database patch: It could cost $23,000 per CPU
On-by-default INMEMORY tech a boon for developers ... as long as they can afford it
Google shows off new Chrome OS look
Athena springs full-grown from Chromium project's head
Apple: We'll unleash OS X Yosemite beta on the MASSES on 24 July
Starting today, regular fanbois will be guinea pigs, it tells Reg
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
prev story

Whitepapers

Designing a Defense for Mobile Applications
Learn about the various considerations for defending mobile applications - from the application architecture itself to the myriad testing technologies.
Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Top 8 considerations to enable and simplify mobility
In this whitepaper learn how to successfully add mobile capabilities simply and cost effectively.
Seven Steps to Software Security
Seven practical steps you can begin to take today to secure your applications and prevent the damages a successful cyber-attack can cause.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.