The Web role was started in a wrong port

So you have started to trying out the Windows Azure Toolkit for Windows Phone 7, and created your first sample application. Then , when you launch the admin page, you get this error:

Sorry, an error occurred while processing your request.
WP7CloudApp1.Web.Infrastructure.RoleInWrongPortException: The Web role was started in a wrong port. For this sample application to work correctly, please make sure that it is running in port 443. Please review the Troubleshooting section of the sample documentation for instructions on how to do this.


Interesting. You notice that in the address bar, Internet Explorer has for some reason browsed to port 444 instead of the expected port 443. Looking at the documentation on MSDN for Azure, in the paragraph Testing an HTTPS endpoint in the compute emulator, one can find this little tidbit: If a port that you specify is not available, in the case of an HTTPS endpoint 443, the compute emulator will increment the port number until it finds one that is free.

And the Compute Emulator confirms the fact that is started to listen on port 444 instead:


So what’s is keeping port 443 busy?

Netstat –a –b says nothing of interest really, other than the fact that something is indeed listening on port 443 (and port 80 also, BTW):

Active Connections

Proto  Local Address          Foreign Address        State
TCP             Magnus-PC:0            LISTENING
Can not obtain ownership information
TCP            Magnus-PC:0            LISTENING
TCP            Magnus-PC:0            LISTENING
Can not obtain ownership information
So you start to close down the usual suspects, as IIs etc. but still something is listening on port 443.

It took me some time, but I finally figured it out…. SQL Server Reporting Services.


Maybe you are like me, when installing SQL Server, you opt in for all features, just in case… Well, this time it bit me hard.

Stopping the SQL Reporting Services Service, and restarting the Compute Emulator, my Windows Azure sample application for Phone 7 started to work again:


How to detect the dark or light theme in Windows Phone 7

If the user of the Windows Phone 7 device switches from the default dark theme to the light theme, how do you detect which one is in use? In the MSDN article Theme Resources for Windows Phone, there are two interesting resource keys that you can query. These are the PhoneDarkThemeVisibility and PhoneLightThemeVisibility keys. So based on these we can determine if we should use a dark or light background image in our application, like so:

var isLightTheme = (Visibility)Application.Current.Resources["PhoneLightThemeVisibility"];
var imageBrush = new ImageBrush();
var imageUri = new Uri(isLightTheme == Visibility.Visible ? "background-light.jpg" : "background-dark.jpg", UriKind.Relative);
imageBrush.ImageSource = new System.Windows.Media.Imaging.BitmapImage(imageUri);
MainPanorama.Background = imageBrush;

Windows Phone 7 Theme Colors

The Windows Phone 7 has two different background color modes; dark or light. In addition, there are ten accent colors to choose from.

image image

There’s currently no simple way of detecting which theme and accent color that the user has selected his or her device. However, since the colors of the current theme is injected into to applications resources, one can at least read out the various colors from there.

The background color can be determined using this piece of code:

Color backgroundColor = (Color)Application.Current.Resources["PhoneBackgroundColor"];

And in a similar fashion the foreground and accent colors can be determined like this:

Color foregroundColor = (Color)Application.Current.Resources["PhoneForegroundColor"];
Color accentColor = (Color)Application.Current.Resources["PhoneAccentColor"];

All the various resource names are described here; Theme Resources for Windows Phone.

Theme Background Color Value Foreground Color Value
Dark #FF000000 #FFFFFFFF
Light #FFFFFFFF #DE000000
Accent color Value
02-WP7-purple-accent #FFA200FF
03-WP7-teal-accent #FF00ABA9
04-WP7-lime-accent #FF8CBF26
05-WP7-brown-accent #FFA05000
06-WP7-pink-accent #FFE671B8
07-WP7-orange-accent #FFF09609
08-WP7-blue-accent #FF1BA1E2
09-WP7-red-accent #FFE51400
10-WP7-green-accent #FF339933