Thursday, January 14, 2010

.Net 4.0 and Azure

We were mapping out a release schedule for one of our Azure based applications today, and a major part of the application needs to be completely refactored to eliminate tight coupling between our WPF client and our server application.  This coupling is exacerbated by the inability to properly XML serialize some of our Entity Framework 1.0 objects due to the recursive traversal capabilities of EF 1.0.  We’d like to push the refactor back until EF 4.0 is available, but that brought up the question of when .NET 4.0 would be available on Azure. 

There is no set release data for Azure with .NET 4.0 support at this time. However, Scott Guthrie mentioned on his blog on Dec 17th that

“We are working with the Azure folks right now to try and get .NET 4 installed on it as soon as possible.  Unfortunately I don't have an exact ETA yet.”

However, the Azure team this week (today since Thursday is their deployment day) did a release to include an ‘OS Version’ attribute for roles so you could specify a particular Azure Build level when deploying. It will default to the most current version if you don’t set it, so it is a way to ensure that if you don’t want to be upgraded, you won’t be. Right now, they only support one version of the Azure OS. This has to be a precursor to the .NET 4 rollout, and something we have been trying to get them to include since our very first meeting with the Azure Team back in November 2008.  I haven’t looked at the feature in detail, but I’m glad they’ve addressed the concern.

My guess is that they will have to spin up .NET 4.0 support well before the commercial launch of .NET 4 because of the integral role of Azure in VS2010, and that in order for final testing to happen, they’ll have to allow full .NET 4.0 Azure deployments. Kind of a chicken and egg thing.  Stay tuned.

Setting up VS2008 For Windows Mobile 6.1 Development

There are a few tricks to setting up your PC for Windows Mobile 6.1 Development that are needed to get moving.  Of course some of this will depend on exactly what you want to do in Windows Mobile.

My project was pretty simple.

  1. Create a Windows Mobile Forms app that interfaces with a Motorola M9090-G scanning device that allows a user of the scanner to scan their employee badge barcode, a barcode for a shipping document, and a barcode for a series of packages.
  2. The user will scan a large number of packages, and then send their scan records in a batch to a central database for further processing.  The user may or may not be close to a wireless access point at the time of the scan.
  3. The app has to be fast.   The folks using this device will fly through dozens of packages a minute, and there will be multiple scanners working to unload a truck, but there are logical gaps in the loading and unloading where the app can upload to the database.

It’s pretty obvious I needed a client cache for the data.  I chose Microsoft SQL Server CE.  For the backend data store, we’re using SQL Server 2008 (with Change Tracking turned on)

I didn’t want to custom build a synchronization methodology, and since I played with Microsoft Sync Services a bit last spring on another project, it seemed like a good place to start.

First off, VS2008 SP1 comes with a number of emulators built in, but no Windows Mobile 6 emulators.  In order to get the right emulators installed, download the following, and install in the following order.  You’ll need to shut down VS2008 to complete this install.

  1. Windows Mobile 6 Profession and Standard Software Development Kits Refresh
  2. Windows Mobile 6 Professional Images (USA).msi
  3. Microsoft Windows Mobile Device Center Driver
  4. Microsoft SQL Server CE for Devices
  5. Microsoft Synchronization Services for ADO.NET for devices – note that you cannot user Sync Services 2.0, as it is not device ready yet.

You should now be able to fire up VS2008 and create a new Smart Device Project.  Make sure you set it up for Windows Mobile 6, or you’ll not have all the options you need, and will have to start over.

One mistake I made, was not realizing that there is a different version of Microsoft SQL Server CE for Devices than for PCs.  You will need to download the correct version to get everything to work.

I strongly suggest creating two solutions for this type of an application.  One for the Mobile client, and one for the WCF Service, whether it be a Windows Service or a Web Service.  It makes it a lot easier to debug, and helps to ensure that you don’t try to deploy Mobile targeted assemblies to the server and vice versa.  The IDE should prevent you from doing it, but it doesn’t hurt to take this approach anyway.

