This blog has, IMO, some great resources. Unfortunately, some of those resources are becoming less relevant. I'm still blogging, learning tech and helping others...please find me at my new home on http://www.jameschambers.com/.

Wednesday, October 12, 2011

CustomBinding on Service Reference Results in TransportBindingElement Error

I’m coding an ASP.NET MVC 3 web site in Visual Studio 2010.  I added a service reference to a SOAP 1.2 version of a web service and started updating my code (I was using a SOAP 1.1 endpoint previously).

Unfortunately the switchover wasn’t as clean as I had hoped. The first method I changed resulted in an error, even on a call that appeared identical to the previous version. The error message I received was:

The CustomBinding on the ServiceEndpoint with contract 'SubscriberServices' lacks a TransportBindingElement.  Every binding must have at least one binding element that derives from TransportBindingElement.

…which looked like this:

image

For the quick fix, head to the end of this article.  Keep reading if you want to know what’s going on.

What Was Going On?

The two things that gave me the strongest clues where “CustomBinding” and “TransportBindingElement”, but for different reasons.  CustomBinding was a little unexpected as the service was added via HTTP. I guess I always assumed that it would be using an HTTP binding? The other piece suggested a derivative of the TransportBindingElement, which according to MSDN is an abstract base class.

Off to Our Config File

Actually, at this point, I wanted less noise, so I quickly created a console app and added references to both services.  The differences were, at this point, fairly obvious. The 1.1 version of the service was using a basicHttpBinding element (which I was expecting), whereas the 1.2 service was using a custom binding:

image

So, what we’re looking at is trying to get the custom binding to know which transport we want to use. This is something that is implicit in the basicHttpBinding but needs to be explicitly set for customBindings.

The Fix

Following the links on the TransportBindingElement will lead us to the httpTransportbindingElement, which has both code and config file samples.  Adding a short and simple section to the binding did the trick; all I needed was an httpTransport element in the customBinding\binding element. The updated config section looked like this with the MSDN sample config injected:

image

Further reading shows that all the properties set in the MSDN example are actually all defaults, which means that our httpTransport element can simply be reduced to a single, self-closing tag:

image

Great!

Quick Recap

So, in short, if you’re using a SOAP 1.2 service reference, or any service reference that requires the use of a custom binding, make sure you’ve added a TransportBindingElement (such as httpTransport) to your config file or in your code.

Thursday, October 6, 2011

Setting up ASP.NET MVC 3 to work with jQuery UI 1.9

Caution: I don't recommend trying this in a production environment. The branch of jQuery UI I'm using in this series is not considered stable and is not meant for prod releases.  You can, however, learn about the new features in the UI library and stretch your development capabilities!

The New and Juicy Bits

jQuery UI continues to impress. The development team's commitment to extensibility means that their own widgets are up for review at each release, and even at each milestone of a release.  The great thing about the modularity in jQuery UI is that you can build your own widgets or customize the existing ones with the very parts used to build the core set in the first place. 

But, before you even have to venture in that direction, you already have the ability to work with the many themes (or roll your own!) to make it look and feel the way you want to.

Focusing on stability and flexibility in the 1.9 build, here are some of the important bits that will be surfacing in this release of jQuery UI:

  • Improved, tested code in many of the existing widgets
  • Much better accessibility accross the suite (for disabled users/browsers)
  • Revisited the API design on a number of widgets (Button, Dialog, Position, ProgressBar, Slider, Tabs)
  • Improved collision detection on Position and added a new flipfit mode
  • A new version of Theme Roller, the download builder and the web site
  • New widgets: Tooltip, Spinner, Menu and Menubar

 

Here's the descriptions of the new Widgets from the horse's mouth:

  • Tooltip: A tooltip is a small overlay that sits over the main page that can be used to provide content or functionality that does not need to be always visible.
  • Spinner: A spinner (stepper) is a simple widget that allows users to increment or decrement the current text box value without having to input it manually.
  • Menu: Menu transform a list of anchors into a widget with mouse and keyboard support for selecting an item.
  • Menubar: A horizontal menu with nested vertical flyout menus for each menu item.

 

Getting jQuery UI 1.9


While I'm a huge fan of the integrated package manager in VS2010, you're not going to find these bits on Nuget.  You're going to either need to follow the links from the Milestone 6 post or grab the bits directly from googlecode.com.

Once you grab the zip, unpack it and have a look at the contents.

image

Pretty much everything we're going to need will be in the UI and Themes directories.  If you're not familiar with jQuery UI, the Themes directory is where all the CSS is stored for making the entire UI has a consistant look-and-feel.  UI is where all the code exists for all components. 

You have the choice of building up your own set of functionality for the widgets you're using by including the smaller UI libraries, or you can fire up the full kit with one library.  This allows the bandwidth-concerned developer the opportunity to choose lighter weight code files (or even compile only the needed scripts into a minified script of their own creation).

As an example, if you wanted to make use of the new spinner, you'd need to include:

  • jquery.ui.core.js
  • jquery.ui.widget.js
  • jquery.ui.button.js
  • jquery.ui.spinner.js


Of course, you would also need to include the relevant CSS files, but with a total weight of 7Kb (and the option to use multiple CDNs out on the web) you might as well just include the full jQuery-ui.css.

Using jQuery UI 1.9 in ASP.NET MVC

I'm going to assume you've done a little MVC work before, if not, hold tight for the walkthrough after the bullet list. I'm using version 3 of the MVC Framework in Visual Studio 2010 SP1.

Here's the steps:

  1. Create a new MVC 3 project using the "Empty" template
  2. Delete the "themes" folder in Content
  3. Update jQuery with NuGet
  4. Add jQuery UI 1.9 files to the project ("themes" go in Content and "UI" go in Scripts)
  5. Add a HomeController
  6. Add an Index view for HomeController
  7. Modify the _Layout.cshtml file (your master page) to include jQuery UI and the theme CSS

 

Walking Through the Setup

Here's the visual play-by-play of that in action.

Creating and Cleaning up the Project

Open up Visual Studio 2010 and select File –> New Project.  Create a new ASP.NET MVC 3 Application.

image

Name the project and click OK.  Finally, select the “Empty” template from the list and click okay.

image

