05.10.08

Migrating a Silverlight v2 Beta 1 application that uses SQL Server 2005, WCF, LINQ, and ASP.NET v3.5, on the cheap, to GoDaddy.com

Posted in LINQ, SQL Server 2005, Silverlight, Visual Studio, WCF, XAML, XBAP at 8:36 pm by TalynOne



Recently I was involved in a project that used Silverlight v2 beta 1, SQL Server 2005, and a WCF service using LINQ in an ASP.NET v3.5 project. A link to an article describing this project will follow soon.

When looking for the most affordable web host that would support this application, fellow blogger & Silverlight aficionado Alan Cobb suggested GoDaddy.

GoDaddy's Windows Economy Plan seemed to fit the bill, it gave me access to 1 SQL Server 2005 database, ASP.NET v3.5 support, running under IIS v6 or v7 for around $9 for two months. That's a price that's hard to beat, but would it work? The short answer is yes, the long answer is that it requires some teeth pulling. I'll explain the gotchas, tips, and modifications necessary to successfully deploy such an application under GoDaddy's Windows Economy web hosting plan.



Silverlight MIME Types

When setting up a new web hosting account with GoDaddy, choose IIS 7, not IIS 6. With a new GoDaddy IIS 7 plan all the necessary MIME types should already be registered for you.

You may be asking, wait a minute, Silverlight is a client side technology, it should be supported on any web server, right? Well that's mostly correct. It is supported on any web server, as long as that server has the Silverlight required MIME types registered. When the Silverlight plug-in requests certain assets (such as .xaml or .xap files) it requires the web server hosting those files to have the correct MIME types registered for those file extensions. Every web server worth a grain of salt lets you configure MIME types. Though every web host, may not give you direct access or the ability to do so.

The Silverlight related MIME types include:

Extension MIME Type
.xap application/x-silverlight-app
.xaml application/xaml+xml
.xbap application/x-ms-xbap


The .xaml MIME type is mostly used by Silverlight v1.0 applications.

The .xap file is where all the Silverlight v2 assets are stored. It's stored in the "ClientBin" folder in a Silverlight v2 application. It's actually just a ZIP file, you can open it in any .ZIP capable application to see what's inside. The files inside typically include a .xaml file (the UI), Silverlight assemblies (.dll files), and embedded resources (.jpg,.wmv, etc..).

The .xbap MIME type is not necessary for Silverlight applications, but could be useful if you wish to deploy WPF XBAP applications.

When I initially created my GoDaddy account, I set it up as an IIS 6 account. I'm much more familiar with IIS v6 than v7, so I chose IIS v6 with the thinking that it's better to go with the devil you know. The IIS v6 account did not have the .xap MIME type registered. The symptom was that the Silverlight plug-in loads fine, but the application shows up as a blank white canvas, as the plug-in can't/didn't download the .xap asset properly. Tip to Microsoft: If the .xap asset can't be downloaded/processed properly in a timely manner, please show an error message, a blank white canvas is a bit disconcerting.

If you already have or must have IIS 6 under GoDaddy (if you need FrontPage Extensions, ColdFusion support, or have other reasons such as this or this), the following are your choices:
  1. Contact GoDaddy support and have them add the necessary MIME types for you. Some have had good luck with this, I did not.

    <Bad Customer Experience Rant Start>

    First, you should know, any support ticket under the Economy plan takes up to 24 hours to process (usually fewer than 12 hours). I guess you get what you pay for. Second, when I put in a ticket for them to add the MIME types they responded by e-mailing me information on how to do so myself using a web.config under IIS 7. That's all fine and dandy, but I was on a IIS 6 account, and the ability to configure MIME types using web.config files is only supported under IIS 7. So I got my support ticket re-opened and escalated. They responded that the MIME type would be added within 12 hours. After 12 hours, when my Silverlight application still did not work, I called in again and they informed me that the techs said the MIME type has been configured. When I explained that it had not been done properly, the rep, in not so many words, said, it is configured properly, I can't talk to the IIS admin directly, and that I don't know how MIME types work under GoDaddy. At this point I said screw it, I'm not going to get anywhere with this doofus, I told him to migrate me to IIS 7. Migrating from IIS 6 to IIS 7 under GoDaddy means canceling out my current IIS 6 web hosting account, getting a refund, and signing up for a new hosting account, this time choosing IIS 7 when setting up the account. After this was done, I was able to run simple Silverlight applications just fine without any additional configuration.

    </ Bad Customer Experience Rant End>

  2. Brad Abrams suggests a workaround where you rename the .xap file to .zip, and change the reference to the new extension in the application's .xaml file, and in the .aspx/.html file that hosts the Silverlight control.
