Tuesday, May 27, 2008

Replacing the configuration in Web Deployment Projects

I am using Microsoft Web Deployment Projects in order to deploy automatically my nightly build on the development and test servers.

It worked great but I struggled quite some time trying to replace the configuration section.

Well, it was as stupid as that you cannot replace the whole system.serviceModel because it's not a configuration section, but is a configuration section group...and guess what?

WDP can only replace configuration sections and not configuration section groups.

What you can do though is replacing a section within the section group.

Within system.serviceModel, you can replace the client configuration section for instance using the replacement string "system.serviceModel/client=system.serviceModel.client.dev.config;"

Monday, May 26, 2008

SQL Code Prettifier from Simple-Talk

Use the Simple-Talk Prettifer to format your code (SQL, C#, VB and Python)http://extras.sqlservercentral.com/prettifier/prettifier.aspx in your web pages.

Update (23-March-10): I have been recently using http://www.manoli.net/csharpformat/, which does a better job and allow xml formatting.

Wednesday, May 14, 2008

Calling a WCF Service

Based on WCF best practices, calling a WCF service should not be wrapped in a using statement as exceptions can be raised (http://msdn2.microsoft.com/en-us/library/aa355056.aspx). Below is a code snippet highlighting the best practice:

ServiceClient client = new ServiceClient();

try
{
client.MyOperation
();
client.Close
();
}
catch (CommunicationException e
)
{
//Handle exception if necessary
client.Abort
();
}
catch (TimeoutException e
)
{
//Handle exception if necessary
client.Abort
();
}
catch (Exception e
)
{
//Handle exception if necessary
client.Abort
();
throw
;
}

However the code to write to do so is quite painful, hence I have written a VS code snippet (wcfproxycall.snippet) to minimize the pain.

To install the code snippet, simply copy the attached snippet to "My Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets"

When you need to call a proxy, type wcfproxycall in your code and hit the Tab key to expand the code snippet.

  • Fill the highlighted fields
  • Use the tab key to navigate to the next field
  • Hit Enter to complete when all fields are filled