Navigate to the content folder at the root of the project and delete it.

image

Updating jQuery

Next, we need to get the latest version of jQuery so that jQuery UI 1.9 is happy with us.  Go to the Package Manager Console and type:

Update-Package jQuery

…and you’ll see the following:

image

NuGet (the heart of this console) happily goes off and updates all our dependencies for us.

Adding jQuery UI 1.9

Pop over to that zip folder you downloaded. You’ll need to make sure you’ve extracted all the files. Copy the themes directory, then switch over to VS2010 and paste it into the content folder.  Do the same with UI, but paste it as a sub folder into Scripts.

image

Adding the Controller and View

We’re going to use the tooling in MVC 3 to do the next bit of work for us, in particular, the code generation that creates controllers and views for us.  Right-click on the Controller folder, then select Add –> Controller.  Call it HomeController when the dialog prompts you (this is so that we can take advantage of the default routing rules in MVC).

image

Your HomeController class is automatically generated with the Index action created for you.  Right click on the name of this action and select Add View. Accept the default name (it picks Index for you because that’s the action you right-clicked).

image

Updating the Layout

Almost there!  All that’s left to do is to adjust our Layout.  The _Layout.cshtml file is like a MasterPage from our days of WebForms and we use it to inject our head element containing the script and CSS references. 

There’s already a jQuery reference there, so that needs to be update to the correct version (1.6.4 as at the time of this writing).  You’ll need to add the jquery-ui.css and jquery-ui.js files as well.

image

For you copy-and-pasters out there:

    <link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" />     <script src="@Url.Content("~/Scripts/jquery-1.6.4.min.js")" type="text/javascript"></script>     <script src="@Url.Content("~/Scripts/ui/jquery-ui.js")" type="text/javascript"></script>


And that’s it! You’re all set up to use jQuery UI 1.9.



Next Up: Using the Spinner with Entity Metadata



Now that you’ve got the library in your project, we’re going to have look at some of the controls in more detail. One of the great things in MVC is the insanely simple templates and data binding, especially when coupled with something like Entity Framework.



Hold on to your hats, in the next segment we’re going to use data annotation attributes to wire up a jQuery UI Spinner widget!

Thursday, April 21, 2011

Time to Move On

I'm starting to chart a new course - still in software development, but trying to focus more on a couple of technologies in particular: Asp.Net MVC framework and the NuGet open source package manager.

As well, I'm going to start sharing my development experiences with other developers and aspiring developers at conferences, workshops and user group meetings.

You'll be able to find my new ramblings at my new site: http://jameschambers.com/blog which will be created with the open source Orchard project.

After being with Blogger for so many years (since 2003, I think?) it will be fun to be working on a new blog engine that is extensible and on the same platform that I develop on (.Net).

Thanks to the many 1000s of you who come here each month, dozens who leave comments and to those of you who have asked questions, made corrections or sent me towards resources I had otherwise overlooked.

Monday, April 4, 2011

Canadians Pay for Music

…but you have to let us at it.

In 2010 Canadians purchased 31.5 million albums.  Folks, that’s darn near the equivalent of one CD per person in the country.

I’m guessing the average album would have sold around the $10 mark.  A digital music store would have taken $3.33 of that.

I hate to continually flog the Zune folks here, but I fail to understand how there is absolutely NO UPDATE or additional information of music in the Zune Marketplace. I started following a few threads in the forums and it seems there is a rising level of frustration, more with the fact that there are no straight answers.

Like I’ve previously said, tell me who the hold up is, and I’d be happy to chase resolution.

This is a market worth 1/3 of a billion dollars, and one that will continue to grow when Canadians have access to reasonable digital content from multiple competitors at a fair price.

Friday, March 25, 2011

Problems with Diamond DisplayLink BVU160

I run a multi-monitor setup and love the extra real estate.  Unfortunately, due to an error in ordering my PC I ended up with a slim chasis and can’t find a dual-head card that fits. I resorted to using the Diamond USB adapter, which for the most part has been a nice way to get that third monitor running.

But lately this little guy has been causing me headaches.

WP_000186

Here’s the formula:

  • Windows 7 Ultimate x64
  • Diamond BVU160 v1.0 DisplayLink adapter, driver is up to date
  • Windows Phone 7 attached (Samsung Focus)
  • Dell E198FP monitor
  • ATI Radeon HD 3400 Series display drivers, up to date

The screen “freezes” up and does one of two things:

  1. The image is locked in a sense, and only redraws small invalidated regions as I drag my mouse across the monitor.  I can also restore a window, invalidating the whole screen, and get the whole thing to redraw.  This works a few times, but then the screen goes black.
  2. It skips #1 (or I just don’t notice as I’m working on a different monitor) and just goes black.

At this point I have to unplug the power of the monitor (power cycling doesn’t do anything, I have to physically remove the AC cable), disconnect the Diamond adapter, reconnect power and then attach the USB adapter again.

This is happening about 2-3 times a day when I have the phone connected and the display adapter is almost hot to the touch when it gets to this state.

I have a fairly high level of certainty that this is related to a conflict with Diamond’s adapter and Windows Phone.  It only ever freezes like this with the WP7 device attached.  I thought it was perhaps Folding@Home, but I uninstalled that and I’m still getting this problem.

If anyone else is running into this and has a workaround, please let me know!

Wednesday, March 23, 2011

How Windows Phone 7 Could Fail in Canada

Folks, let me start by saying that I love my Samsung Focus.  Everyone’s seen an iPhone by now, but you can still turn heads when you’re zipping through the home screen on a WP7 device.  The interface is slick, the apps you need are mostly in the marketplace and the cooler ones – I’m still waiting for the possibilities of augmented reality apps with video and compass APIs – are on the way.

The phone is well integrated into my other communication points, from email and messaging to scheduling and sharing, and though I’m a heavy user I’ve seen little by the way of bugs.

But I live in Canada.  And the sale of this phone platform to my friends will be tough.  It’s not because the platform isn’t great – and I do think WP7 phones are on a great platform – it’s because the phones in Canada are crippled.

The Show Me Factor

We are moving away from a people with music players to a people with multifunction devices that have music players on them.  At least, those of us with the ability to support a smartphone contract are.  Well, us and the teenagers whose parents spoil them, but I digress.  I had my first MP3 player over 10 years ago and haven’t missed it a bit.