If you're on another web host that's running IIS 7, but doesn't give you direct access to IIS MMC, you can configure mime types using a web.config file using this guide. Don't do this on a GoDaddy IIS7 account! Placing these directives in a Godaddy IIS 7 account, which already has these MIME type configured, will cause the server to spit out server configuration errors. Under IIS 6, these directives are ignored.

If you're hosting on your own IIS server, or on a different web server that gives you full access to the IIS 6/7 MMC, read this link for information on how to configure the MIME types.



WCF Services on web hosts with Multiple IIS Identities (GoDaddy)

WCF services hosted on IIS can only have one base address. Under some hosting configurations, such as GoDaddy's shared Windows Economy Plan, multiple base addresses exist. When attempting to access WCF services on an IIS with multiple base addresses, an exception similar to the following occurs:

This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: This collection already contains an address with scheme http. There can be at most one address per scheme in this collection.
Parameter name: item

The solution, using a combination of information found here and here, is to create a custom service factory and override the "CreateServiceHost" method. For Godaddy, I need to have it return the second base address found. The code below only returns the second base address when more than one exists, otherwise I return the first base address. This way I can share the same code base when using my local IIS/ASP.NET server, and GoDaddy IIS servers You may need to modify this code to return a different/custom base address depending on your application's needs.

Simply add the following class, as a sister class, in the service code behind file (yourservice.svc.cs):
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{                       
    // If more than one base address exists then return the second 
    // address, otherwise return the first address
    if (baseAddresses.Length > 1)
    {
        return new ServiceHost(serviceType, baseAddresses[1]);
    }
    else
    {
        return new ServiceHost(serviceType, baseAddresses[0]);
    }            
}


Then edit the markup in the .svc file (yourservice.svc), by adding the following attribute to the "ServiceHost" tag: (You can edit this file in any text editor, or by right-clicking on the file in Visual Studio 2008 solution explorer, and choosing the "View Markup" menu item):
Factory="YourWebProject_Web.CustomHostFactory"


WCF .svc files and GoDaddy

For some reason GoDaddy's IIS 7 server configuration doesn't have the buildprovider extension configured for the .svc file extension. This is easy enough to fix. Simply go to the ASP.NET project application folder and open up the web.config file, under the "<compilation>" tag, which is under the "<system.web>" tag, add the following directive:

<buildProviders>
    <add extension=".svc" type="System.ServiceModel.Activation.ServiceBuildProvider, 
         System.ServiceModel, Version=3.0.0.0, Culture=neutral,
         PublicKeyToken=b77a5c561934e089"/>
</buildProviders>




Setting up SQL Server on GoDaddy

This page has information how to create a SQL server database on the GoDaddy account. When you set up the database, you don't need the "DSN" option, as that's for older ODBC connections, which we won't be using. You should check/include the "ASP Schema" option. Don't worry, if you missed these options when you set up the database, you can go edit the database properties through GoDaddy's interface to add/remove these options as needed.

Exporting local SQL Server database to GoDaddy

If you wish to export a local SQL Server 2005 database schema/data to GoDaddy follow the infromation provided here & here.

Configuring LINQ/ASP.NET/WCF to connect to the GoDaddy SQL Server

  1. Find the database host address, database name, user id, and password for the SQL Server you wish to connect to. Information on how to do that is here
  2. Edit the web.config and find the "<connectionStrings>" section, change the "connectionString" attribute to:
    connectionString="Server=SQL_HOSTADDRESS; Database=SQL_DBNAME; User ID=SQL_USER_NAME; Password=SQL_DB_PASSWORD; Trusted_Connection=False"




Setting up IIS Application folder on GoDaddy

