24. February 2011 18:53
Having recently put up this blog I figured that the next logical step would be to create an actual web site for people to land on, rather that just this blog. I also have seen a personal site that one of my co-workers has and became a little envious. I have known that the mono project has supported ASP.NET for some time and sense that is where my skills are and I am using a linux server, I figured that I would take it out for a test drive and see what I could get. With ASP.NET, the development pattern of the day is Microsoft's MVC frame work. I fired up Monodevelop and one of the project types is a MVC web appliction. I have done some SilverLight develoment and am familure with the MVVM pattern. It is great for unit testing but there are two sticking point, IMO. First the syntax for the actual binding is tricky to wrap your head around the first time you jump in, second, I find that my ViewModels tend to become very bloated classes because in addition to some logic, the properties on ViewModels must have setter logic to notify of changes. Using a good template it takes a one line property and turns it into a 10 to 15 line getter and setter. Add a dozen or so of those and you code files becomes quite large. I am a big fan of code files under 100 lines, but I can never do that with a ViewModel. ASP.NET MCV is managed code, so any implementation of the .net framework should run it, and mono is no exception. What really impressed me is that the Monodevelop guys have put some good work into making the development experience very positive. They have provided custom dialogs for adding views and controllers. Monodevelop is an excelent Visual Studio lite. Then when I hit run, the web site just works, exactly like I would expect it to in Windows. Nice! So I take it a step further, adding some AJAX. In linux land I could not find the java script files for AJAX support. I had to go out on a windows machine and find them, but once I had them, I just setup and Ajax.ActionLink() and pointed it to a partial view. Again when I ran the web site everything just work. Excellent job mono and monodevelop! Now my site is still quite simple but I have no reason why I wouldn't use ASP.NET, mono, and linux for any serious web site I would ever develop.
14. February 2011 20:27
As of Mono 2.6 (little old at this point, but it is what's installed on my ubuntu 10.04 machine) is is possible to host and consume basic WCF services. Good news for .NET developers that like linux like me (linux server hosting is much cheaper than windows servers.) Creating a service is as simple as following the WCF example service from MSDN. Not everything is implemented in mono, only Basic Http and net tcp endpoints are implemented and the security model is lacking. In the attached sample I have a simple service that returns a string. So you can fire up the service and point your browser to http://localhost:8080/service and you should see a link to the services wsdl.
Now for the harder part, the client. Like Visual Studio, to consume a service you need to add a web reference to it from Monodevelop. Also like Visual Studio, Monodevelop run svcutil to generate a client proxy. That's about where the similarities end. To add your reference you need to reference the wsdl file directly, i.e. http://localhost:8080/service?wsdl
Not that big of a deal. Now the first issue I have noticed, the generated client is created inside the Namespace you provide, but that is the only thing generated inside the namespace. Data Contracts are not included inside your name space. Again not that big of a deal because you can change the generated file a little bit to correct. Problem number two is that contracts with a parent/child relationship are not always present. The Know Type Attribute is not supported in the wsdl generation. I can work around this, not always ideal but I can deal with it. Here is the real problem that bugs me.
Currently the generated proxy has the wrong namespace for your service. This is easy enough to fix, but unlike other issues this will crash your clients if you don't correct it. Now keep in mind that I'm using an older version of mono, 2.6, and I am using ubuntu and not the official image from Novel. Inspite of these issues it is still pretty cool what you can do in a complete linux environment. Attached is a service and client that runs on ubuntu 10.04 with mono 2.6.7.
WCF Mono.zip (15.75 kb)