But the music marketplace in Canada Sucks.  Yes, “sucks” with a capital “S”.  We have very limited choices in where we can purchase our digital content outside of the iVerse.  I’ve used Puretracks and played with the paid versions of some other services but not all the content I want is there and I’ve previously had troubles with DRM content on mulitple devices.

I want my family – we have four PCs all running Windows 7 as well our our Xbox 360 – to be able to use something more fluid within our ecosystem, connected to and built into the devices we use.

Including our phones.

Look, there’s going to be a point where people will have seen it/been there/done that and if the experience isn’t positive they won’t want to go there again.  There’s a really good, but shortening, window that Microsoft should be able to leverage.

The Switchover Debate

Look, if I can’t convince my wife, my soul mate, my partner until forever to buy a Windows Phone device then I’m not going to get too far with others.  These things should sell themselves, but this media marketplace keeps kicking WP7 in the face.

We’ve talked about the switch to a smart phone and she’s been leaning towards an iPhone for some time.  All of her music is in iTunes and we’d need to spend some time converting it (in some cases with DRM that might not be possible) and then we’d be left with the purchase void.

That chasm is too far to cross at the moment.  We’ve agreed to wait for a bit to see if the marketplace changes, but at this point it’s a wide open yawn’s worth of information available and no one is giving any updated information.  For fully three years we’ve been hearing “Keep checking the Zune web site for your region” and nothing more.

Challenge #1 - Marketing

I eagerly waited for the Zune HD here in Canada, only to have my hopes dashed when Future Shop pulled the remaining original Zune devices from the shelves.  A new employee said to me, literally three days after I almost bought one, that he’d never even heard of Zune.

What?!  How could that be?  How could the only device poised to be an iPod killer not even enter the general population’s vernacular? We are talking about a company who did the unthinkable here and broke into the video game industry, a move previously believed impossible as the market already had enough players.  How could, in this young and developing area with few serious players, Microsoft miss the boat with visibility?

The same thing seems to be happening with Windows Phone.  I can still walk into a room of people completely unaware that WP7 devices were actually out.

Challenge #2 – The Marketplace

This appears as #2 on my list, but not because it’s less important.  I will say this as directly as possible, Microsoft: the music marketplace must be fixed.

Technically, it’s not broken.  Because it’s not here.  This is the number one reason my wife won’t buy into the ecosystem, and it’s almost always one of the first things I’m asked of when I’m showing my phone.  You fire up Shazam and it’s right in your face: excellent execution followed by a lack of follow-through.

I am a sell out here, folks and I know it.  I’m a die hard.  This is a platform with great potential and I’ve even gone so far as to evaluate my “grey area” options (US credit card, friend’s address).  But I’d much rather see the ecosystem change for WP7 in Canada so that we can do things legitimately and without hassle.

I understand that there may be other problems.  I’ve heard everything from the CRTC blocking Microsoft, to third party licensing complications, to Apple threatening to make things messy.  But Microsoft hasn’t said peep squat about what the problems are.

Challenge #3 – Marketing

Yes, it’s the same as reason one, but different.  You see, the thing is that Apple didn’t sell it’s iPods to the millions of customers that have them.  The other customers did. Unfortunately, proud Canadians wielding their WP7 phones are ill-equipped to make the sale.

Heck, even the stores clerks aren’t really there as far as sales pitches.  When I asked to see the Focus at Future Shop, I was greeted with a, “Really? Why?”.  He was even more shocked when I took it home with me.

I’m not selling these phones and I don’t work for a cell phone company or Microsoft (yetWinking smile), but if a guy can’t convince his wife to get one, we’ve got a problem.  Shoot, I even convinced her to marry me, but I can’t pawn a phone on her!

The Fix

Actually, Fixes.  It’s plural.  Here are the things that can right the course for this beauty of a ship:

  1. Figure out the content licensing and make music available in the marketplace. If it’s a ways out, for now you must, must clearly communicate what the issues are.  Customers would be happy to lobby any group that is blocking the process.
  2. Set up Zune Pass now, even at a lower cost and with limited content. Get buy in from the Canadian content providers to get them in the streaming mix be it independent radio stations, the CBC, CTV or the sports broadcasters. Flesh out the product and give Canadians the same level of product that’s available in other countries around the world.
  3. Give out some more free phones.  Future Shop wouldn’t even let me play with one of WP7 phones until I said I was surely going to buy one.  They wouldn’t take it out of the box.  This is wrong and bad and a poor purchase experience and bad, too.  Apple has kiosks setup to demo different models of the iPod/Pad/Phone/Thing and for WP7 I get to look at a cellophane wrapped box? Boo!
  4. Increase visibility.  Get storefront space. Encourage cell phone dealers to use and promote the phone.  Roger’s booth in our mall here had the iPhone 4 announcement posters up six weeks before the phone was launched.  There is still nothing in the mall about WP7.  Nada.

I am a software developer and though my previous experience has been on other platforms and technologies, right now I work exclusively on the MS stack.  I am going to MIX11 and am super pumped to see what the year ahead will bring us.

I’ve already come to terms with the fact that most of my concerns will not be addressed by the time the event rolls around, but you can be sure I’ll be sharing my thoughts with whomever will give me an audience.  Basically, it’s a conference where I’ll be hanging out with a ton of folks who’s phones are cooler than mine; sadly, we’ll have the same phone.

This is a phone that can really give customers a fresh experience with a unique level of integration with communication, search, maps, gaming and social networking.  I really hope that WP7 survives in Canada long enough to bear the fruit it is longing to produce.

Sunday, March 20, 2011

jQuery IntelliSense with ASP.NET MVC and the Razor View Engine

The Razor view engine in ASP.NET MVC3 brings great improvements to the readability of code in the view.  Unfortunately, some of what I’d previously lamented in missed productivity improvements has stuck around.

If you are working with Razor’s reimplementation of Master Pages – Layouts – then you will likely run into the same kind of limitations with IntelliSense that existed in previous ASP.NET editors: you simply don’t get IntelliSense for jQuery on your views when you include the script reference in your _Layout.cshtml.

Enabling IntelliSense