For ASP.NET application to work correctly, the folder that it's contained in must be set as an application folder. To do this on GoDaddy:
  1. Logon to the web hosting account ("Hosting & Servers" menu, "My Hosting Account" sub menu item).
  2. Click on the "Manage Account" link next to the domain you wish to configure.á
  3. Under the "Content" menu item, choose the IIS Settings sub menu item.
  4. Click on the "Create" button and set the "Directory Name:" textbox value to the same name as folder you wish to place the ASP.NET application in.
  5. Make sure to select the "Set Application Root" option.
  6. Press the "OK" button.
Configuring a Cross-Domain Policy File (clientaccesspolicy.xml)

If you wish to debug a Silverlight application, which accesses an on-line server's WCF service, through a locally running instance of Visual Studio, you must configure a cross-domain policy file. You may also need a cross-domain policy file configured if the base address returned by "CreateServiceHost" is not interpreted as a local address by the WCF service (covered in the "WCF Services on web hosts with Multiple IIS Identities (GoDaddy)" section above).

For a full explaination of how to create cross-domain policy files, this article is a good read.

Karen Corby's three part article on site of origin, cross domain communication, and configuring a cross domain policy file is also a good read on the details of how Silverlight handles communication.

Uploading the project

I always found it surprising that there's very little documentation detailing which files are actually need for a deployed application to run. When you look at the solution file you will see many files (.sln, .csproj, .aspx, .dll, .dbml, .cs, .svc, folders, etc...). But to deploy an application only a few of these files and folders are needed. The folders/files that actually needed for an application to run include:
  1. Any .aspx and/or .html files that the application uses. A Silverlight web application project usually creates a default.aspx and default.html, which aren't actually used/needed for anything. You probably will want to rename the startup .aspx or .html file to default.aspx or default.html. When the startup file is named "default.aspx/default.html" then users can access the application without specifying the application file name (http://www.yoursite.com/yourappfolder/ instead of http://www.yoursite.com/yourappfolder/yourapp.aspx).
  2. The WCF .svc file, this file associates a service with its implementation and is the means for IIS to create a ServiceHost for you. For further reading, this article details hosting and consuming WCF services.
  3. The "web.config" file in the web project folder. Information on the web.config file can be found in many places, including here, here, and here.
  4. The "bin" folder (ASP.NET assemblies) in the web project folder.
  5. The "Clientbin" folder (Silverlight assemblies/assets) in the web project folder.
  6. Any assets referenced by Silverlight, HTML, and ASP.NET sources, such as images, videos, etc...


Reconfiguring Silverlight WCF Service Reference Location

