Clean Namespace AddIn

One of my pet hates about Visual Studio is that it assumes that you organise folders in projects according to namespaces and adds folder names to the namespace declaration for classes.  Worse still there is no way to turn this behaviour off.

Usually I get by this by adding my classes to the root of the projec then dragging them to the relevant folder, and I strongly suggest that developers working for me do the same.  This week I came across a developer who complained about this and come up with reasons based around the lack of tool help if they forget to do this, so I decided to write an addin that automagically sets the namespace declaration of new C# classes added to match the Default Namespace setting in Project Properties.  I have called it Clean Namespace and published it on Visual Studio Gallery

No commands, menus or UI it just detects when a new C# class file is added to your project and changes the namespace declaration.  You can turn it off simply by disabling the addin via Tools, Add-in Manager...

Download Clean Namespace Visual Studio Installer

NavFx Updated for SL 2.0 Release

NavFx has been updated to work with the release version of Silverlight 2.0 and new downloads for binaries and templates are available at http://www.codeplex.com/NavFx

NavFx Part 2 - Setting Up

The next article on NavFX is now available and can be read here NavFx Part 2 - Setting Up

Silverlight Cross Domain WCF calls with VS WebDev.WebServer.exe

This one had me stuck for hours earlier this week, and judging by the number of posts on forums plenty of other people are suffering the same, so I hope this little titbit saves someone the frustration I suffered.

I am using Visual Studio 2008 to create a Silverlight 2.0 (beta 2 at the moment) application. In my solution I have two web site projects, one for hosting the application, the other to host WCF services.  All I want is to hit F5 and have both sites run in debug mode and my SL app call my WCF services and work.  So I set my projects up as I believed they should be via the properties sheet for the project root as follows.

  • Disabled dynamic ports so I know the fixed address of the WCF
  • Remove the virtual directory name to make both root applications
  • Add the following clientaccesspolicy.xml file to the root of the WCF site (wide open for now)

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
 <cross-domain-access>
  <policy>
   <allow-from>
    <domain uri="*"/>
   </allow-from>
   <grant-to>
    <resource path="/"
        include-subpaths="true"/>
   </grant-to>
  </policy>
 </cross-domain-access>
</access-policy>

So having written the code for my SL app to call my WCF service, references and all that stuff working fine I expect it all to work, I hit F5 in VS 2008 and both sites run, I can browse to the .svc file and get a working web page telling me how to create a client but in my SL application I get an error when I hit the button to call the service.

WTF? double check, tripple check, hours of googling to make sure I have done it right, that my clientaccesspolicy.xml file is right still not working.  I read hundreds of blog/forum posts and articles and still no clue.  Many talked about problems with WebDev.WebServer.exe not having a root to place the policy file in but I had that covered you can change it in the properties sheet for the project.   Still no luck.

Just when I was about to give up and wire my project up to IIS I re-read an article that I had spotted earlier about "Self Hosting" WCF services in a Windows Service and what was required in the policy file to support this.  Light bulb moment, WebDev.WebServer.exe may not be a Windows Service but it is effectively a "Self Hosting Process", a quick change to my clientaccesspolicy.xml file and bingo it works.  What did I change?  Look below at the attribute in bold on the <allow-from> element.

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
 <cross-domain-access>
  <policy>
   <allow-from http-request-headers="*">
    <domain uri="*"/>
   </allow-from>
   <grant-to>
    <resource path="/"
        include-subpaths="true"/>
   </grant-to>
  </policy>
 </cross-domain-access>
</access-policy>

So make this note in your little black book:

When it comes to web services (WCF or ASMX) WebDev.WebServer.exe is a Self Hosting Process and any requirements for self hosting apply.

NavFx Part 1 - Quick Reference

I have posted my first article on the navigation framework NavFx I created for Silverlight.  Took a little longer than expected as I actually had to get some work done.  You can read it here NavFx Part 1 - Quick Reference.

1st July 2008 - This article has been updated with some recent changes and enhancements made to NavFx.

 

Silverlight Navigation Framework

I am working on a navigation framework for Silverlight 2.* applications and will be posting a series of articles and the code over the coming days and weeks.

The first article Introducing Silverlight Navigation Framework  is available now.