The only way to get those digits moving at the speed of computer-type-it-for-me is to add the script references to your view.  Because we don’t want the script written to the page twice – once through the viewstart/layout and once through the view – we simply use our old if(false) trick (see part way down) to get IntelliSense back online.

@if (false)
{
    <script src="../../Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery-ui.min.js" type="text/javascript"></script>
}

Write the if block out and then drag and drop the files from your scripts folder in the Solution Explorer as an easy way to do this.  Once you’ve done this once, you can then put it in your Toolbox by highlighting the code and dragging it to the Toolbox window.  Here, I’m about to rename it to something more useful:

image

How This Could Be Fixed

To understand why it’s not working we have to look at what the IDE is aware of and what it does to figure out what styles/scripts are available in the editor.

When you’re on a view, Visual Studio doesn’t really know which layout will be used to render the view.  In some cases you may have many and you may be dynamically selecting it based on, for instance, the role of a logged in user.

However, we also know that the MVC Framework relies heavily on convention, and chances are that the default, most-used scenario with the ViewStart/_Layout.cshtml being used is likely the one that most folks will be dealing with.

So I would propose this: in the event that there is only one _Layout in the Views folder, assume that this is the one that will be used. Infer style sheet and script references from this file and enable IntelliSense based on the same.

Making the Most of It

Well, we’re set to receive up to a total of 35cm of snow in the next 24 hours. With the gorgeous weather at hand, but the threat of a raging river looming, you need to do something to take your mind off the impending flood.

We had a great afternoon of sledding, snow ball fights, snowman building and hot chocolate with marshmallows.

image

Mr. Frosty here is a good 45cm taller than my son. An incredible afternoon.

After completing the snow adventures we drove back home past the sandbagging efforts of the city, which are required in order to keep major traffic routes from being submerged.

Thursday, March 17, 2011

ASP.NET MVC3: The Razor View Engine and Text

I knew this, but I had a brain fart here and couldn’t figure out what was wrong. I was trying to output some simple text to the browser based on some condition:

image

I started to get the following error message:

The type or namespace name 'Do' could not be found (are you missing a using directive or an assembly reference?)

Along with a list of others:

image

But nothing really said what was wrong.

Nothing’s really wrong, per se, but Razor can’t figure out what I want to do here and doesn’t know that Do should be text and not me trying to code something. To fix it, simply wrap the text in a <span> tag and roll:

image

Tada! </facepalm>

The only reason I ran into this was because I copy & pasted the text. Normally you’d get IntelliSense as soon as you start typing and that should throw up a context flag pretty quick.

Tuesday, March 15, 2011

Google News Fail

Ran into this today when checking the news:

image

The headline reads: Japan’s PM warns of radiation risk

The body of text below: Scientists say they may have discovered the lost city of Atlantis buried deep under the marshlands of southern Spain, north of Cadiz and near the Straights of Gibraltar.

Sunday, March 6, 2011

Who’s Smarter Now, Mr. Computer?

The New York Times have posted the game Rock-Paper-Scissors – You vs. the Computer in the wake of the big Watson computer win over the human Jeopardy contestants.  They reduce AI to “building on simple rules and statistical averages” and present a game of chance, with some big claims.

They have two versions of the game, one that has to learn as it plays, the other that has some experience in the mix.

Picking an Opponent

I’m no rookie, I have been known to dominate the RPS scene at my office and I know how to stare down an opponent.  Oh, wait…shoot.  I start with the sure-fire winner, the one you should put your money on.

The Veteran Presence

So here’s their idea…after several rounds of play their computer will use statistical analysis to figure out your strategy, backed by 200,000 previous rounds of play. They don’t define the 200,000 rounds – as in, were they human played, were they 200,000 different people, if nationality or race or education played in – but for some reason that’s enough data to “exploit a person’s tendencies”, and yet, I have my doubts.

I decided to play 40 rounds.  If there was anything akin to AI in the pot, this thing should at least win one third of its games.

Here’s where I was a few moves in:

image

While it made some ground up towards the end, I was able to hold it off of any streak and the closest it got was within two.

image

After that, I teetered on +2-3 points and as high at +4-5 points, and ended up +4 over the computer, thus solidly proving that, minimally, if we’re going to partner a game of chance with technology called “AI”, we have a long way to go.

image

There was no stopping me by some ‘simple rules’ engine. ;o)

I want to point something important out about this statistic: for the one who is winning more that the opponent and the tie, they are beating the odds.  I am a combined +10 on 40 rounds here at the end of the game, meaning that not only am I beating an expert player, but I’m beating the tie-chance handily as well.

Bring in the Rookie

Finally, I tried out the “dumb” version, the rookie alter-ego that must first learn the rules and doesn’t get the benefit of 200,000 other players’ moves in a database.  I decided to give it an extra 5 moves as a chance to learn some of the rules before getting into the play.

image

What? Shocker?! How could it be that with 5 more moves against an (arguably) weaker opponent I could have fewer wins?!

Oh right…it a freeking game of chance. Unless you put on your idiot cap and play the same hand each time, this is a game of odds and they are 1/3, 1/3, 1/3 as to what I’ll play next.  Period.  Just because 200,000 other people picked R-R-P-S-S-R before me doesn’t mean that I’ll play P instead of R on my next move.

This is not a prediction, even when backed by hundreds of thousands of records, not any more than a lady in a tent with a lit glass ball.  Over time I will win 33%, lose 33% and tie 33%.  It’s no different than a coin toss, with one more side to the coin.

The only learning that this ‘AI’ does is around the rules of the game.  To that end, there’s only really six (counting ties), and it seems to know when it’s learned them all, suggesting a bias in the first place.

Okay, Yeah, But…

There’s more going on. I know it does some pattern matching and what not, but that doesn’t mean it’s AI.

After playing these games I walked through it’s demonstration about how it thinks.  It uses some good buzz words making it sound like it’s thinking, but really, this is just straightforward math equations muxed with some simple filtering that any first year CompSci student should be able to figure out. 

No magic here, folks, move along.

Conclusion

The programmers at the New York Times have created a good gimmick that will fool most of the general population into believing that they have created some form of artificial intelligence that, when it mates with Watson, is ready to techno-freak the humans into submission. 