I like writing code, but I like getting projects done even more.  So if I find code out there that works, I’m not afraid to put it to use.  There were a couple of projects I found that really help to do some of the heavy lifting:

  1. SyncComm on Codeplex.  This provides you with all the plumbing you need to get Windows Mobile Sync working in your project.  If there is one thing I would change (and did) in the project, it was to break the ClientService.cs up into another partial class to remove the customizations that were done to it.  I have found three methods that I moved into a separate file.  Otherwise the code gets wiped out when you regenerate it.  Cost me an hour of work.  See code below.
  2. Custom Message Encoder: Compression Encoder on MSDN.  Download the sample there.  The download link is trickily hidden under the title of the article.  This provides you with all kinds of samples.  The one you want to go to is under <installroot>\WCFSamples\WCF\Extensibility\MessageEncoder\Compression\CS.  Take the GZipEncoder and add the project to your server solution.
public ServerClient(System.ServiceModel.EndpointAddress endPointAddress, BindingType bindingType)



        : this(GetBinding(bindingType), endPointAddress)



    { }



 



    static Binding GetBinding(BindingType bindingType)



    {



        Binding binding;



 



        switch (bindingType)



        {



            case BindingType.Basic:



                binding = CreateDefaultBinding();



                break;



            case BindingType.Compressed:



                binding = CreateCompressionBinding();



                break;



            default:



                throw new ArgumentException("BindingType value not excepted");



        }



 



        return binding;



    }



 



    //NOTE:



    //set compressed endpoint binding custom properties here



    public static Binding CreateCompressionBinding()



    {



        // Create a CustomBinding



        var customBinding = new CustomBinding();



        // Create a compression binding element



        var compressionBindingElmnt = new CompressionMessageEncodingBindingElement();



        // ..and add to the custom binding



        customBinding.Elements.Add(compressionBindingElmnt);



 



        // Create an HttpTransportBindingElement and add that as well



        var httpBindingElement = new HttpTransportBindingElement();



 



 



        //TODO



        //Set here desired values. Take care to match such values 



        //in app.config in SyncComm host project



        //max buffer size



        //httpBindingElement.MaxBufferSize = int.MaxValue;



        //max received message size



        //httpBindingElement.MaxReceivedMessageSize = long.MaxValue;



        //max buffer pool size



        //httpBindingElement.MaxBufferPoolSize = long.MaxValue;



 



        customBinding.Elements.Add(httpBindingElement);



 



        return customBinding;



 



    }




In order to get WCF to connect from the Windows Mobile 6 Emulator to a Web Service on the local host, you’ll need to follow the steps listed by Chris Brandsma on StackOverflow.  This is critical and can cause a lot of frustration if you don’t do it.



So as of today, I have a client on my Windows 6 Emulator, a Web Service, and the basic data flowing, though I have a lot of work left to do to test and refine the processing, and to test on an actual device.  I’m sure I’ll find a few more issues, but I wanted to note what I had done to this point, just in case I need to replicate the process on another PC or build server here in the near future.



Let me know if this doesn’t work for you.

Monday, January 11, 2010

Windows Mobile versus Windows CE

As I explore the wonderful world of really small screens, I’m having to choose between Windows CE and Windows Mobile.  There are pros and cons to both, and what I’m going to list below is just what I think I know at the moment.  Of course what I thought I knew on Friday has changed a bunch, so I’m sure I’ll be contradicting myself in later posts, if not calling myself a complete idiot.

Windows CE is a term used to describe a variable set of OS components that can be deployed to small devices with limited memory and storage.  If you look at the .NET Framework options available in CE apps, you’ve got very little available.  Certainly no WPF, no Silverlight, no native WCF.  You basically need to build up your OS as you go with these components.

Windows Mobile is built on top of CE, but comes with a more standard (i.e. heavier) package of components and applications built into the OS.  The basic environment to run the application is baked in, but you can add elements from CE type SDKs as needed.

At this point, there seems to be the following CE Environments:

  • 4.2 – Deprecated and generally not supported
  • 5.0 – Most devices can run 5.0.  Its like the XP of the Device world.
  • 6.x – Various incantations of 6.0 are out there, but the adoption rate by the major vendors is slow.  Motorola (who bought Symbol), is the big player in the scanner market, and they’re just releasing their 6.x machines this year, and 6.x hit the market in 2006.

