My RMAUG ( http://www.rmaug.com/ ) presentation comparing web services done the Adobe way and the Microsoft way. Compared technologies : Coldfusion9 with Hibernate vs ASP.NET with nHibernate. There are some code screenshots along with coding tips for both stacks.
NOTE : Jun Heider and I will giving an in depth comparison of the Adobe and Microsoft stacks at 360|Flex 2010 in San Jose. This talk will be more of an apples to apples since both sides will handle remoting, as well as the latest and greatest ORM and techniques that apply to each side. This preso does not talk about MS Remoting, or MS' Linq to SQL ORM functionality.
On the internet, end users don't know what technology is powering their experience, and they don't care. What do they care about? Does it work? Is it awesome? The webservices we're going to be looking at have identical functionality to an end user. This one hour tour is for the coder, the technical decision maker, or just the curious.
This is me in a nutshell. I'm the head button pusher, internet brain for Interactive Design & Technology Studio , wiretree.com. I have to keep my finger on the pulse, so knowing how to pull off web solutions in differing technologies is key. I tweet mostly when I'm working, so be forwarned that it's tech related. If it's after biz hours, you'll find out about my son Fletch. Web, I'm there too.
The obvious players to compare are Adobe and Microsoft. Not the only games in town, but these are the two most common stacks that I work with. These apps were both built on a Windows7 machine running IIS7. A decision based purely on convenience. On the Adobe side, everything used to build the client and server pieces are out of the box functionality. On the Microsoft side we needed two third party add on. - nHibernate ORM - MySQL's Connector .net data provider These two libraries where used to keep the stack as similar to the Adobe side as possible. Hibernate was used in this app since it's built into Coldfusion9, and it made data access ridiculously simple. ASP.NET 3x comes with LINQ ( .NET Language-Integrated Query ) I'm not familiar enough with LINQ to compare it to Hibernate. Since Coldfusion9 has Hibernate bundled with it, using nHibernate would keep the stacks as similar as possible. This isn't a fair comparison of Adobe's Remoting vs. Microsoft's Remoting, but the demo is fast enough. Flash Remoting uses AMF and is fast. .NET's Remoting uses LINQ and it's own binary format that is only supported by SL. .NET ASMX services are SOAP, so it's a bit slower.
Update and Delete not shown in SL? Can show Update and Delete in ASMX via browser though
simple single table with four columns vid is an auto generated id column the other three columns contain strings same db and table for both stacks same data
Coldfusion9 comes with Hibernate built in. You still have to enable it to use it in your application This is everything required to setup Hibernate in this demo app. Application.cfc - turn on ORM, and set your datasource. VIDEO.cfc - This cfc is used as the Hibernate mapping file between coldfusion and the video table in the database.
nHibernate is an exact port from Java's Hibernate, so let's keep things consistent between the stacks. Not shown here is the NHibernateHelper session factory class. Every nHibernate operation requires a session. This singleton class is the recommended way to deal with nHibernate sessions. The setup for nHibernate was not as enjoyable as Hibernate in CF9 Setup : 1.Download and install Connector MySQL .net data provider ( this is what nHibernate uses with MySQL ) 2.Download and install nHibernate The install process for Connector and nHibernate is primarily adding references in your project to the correct dll files. hibernate.cfg.xml - Next you configure nHibernate to connect to your MySQL DB video.cs - Next you setup your entity class class notes : - use getter setters - mark properties as public virtual video.hbm.xml - Next you setup your mapping file tie-ing your entity class to your table in the DB.
Flash Remoting is also enabled in the CF Admin under Flex Integration. If you don't enable Flash Remoting, Flex clients won't be able to call remote CFC functions ( the webservices ) webservices in Coldfusion are built in CFCs the CFC cffunction's have their access set to remote using ORM cut's down on amount of code to be written if you're not totally happy with ORM, don't go 100% ORM, mix it up.
This demo uses standard .net WebServices ASMX .NET has it's own flavor of remoting called WCF Webservices. WCF Webservices are only supported by Silverlight right now. ASMX Webservices can be consumed by anybody The nHibernate code is more like Java's Hibernate than CF9's easy Hibernate. nHibernate still cuts down the amount of code needing to be written, but it's not as simple as CF9's
No Flash Remoting, no dice! When you run into CF errors, the server will suggest you turn this on. Might as well turn it on while you're setting up your server. While I'm figuring out code, I like to build my function as a standalone block in a test.cfm page. Once complete, refactor that block of code into my cfc cffunction. By setting the cffunction's output to true, you can call this cfc.cffunction in test.cfm and have it spit the results out to the page. This saves time on the server before going all the way to your Flex client to test data services. While it's not terribly helpful, you can view your webservice.cfc in a browser. The CF server will render it out in a classdoc format. While a sniffer might not help decoding AMF traffic, you must have a good sniifer.
My favorite part of building webservices in .net is the ability to test them in your browser. Loading your webservice.asmx file in a browser first shows you the breakdown of the webservice - each method is a clickable link - clicking a method shows you how to use it via SOAP 1.1, SOAP 1.2, and HTML POST - the method screen also builds a form so you can invoke this webmethod - if the webmethod doesn't receive any input, an &quot;Invoke&quot; button will appear nHibernate's IList doesn't support the IList<genericType> feature, and .net has a hard time serializing when returning from a webservice. If you need to return a collection of custom class objects and you're using nHibernate, after retrieving your nHibernate IList, copy the items into a .net List<genericType> and return that List instead. ASMX has no problem with this route. Just like when you're working with FlashRemoting, Silverlight also requires access XML files. clientaccess.xml goes in the root of your Silverlight application and crossdomain.xml goes in your webserver's root folder. * these config files are tricky, I had to copy both files to both locations to get things working, but didn't bother figuring out the minimum requirements Do us all a favor and don't even bother with VB.NET. Can't stress enough how important it is to have a network sniffer when you're developing webservices, or really any RIAs that talk to a remote server.