Hey, it may even be an impressive chunk of code, but it does not represent any of the modern complexities that some impressive minds (like those at IBM) have solved.

I could likely to write a version just as capable by picking randomly the answer.

Better yet, I’m going to write a traffic light color prediction engine. 

Look out, Matrix, we’re all about to take the blue pill. Or was that the red?

Saturday, March 5, 2011

This update improves the experience of updating your phone in the future.

Well, it’s arrived, my phone’s hit the list for updating.  I got the notification on my phone and plugged it into my laptop to start the process.  My update was delayed as I was on the brick list; I have a Samsung Focus.

image

First Things First

Before I was able to apply the update, Windows Phone 7 required an update to Zune. 

image

This process took about four minutes, including the download.

image

Updating the Phone

After the Zune update was complete the software shut down but did not restart on its own.  I left my phone plugged in, but was not prompted to update.

When I restarted Zune I had to go into Settings->Update where I was able to launch the update process.

image

The only thing different this time around was that the warning had been updated to note that telephony would be disabled.

image

The estimate was 20 minutes for the entire process and I was on step 6 of 9 in about 15 seconds, so I was optimistic.

image

When the reboot was complete the updates were pushed to the phone and the computer installed new device drivers. One more reboot, the updates completed installation, and the phone was as good as gold!

image

Total time: 18 minutes, start to finish.

Thursday, March 3, 2011

Windows Phone 7 Wishlist #3

There are two things I am looking forward to in a big way, but not on my wish list (because these will be realized for sure):

  1. The upgrade to HSPA+ in my area, and,
  2. The Windows Phone 7 first update.

I’ll get to my wish list in a moment.

I am stuck on the Edge service network because of my locale. The towers were upgraded months ago, but one of the partners in the carrier network (not mine) have equipment and services and software older than bunk and they can’t flip the switch until everyone’s ready. This is going to happen in days and I can’t wait until I’m pulling down 7Mbps on my phone.

I have a Samsung device and have not yet received the update. I’m not sure if it’s a candidate thing, or a rolling update thing, or even if my carrier is blocking it (I’ve heard all three) but I am looking forward to the pre-update update that is currently in the works, especially as it paves the way for The-Big-One in the next few weeks.

I wondered here if my carrier might be blocking the update, but I don't think that could really be the case. The phone checks for updates, likely directly to a WP7 service, and the device itself is updated through the Zune software on PC.

Here’s My List

  • I would like a way to search my text messages. This is present in mail, so it seems like it’s not too far fetched in texts. I had someone text me the phone number of my friend ‘Mike’, but I couldn’t remember who sent it to me. The text was something like “Hey Mike’s new cell is…” so I should have been able to find it fairly easily.
  • I would like an editor for my alarms and ring tones. Build it into Zune, or make a Windows Live ZuneTone application that you can download and make your own ringtones and alarms. Let me set cues for vibration. Let me shift pitch and even layer multiple audio tracks. Let me share it through Zune or Live or something with my friends.
  • A first-party, no frills sound recorder. The same level of function as the one built in to Windows 7. In fact, I would love it if I could also use the audio jack as a line in to record. I volunteer on a regular basis and work the sound board (or at least help) and I hate lugging around a laptop to record the audio.
  • Because I feel as strongly as I do about this, I’m going to say it again: Canadians want to pay for their content. Please make Zune Pass available in Canada. If this plea doesn’t work, I’m going to track down folks at MIX11 and talk to them in person! ;o)

I have a couple of other items on my list, as mentioned previously:

Extension Methods for Converting ints and bools

I was recently working on a chunk of code where I had three different scenarios for conversion.  With two external libraries (something I couldn’t change) and this not being a big enough project (so not worth a facade) as driving factors I rolled a couple of simple to use extension methods.

The Code

I won’t lollygag here too much.  You need a namespace and static class name that work for your (they’re more-or-less irrelevant in the grander scheme), and a couple of static methods.

namespace ExtensionMethods
{
    public static class Extensions
    {
        public static bool ToBool(this int i)
        {
            return i == 0 ? false : true;
        }

        public static int ToInt(this bool b)
        {
            return b ? 1 : 0;
        }

        public static int ToInt(this bool? b)
        {
            return b.HasValue ? (b.Value ? 1 : 0) : 0;
        }
    }
}

Basically, we’re just using a tertiary operation to decide which value is appropriate to use in each of the contexts.

The third method is there to help out with nullable boolean values.  This was handy in my case, not sure how many people would need this.

Monday, February 28, 2011

Fixing “Unrecognized configuration section userSetting” Errors

Though I have not seen the error “Unrecognized configuration section userSetting” as a standalone exception, it has come up a number of times for me and surfaces as the inner exception on a “Configuration system failed to initialize” exception.

If you’re running into this error and following along, I’m currently using Visual Studio 2010, mostly on .NET 4.0 and I program in c#.  If you’re using a different environment some of the file names or UI might be a bit different, so you’ll have to adjust accordingly.

The exception will be raised in Settings.Designer.cs, on the first attempt to read a value from the application’s configuration.

You can fix the error by navigating to the current directory where the user settings are being saved for your app.  This will be in %system%\users\your_user\AppData\Local\Microsoft\YourApp.vshost.######\version

Delete the user.config file, clean your solution and rebuild all.  This should fix the problem.

If that doesn’t work, you may need to go so far as to shut down Visual Studio, clean out all the %system%\users\your_user\AppData\Local\Microsoft\YourApp directories of any config files and then follow the above steps.

What’s Happening?

When you first add a setting to the application through the UI, the default is to create a user-scoped setting.

image

User settings and Application settings are primarily different on two fronts:

  1. Storage location
  2. Run-time accessibility

User settings are read/write and can be altered at run-time. These are perfect to save things like favorites, window layout, user-specific options, color preferences and the like. These files are stored in a directory created for the application, basically sand-boxed from system-wide access and the only place your app can read/write from for free (elevated privileges aside).

Application settings are read only at run-time and can only be altered by changing the XML file and relaunching the application, or by some creative XML file management (and then a reload on your configuration data).  These files are stored in the app directory in app.config and also contain the default settings for users who have not yet launched the app (these are the settings that will be defaulted in for the new users).