If the Silverlight application is currently pointed to a locally hosted WCF service location, and you wish to point it to an on-line/different WCF service location, the process is simple.
  1. Go to the Visual Studio Solution Explorer, and right-click on the server reference (under the "Server References" folder)
  2. Choose the "Configure Service Reference" menu item.
  3. Set the "Address:" text box value to the URL of the WCF .svc file (http://www.yourserver.com/yourappfolder/yourservice.svc).
Debugging Silverlight/WCF

06.17.07

XBAP Greeting Card by Alan Cobb

Posted in WPF, WPF Animations, XBAP at 3:27 pm by Cal

Alan Cobb

www.alancobb.com

Alan is a friend of mine from Sacramento who is taking my Spring 2007 WPF class. I knew before Alan took this class that he was a talented developer but I had to raise my eyebrows when I noticed that he consistently scored 100% of all of the tests. I’ve been teaching for quite a while and I can assure you that that doesn’t happen very often.

I asked Alan if instead of the regular lab assignments he would mind working on a Greeting Card project which I could then incorporate into one of my MSDN webcasts (coming up on June 21st). The format which Alan chose was an XBAP application. He decided for the first project to create a baby announcement. After digging through my collection of 70,000 digital photos I selected a baby picture which I took last summer of the daughter of a couple of my friends from the Netherlands.

Alan’s Greeting Card illustrates quite a few WPF features including several different animations and audio. For a complete list of features illustrated, see the Documentation page.

04.28.07

Moving or Renaming an XBAP Application

Posted in XBAP at 10:57 am by Cal

One problem which can arise if you move an XBAP project or rename one of the folders in its path is that the application will no longer run in debug mode.? Compounding this problem is the fact that the output window is completely blank and doesn’t give you any clues as to what the potential cause of this problem is.?

To solve this problem turn to the Debug tab in project properties. The start action should already be set to your local instance of PresentationHost.exe. You should not change this since XBAPs require this document host in order to run in Internet Explorer.? Turn, however, to the command line arguments.? If you are like me, most likely you will not be able to see the entire value for this setting because the textbox is too small to accommodate it*.? I recommend copying this value to the clipboard and pasting it into Notepad (or any other handy text editor).? I expect that you will find that the path shown in this value will reflect the old location for your XBAP application and not the new one.? Simply modify this setting to accurately reflect the new path for your XBAP, paste it back into the inadequately sized textbox for this setting and your debugging capability should be restored.?

You can find an excellent summary of XBAP debugging at the Nerddawg blog.*

? One of my biggest pet peeves is keyhole programming — textboxes which are too small to fully display the entire string which they contain.? The authors of the XML standard have said that in the trade off between brevity and clarity, clarity should prevail 100% of the time.? In my opinion, in the trade off between appearance and functionality, functionality should win at least 99% of the time.?

04.21.07

Introducing TravelsWithCal.com WPF Zone

Posted in XBAP at 8:09 pm by Cal

As indicated in a previous post, I recently developed a little XBAP application to display photos of Senegal (West Africa).? I started with the Felipe Fortes model and added a few minor embellishments — such as animating the images? in my list box.? You can see this application at TravelsWithCal.Com/wpfzone.?

You must use either Internet Explorer 6 or 7 and you must have Version 3.0 of the .NET Framework installed in order to view this XBAP application.

04.15.07

XBAP Deployments

Posted in Deployments, XBAP at 6:55 pm by Cal

Man -- Kaolack, Senegal, West Africa
Recently I made a little XBAP application to display photos of Senegal (West Africa) using the Filipe Fortes model. Since I would like for the public to be able to view this application from my website over the Internet, I decided to step through the process to deploy my XBAP application.

First, using Visual Studio, I published the application to an IIS Virtual Directory on my local computer. A brief test showed that just this step was not sufficient for me to view my app in any version of Internet Explorer.

Typically (as in my case) some minor configuration changes are required to IIS in order to successfully access an XBAP application. Microsoft has instructions for this on the MSDN website. Essentially there are just two steps: (1) Set Enable Content Expiration to one minute and (2) register a series of Mime types. For your convenience Microsoft has provided a .vbs script that will register the mime types for you automatically if you simply run it from a command window. As soon as I finished these two steps, I was able to successfully view my locally deployed XBAP application in both IE 6 and 7.

Next I uploaded my application (via FTP) to a Unix web server (running Apache) where we host some of our web content. I was pleasantly surprised to see that without any configuration changes I was able to see my application using IE 7. However, IE 6 showed me some XML text (as of course did Firefox) instead of the actual content of my application.

The documentation for our web server suggested using the AddType method in the httpd.conf file so I added the following lines to this file:

AddType application/manifest .manifest
AddType application/xaml+xml .xaml
AddType application/x-ms-application .application
AddType application/octet-stream .deploy
AddType application/x-ms-xbap .xbap
AddType application/vnd.ms-xpsdocument .xps

Then I uploaded the revised version of httpd.conf to my website and restarted Apache.

This solved the problem for IE 6, although Firefox still won’t display XBAP applications. However, I did have to close IE 6 and reopen it to flush its cache before it worked correctly.

Also, with the Mime types now registered, Firefox displays a download prompt instead of the contents of the manifest. Since downloading this file with Firefox is pointless, I decided to put a page in my website which explains the requirements of an XBAP application (Internet Explorer 6 or 7 and .NET 3.0) Instead of giving out a link directly to the XBAP application I will give people a link to my gatekeeper page from which they can then proceed to my XBAP applications. Anyone who doesn’t meet the requirements can simply download and install them before attempting to access my XBAPs. More importantly if anyone experiences a problem viewing any of my XBAPs, he will have an explanation of what is causing this problem and how to solve it.