Windows Mobile is on a slightly different pace

  • 5.0 – Seems to be fading fast
  • 6.0, 6.1 – Are the mainstay of the Windows Mobile Market place, though being surpassed on phones by 6.5
  • 6.5 – The current version, though wikipedia says it was never really planned.  It just sort of happened.  I hate it when that happens.
  • 7.0 – The light at the end of the tunnel, coming out sometime this year.  Rumors are swirling that the whole OS will be built in Silverlight.  Microsoft has to come out with something just kick ass to stay relevant in the market.  If Windows Mobile 7 is still based on CE, then that’s a good indication, that they’ve given up on everything except bar code readers.

As I was evaluating the various options, I got that creepy feeling with Windows CE, that if I tied my client to it, or worse, spent the year learning it myself, it would be obsolete before the calendar read 2011.  I was also finding it really difficult to just get going with it, finding the tools I needed to build the software, figuring out how to deploy it, and how to build an emulator for it.  I can’t say that from an architectural perspective, it’s a bad product, but in my gut, I knew it was a dead end.  It hasn’t updated in 4 years.  Even COBOL has been updated in the last 4 years, right?

So I switched my project over to target Windows Mobile 6.1, and within an hour or two (most of that being downloads of SDKs), I was up and running, and realizing just how little real-estate is on a 240px-320px screen.  Now it’s a matter of figuring out Windows Synchronization Services, and I’m off and running.

Tomorrow, I’ll post what I did to get my Visual Studio 2008 ready to build and test the Windows Mobile app, which is something I need to document anyway, since I’ll be getting a new work computer soon, and will need to reinstall it anyway.

Let me know if you think my evaluation is off target.  I’d appreciate the feedback.

Friday, January 8, 2010

Windows Devices

I recently took on a new project at work to build a custom scanning app for one of our customers.  It’s a brand new system, likely to be built on the Motorola (ex-Symbol) MC3090-G or MC90900G platform using either Windows CE or Windows Mobile as the base environment.

I’ve never worked on a mobile device, and the first three days has been something of an adventure.  I’d love to use Silverlight, but the 3090 doesn’t seem to support it.  I’d love to use the Microsoft Sync Framework 2.0, but it looks like that SyncFX 2 does not work on CE, and I’ll have to use 1.0.  I may end up spinning up my own sync processor since the database is dead simple (1, maybe 2 tables). 

What’s weird is that a year ago I was struggling as an early adopter to learn all new concepts for Azure, a new technology with little documentation and an unstable base.  Now I’m trying to use technology that’s been around for quite a while, and changes a lot more slowly than Azure and Windows Desktop, yet the process of learning is just as hard because the documentation all dates back to 2006-2007 and my gut says ‘don’t trust it, it’s old’.

So over the next few weeks, I’ll be blogging more about CE / Win Mobile.  Hopefully others will find this useful to get started, and maybe, just maybe, someone will read this, and be able to point me in the right direction.

Anyone at Microsoft need an early adopter for Windows Mobile 7 + Silverlight on a scanner?  Let me know.  I may consider it if I can’t figure out the other ways sooner than that.

Moral Responsibilities

If you work in the software industry long enough, sooner or later you are going to be asked to do something that comes into conflict with your conscience.  Whether it be to ship with defects in the hopes that no key users will find them before you can get it fixed so you can ship on time, or whether it be to include some arcane EULA agreement into the software that no one will ever read, but gives the software or the company to do anything to your PC, or to gather and distribute any personal information the company wants to sell.  Sooner or later, you will review the strength of your convictions.

When I started out in the industry fifteen years ago, I was an idealist (aren’t we all when we are young).  I can remember tracking my hours religiously to ensure that I got paid for every minute I worked past 40 (this was in Canada and overtime was required… that was nice).  Now, I track hours so I can bill clients, but I have adapted to the term ‘salaried employee’, and I just do the work.  It took a few years to get the ‘overtime’ idea out of my head, but I’m paid well for what I do and I want the small company I work for to be a success.  I also know that I must spend my own time to improve my skill set.  That  was something I didn’t see as my cost of working, just a few short years ago.  My moral values changed over time. 