I have hit the “Configuration system failed to initialize”Configuration system failed to initialize error a couple of times, and it always seems to be the User scope default biting me in the arse.

Basically, I create a setting, plug along for a while, then go back to add another setting and realize that I had left it in user scope.  I switch the first setting to application scope and keep plugging away.  Somewhere between then and the next time the application tries to access that property, the exception is thrown and doesn’t give you much detail at the surface level.

Figuring out the Files You Need to Delete

I said you can likely delete the user.config files without much regard.  Truth is if you’re into testing something settings-related that can be a real inconvenience.

I will drill into the inner exception to find the problem file; it’s only two deep, so it’s easy to find the path of the file in question if you’re willing to dig. 

Trust me, folks, your debugger is your best friend.

Friday, February 25, 2011

Windows Phone 7 - What if?

Nice. Looks like Microsoft is starting to ramp up the ooh-la-la with their advertising. Combined with the web-based ads with the head-to-head comparisons, the new Windows Phone 7 commercials are starting to look a little more playful.



Yeah. My phone does that. :)

Monday, February 14, 2011

An Azure Deployment Primer

From the Developer & Evangelism Labs: Introduction to Windows Azure

This post is a summary of the notes I took while working through the Introduction to Windows Azure lab in the January 2011 Platform Training Kit.  I ran into a couple of road bumps and bruises along the way and thought I’d share.

The Platform Training Kit – The download for the kit

The sample is a guestbook that lets you write your name, a message and post a photo.  A background service resizes the photo and the thumbnail is linked to the full size image.

The lab walks you through setting up the relevant bits of the application locally, then walks you through deploying it the application to the cloud.  I found it to be a good balance of hand-holding and explanation, but you may find many questions left unanswered. The Microsoft Platform Evangelism team has certainly lowered the bar for folks to get in over their head! Thankfully there are 26 other labs to help quench your thirst.

When you get it up and running, here’s what the end product looks like:

image

Well…that’s what it looks like if you post a picture of the snow on my roof with a name of MisterJames! 

Snags, Detours and Road Bumps

Documentation Gap

Following the lab from the first step and trying to use the project through all of the exercises has its pitfalls. First of all if you make a mistake, that carries through the whole way.  Secondly, when preparing for and throughout exercise 3 (deployment) there isn’t much clarity around the implications of misnaming your hosted service or storage account.  There are also rules around naming (they have to be DNS suitable names) but this isn’t clear through the docs.  Worse, the error you get when you make an account naming mistake is not very leading: One of the request inputs is out of range.  I was getting this error when making a call to CreateTablesFromModel, and nothing really pointed me back to the name.

You can, however, opt to jump in with the files provided for the lab.  At each step of the exercise the team has provided us with an updated, accurate solution to continue from.

This is good, as in step 3 it assumes you’re using that and doesn’t give clear instructions on the updates required in the service configuration file.  The nodes and values required are in the provided solution.

Error Loop on Deployment

After I completed the lab I started playing around with config files and some simple changes to the app.  In that process I managed to botch a deployment package (the configuration bits).  Unfortunately, I didn’t realize that until I had already deployed the package as an upgrade to the first version.  The instances were stuck in some updating/starting/waiting/resetting cycle that took over 40 minutes to work itself out. The result was an error state, which until reaching I was unable to stop and update the service.

A Missing Warning

I just want to add another voice to the mix here: remember to stop and delete your project as you don’t want to be incurring charges or burning up valuable compute cycles.

Time Expectations

This is a lab that is scheduled to take approximately 60 minutes.  In addition to the coding bits I took two phone calls, answered a few IMs and emails and was wrapped up on the code/deployment side of things inside 55 minutes. I did muscle through it pretty quickly, though, as I’ve done several of these labs and know the style. 

If you aren’t patterned to recognizing the parts you should and shouldn’t need to read, this lab could take up to 75 minutes to complete.  One other note: I already had my Azure account up and running, so I was able to skip that part of the task.

After plugging through the juicy bits, I then had to wait for the succession of updates, host starts, role starts and what not.  This easily pushed me over the allotted 60 minutes.

image

For all of these services to finish their progression to their final states took about 20 minutes, at which point we end up here:

image

Conclusion

Set aside a two-hour slice of time and you should be able to move casually through the lab, start to finish. The Introduction to Windows Azure does a great job of touching on many of the concepts you’ll be working with when you get into cloud development.  You will be left with questions around deployment and configuration, but this start is good exposure and the walkthrough doesn’t leave out any important steps.

Don’t forget to delete the services created in the lab!

Sunday, February 13, 2011

Mixin’ it up

Bootcamps. Keynote. Sessions I’m actually interested in. Meeting folks that I’ve only ever known online.  Should be a great event!

Tuesday, February 8, 2011

Parents, Open Your Eyes

I just read this blog post from over on ZDNet: It's time for iTunes and Xbox Live to put spending limits in place.  Mr. Adrian Kingsley-Hughes writes that:

There’s a fine line between something being lucrative, and starting to feel scammy. Apple is certainly sailing close to the wind with some of the in-app purchases it is allowing, and Microsoft could certainly do more to prevent this kind of bad publicity. [...] And it’s clear that the current mechanism of relying on parental controls isn’t enough. Both companies need to get their act together.

I would agree that parental controls are failing – couldn’t that be said about a lot of things? – imagebut we would stop short of flogging a parent who pulled off the same stunt at Wal-Mart and then tried to blame the store management. 

Could you imagine walking your child into the store, giving them a shopping cart and meeting them at the checkout – at which point you blindfold yourself and let the check-out clerk scan all items…and then your credit card?  And you don’t even check?

Look, I’m no fan of Apple, but I don’t think they (or Microsoft) are in the wrong here.  My wife has disabled in-app purchases and we don’t share our password for the iPod Touch or the Windows Phone 7 devices we own.  Not going to happen.

Our kids just don’t get unchecked access to our credit cards.  Period.

While Mr. Kingsley-Hughes refers to it as ‘insanity’ and points blame to the companies in question, I refuse to be an enabler for parents who want to make stupid, unconditionally blameless children.

Monday, February 7, 2011

Dedicated Back Button: Genius

My wife has an iPod Touch and we were running through some of the same apps that exist on iOS and Windows Phone 7.

At several points we both accidentally clicked the wrong link/button/UI element etc. on our own device.  There was one glaring difference, however; the iOS versions often land you in a place where you have to navigate through the home screen and back into the app where you accidentally made the click.

Not so, with Windows Phone 7: there’s a dedicated, hardware-based back button.  This makes it easy to back up through your screen progression to the last place you were at.

It’s so simple that you think that it wouldn’t be necessary, and yet, there she is…my wife pushing the empty space on her iPod like there should actually be something useful there.

Monday, January 31, 2011

Windows Phone 7 Wishlist #2

So I’ve been playing with the phone now for over two weeks now and having a great time showing it to my friends. They are shocked that it’s a Windows phone. I have two friends, in particular – one from Vancouver and one from Toronto – who were in town for this past weekend and are huge iPhone fans. image

Between the two of them they’ve owned every iteration of the iPhone, including their now current iPhone 4. They put their phones down and were fighting over my Samsung Focus.

The one was quite miffed that the Rogers rep at the mall didn’t demo it for him as he just picked up his iPhone 4 three weeks ago.

Things I’ve Noticed

  • When you give the home screen a little inertia to let it scroll, then repeatedly hit the Windows button, you can make the tiles skip and keep rolling from the start. This turned out to be a fun game for my kids, who have contests by pinning all the apps to the home screen and then seeing who can be the first to scroll-home-tap and give it enough momentum to get to the bottom of the list.
  • I tend to hit the back or search buttons when I’m using the camera. I am so used to holding my other phone that had no buttons in that area that my fingers get in the way. This isn’t so much a WP7 problem as a Samsung Focus problem. It happens enough to be annoying but not so much that it’s a problem.
  • Same thing with the volume and power, which are on exact opposite sides. You use the phone for leverage on the opposite side to push the button…with unintended results.

Things I’d (Still) Like to See

  • Video sharing
  • Zune Pass and music in the Zune marketplace for Canadians (I’ve already mentioned this, but it’s worth repeating)
  • Updates to the Facebook app – (doesn’t really seem to do it’s work in the background)
  • Some way to organize the apps list. I love the tiles, I love the way the other apps are off to the side, but what would really work is to carry forth the Metro metaphor and allow me to make a panorama out of the apps, with categories I can set. I wouldn’t even mind – at first – if I had to do it in Zune.

Thursday, January 20, 2011

ASP.NET, MVC 3, the Razor View Engine and Google Maps

With the release of MVC 3, the updated project templates and the Razor view engine we have several new features and tool improvements at our disposal.  I wanted to see how hard it would be to get a quick mash-up of some ASP.NET goodness and the Google Maps API.  For this project, I’m going to walkthrough creating a new project in ASP.NET using MVC 3 in Visual Studio 2010.  You’ll need to have the RTM build of MVC 3 (which contains other ASP.NET enhancements, btw).

Getting Started

Once installed, it’s fairly easy to invoke the New Project dialog and select ASP.NET MVC 3 Web Application from the Web templates.  If you don’t see the project type listed, make sure that you are targeting the correct framework.

image

I named my project RazorMaps.  When we click ok, we are then presented with a bit of a wizard to select our options for the project.  This is a simple but good improvement over the previous MVC bits because it rolls up the wizard, test project creation and multiple templates (empty versus the “internet application”) and lets us select the view engine.

image

imageFor simplicity sake here I’ve just selected an Empty template and no test project. 

Most of the project pieces feel familiar, in fact, there’s no noticeable changes to the MVC project at a root level and all the expected folders are there.

It’s nice to see that jQuery is added by default to the _layout.cshtml file, and to see that jQuery UI is included in the project.

As at my writing this, it’s also the latest bits for the jQuery library, and they have the vsdoc file updated (AWESOME! No more renaming the old one and replacing the library!), and there are other libraries in the mix as well (enabling unobtrusive validation, etc.).

A Simple Home Page

We need to get a view set up so that we have something to look at.  The base project doesn’t include the controller or the view we’re going to want, so we’ll start there.

Right-click on controllers, Add > Controller and name it HomeController.  We get our basic controller up-and-running and the code for our first ActionResult (our home page) is free:

image

Next, right-click anywhere in the Index method and select Add View from the context menu.  If the View Name is Index then you shouldn’t need to change anything else.  We’re using the Razor view engine and we already have our layout specified in _viewstart.

image

Press F5 to see your lovely work!

Hello, Google Maps

We have a couple of things that we need to do to get the basic, no-frills map up-and-running.  Though I worked from the simple tutorial on the Google Maps Javascript API page, I’m going to try to MVC this up as much as possible and look at some of the features of the Razor view engine.

We know that we need to add the Google Maps script to our page, and we can see from the tutorial that you also need to have a couple of styles.  Because we are using layouts in Razor and don’t want these on every page we create, we’ll take advantage of Razor Sections in our layout.

Open up _Layout.cshtml and add the following lines of code to the <head> portion of the document:

@RenderSection("Scripts", false)

<style type="text/css">
    @RenderSection("Styles", false)
</style>

We’re adding two optional RenderSections here.  This is very similar to creating content sections when using master pages.

Next, pop back into our index.cshtml file so that we can add the juicy bits to get the map loading.

Fleshing out the Page

Right at the top of the file, you’re going to want to add the following code:

@{
    ViewBag.Title = "MVC 3 and Google Maps";
}

@section Scripts {
    <script type="text/javascript"  src="
http://maps.google.com/maps/api/js?sensor=false"></script>
}

@section Styles {
    html { height: 100% }
    body { height: 100%; margin: 0px; padding: 0px }
    #map_canvas { height: 80% }
}

The ViewBag is a dynamic expression and evaluated at runtime.  The “Title” property is filled into our layout template with the @ViewBag.Title expression. 

Next, we have our two sections; the first adds the map script to our page, the second applies and specifies the styles we need to get the map rendering correctly.

The rest of the page consists of:

  • A div element (to host the map)
  • An initialize function that sets up the map, and
  • A jQuery shortcut to invoke the initialize function when the page is ready

Here’s the code:

<h2>Hello, Google Maps</h2>

<div id="map_canvas" style="width:80%; height:80%"></div>