A few weeks ago, I upgraded all my personal PCs to Windows 7.  One thing I hadn’t done was to install the HP driver software so I could download pictures from my HP C6180 All in One printer.  I could print to it, but I couldn’t see the SIMM card reader to get the photos.  We had a bunch of pictures on the camera I wanted to post for family to see.  I went out to HP’s website and started to download the installer for the drivers.

I stopped the download when I saw it was 340 MB.

Yes, 340 MB.  For drivers.

Now I’m not an expert on driver software, but I recognize bloatware when I see it.  I stopped the download, and attempted to find driver software just to get the ph0tos.  You know, something that will allow me to see the SIMM as a USB device.  HP’s own site (in small letters off to the side), said that if you wanted just the drivers (no network), to search for the Basic package.   I did that.  The only package that came up was one for XP and Windows 2000 Server.  Hmmm.

I got impatient.  I didn’t plan to have my whole evening sucked up with just trying to get pictures off the camera,  That’s supposed to be the easy part.  So I decided to download the 340 MB package and install it.  I knew that the previous version of the software had some really annoying apps that I didn’t want, so I figured at some point during the install I would have a chance to opt out of those. I started clicking through the install.  I got to  the page that asked you to accept the EULA.  I clicked to accept (like anyone reads those), and then clicked next.  I then noticed that the install was about to start without giving me an option to opt out of the bloatware.  Hmmm.

I went back a screen, and re-read it.  On the screen were a series of links that look like they are part of the text, but are really optional installer screens that let you go an opt out of some of the options.  Okay, my fault, I missed it.  But reading on, I see a part that says failure to install all of the options will probably cause the installer to fail.  What?  Scare tactics or honest truth?  Bad software?  I was about to commend them for their honesty, until I went into the screens, and started to see all the crap (pure bloatware) and all the really dangerous stuff (outright spyware) they were about to try to install.  Holy Mother of God.  I’ve never seen such a blatant attempt to take my personal information.

Let me stop here for a second, and go back 29 hours.  The previous day I got a call from my wife that she got a call from our credit card company that they had noticed some unusual activity on our credit cards, and sure enough, someone had stolen our number and was buying stuff at BigLots! and Target in California.  I live on the West Coast, but nowhere near California.  So we cancelled our card, had the charges removed, and everything was taken care of in a couple of hours.  I was a little upset, and briefly talked about the death penalty for credit card theft (a damn fine idea if you ask me), but after a few hours, everything was okay.

Fast forward to last night, sitting in front of my PC, looking at all of this crap.  I was spitting mad.  Mad at HP for creating such a mess.  Mad at HP for knowingly taking advantage of the fact that no one ever reads the EULA.  Mad at HP for violating the trust that we are supposed to have for large purveyors of  hardware and software.  They are supposed to be out there fighting against this kind of thing.  Mad at HP for making software developers do this, because I have to believe that no self-respecting developer would ever do this except against their will in an effort to keep their job.  Mad at the industry that slowly whittles away our moral values to the point that this is acceptable behavior.  Mad at the fact that my elderly parents would install this without questioning it, and expose themselves to all kinds of corporate invasion.

I went through and eliminated the stuff I didn’t want, and installed what I thought was the barebones driver.  But I missed a checkbox, and it still installed something called HP Web Printer Helper.  The next time I fired up a browser, half the screen was taken up by an HP add on that kept asking for special permissions to send information HP to help improve my experience.  What the fuck!?!  Screw that.  Search though the add on list and disabled it.

But then I realized that disabling it wasn’t enough.  My other logins for the rest of the family may still have it installed and active.   So I went back into Control Panel and removed anything from HP that was questionable.  I was still pissed.

I popped on to HP’s site, looked through their contact page, and fired off a long note to the HP CEO Mark something or other.  There was a 3500 word limit.  I may have been close.  I doubt if I’ll hear back, and I doubt even more if HP will change their evil ways.  I was ready to call for an all out boycott, but I realized that I liked the HP EX 490 Home Server I recently purchased too much not to recommend that one to other people.

Instead, I’ll simply document my experience here, and hope that my tale takes root, and those roots break the concrete of corporate greed and malfeasance.

So be forewarned, those of you who blindly approve all EULAs from supposedly trustworthy companies.  They know it, and they’re starting to take advantage of that fact.  Scary.