<script type="text/javascript">

    function initialize() {
        var latlng = new google.maps.LatLng(40.716948, -74.003563);
        var options = { zoom: 14, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP };
        var map = new google.maps.Map(document.getElementById("map_canvas"), options);
    }

    $(function () {
        initialize();
    });
   
</script>

And there you have it!  Press F5 again and the map loads.

Conclusion

If you have a good handle on ASP.NET MVC and you understood MasterPages, the switch to the Razor engine and templates is going to be easy and refreshing.  Integrating per-page code, via Razor section rendering, is straightforward and keeps our templates clean.

Updated script libraries and improved templates and a ton of feature enhancements round out this release nicely.

Wednesday, January 19, 2011

Built-In Authentication and Authorization Providers in ASP.NET with the MVC Framework

If you’re not already doing so, you should seriously be using the the built-in Auth & Auth in ASP.NET. While the subject is fairly well covered, I continue to get several questions and comments related to creating accounts, logging in and permissions and when talking with other developers. I am shocked at how many still roll their own authentication and authorization bits – often for no better reason than not knowing how great (and FREE!) the default providers are.

The Basics of Authentication and Authorization

There are two things you will need to do on most web sites with “account” functionality: identify existing users based on provided user names and passwords (authentication) and then express privileges to control access to protected resources (authorization).

These two facilities allow us to do some creative things, like showing different content to users when they are logged in, or to restrict and redirect requests based on the logged in user’s set of privileges.

In ASP.NET, Auth & Auth are Free

The first official, for-a-customer e-commerce web site that I notched on my belt was back in 1997. I spent days creating a system to log users in, store cookies (that I do not care to discuss security about!), store user information, track log-ins and the like.  Each page that I wanted to protect with security meant checking cookies for certain keys, looking those keys up, then checking against a static set of rules for permissions.  I spent weeks fixing the broken parts.  Because most of it was wrapped up in per-page scripts, I had to essentially recreate the whole mess when the customer decided they wanted to self-administer the storefront.

Today, so much of that mess is cleaned up for us.  I want to give you the steps to set up Authentication and Authorization in your next MVC web site.

  1. Open Visual Studio 2010 and create a new ASP.NET MVC 2 Web Application.

Yeup.  We’re done.

Walking Through What’s There

image

If you are familiar with the MVC pattern the default project is quite straightforward, but not entirely trivial.  There is no magic here, just convention and after working with the project for a few minutes you should be able to orient yourself.

The three basic concepts of MVC – Model, View and Controller – are expressed as classes and .aspx pages (as well as .ascx for partial pages and templates).  As part of the convention, each part has it’s own directory, and in the View folder we have subfolders for each controller.

The Project Components

What is relevant to us today are the items related to user accounts. You can see that there is an AccountController for us as well as the classes we need to log a user on in AccountModels.  The Account subfolder in Views gives us four pages dealing with account creation, maintenance and sign on.  Finally, the Shared subfolder in Views has a LogOnUserControl that displays different content based on the authentication status of the user.

At this point, we’re actually still missing a couple of pieces.  If you drill into your App_Data directory you would find that there is no database to hold your account data.  Thankfully, we don’t need to do much to create one; namely, we just use the site.

The Registration Process

Press F5 to start debugging the application.  When the site opens up you’ll see the default master page and index in action:

image

Follow the Log On link up in the top right corner of the page.  This will take you to a page with a form to log on, but also a link to the registration page. Follow that, and create an admin account.

imageOnce you’ve created your account you can return to the App_Data directory and see that the database has been created (you may need to click the show all button in the Solution Explorer).

The show all button looks like this: image

Authorization In An Attribute

This is where the easy kicks in.

To add authorization to your application you can make use of the attributes available to us in the ASP.NET MVC Framework.  It is as simple as adding one line of code to your controller.

Let’s turn our about page into something that only authenticated users can view.

image

Perfect! The [Authorize] attribute describes the controller action as something that only users who have been authenticated can access.  And now, when we load up our site, if we try to navigate to the About page prior to logging in you will be redirected to the login page.  To prove this, start debugging the site and add /home/about to your URL.  You’ll see this:

image

After logging in, you can see the About page in all its empty glory.  In fact, because your request was originally for the About page, the default AccountController pushes you through to that page once you’ve authenticated.

image

Some MVC Sweetness

Views in ASP.NET MVC inherit from the System.Web.Mvc.ViewPage object and therefor expose some interesting objects for us that we don’t have to work for to use.  Taking advantage of this fact allows us to shortcut to some features right in our views.

For example, the User object on our ViewPage allows us to test for authenticated users:

image

Or, we can test to see if they belong to roles in the ASP.NET membership/role provider:

image

While this can be super handy, it’s important to consider coding practices and whether or not your logic for such elements should be in your controller or your view.  This post will not enter that conversation, but it’s important to note that a similar roles-based approach is just as easy inside your controller:

image

Oh Yeah, About Those Roles

The easiest way to get roles going would be to navigate to the ASP.NET Configuration site.  You can enable and define roles from there:

image

This built-in administration tool simplifies the process of enabling roles on your site, adding existing users to roles and/or creating roles and bringing in existing users.  It also allows you to add a role to a user as you create them.  It’s tidy and functional, but doesn’t have many bells and whistles.

This isn’t the best for a production environment as the ASP.NET Configuration site is not deployed when you publish your app.  One solution would be to use a community-based console to help administer the site post-launch such as this one.

Some Reading Homework

I recently had the privilege of working with one of the authors of this book (Stephen Walther) and I can attest to the fact that these guys know this stuff inside and out.

ASP.NET 4 Unleashedcontains a ton of great information on using and abusing the .NET Framework when working on web applications, including a section devoted to the membership framework.

Conclusion

We’ve come a long way in web development.  Tasks that used to require “rolling your own” and a day or a week of dedicated time can now be reduced to simply clicking on “New –> Project”.

The beauty in that is that way that we can fully customize those bits, integrate them with our existing auth/auth stores and more.  We can choose our view engine (classic ASP.NET, MVC or now Razor).  We can integrate jazzy Ajax features through the fully supported jQuery libraries and its good-looking sister, jQuery UI.

It’s a good time to be a web developer.