Friday, November 6, 2009

Code: Windows Server 2008 R2 and Microsoft Message Queuing (MSMQ)

We’re nearing the end of a large development project in which we used MSMQ extensively.  All of our queues are private and transactional.  For the most part MSMQ works great and serves its purpose excellently.  Save one glaring issue: We have had serious issues trying to send messages to the queues from remote machines.  All of the machines are in the same domain (and location).  We’ve had the environment set up on 3 different machines (for various reasons).  The first two installs we seemed to be able to post to the queues, although it took many tries changing security permissions on the queues and changing connection string formats (TCP vs OS).  On this 3rd environment we have been totally unable to send messages to the queues from a remote machine.  The messages get eternally stuck on the sending machines outgoing queue.  In the end we believe it to be an issue with the security lockdown of Server 2008 R2.

To get around the issue we had to install MSMQ HTTP Support and send the messages over HTTP.  To do this IIS must be already installed.  Then go into Features and enable Message Queuing > Message Queing Services > HTTP Support.  This will install a MSMQ Virtual Directory/Application on the default web site.  After that we just needed to change the connection strings to below and now things work great.

Code Snippet
  1. FormatName:DIRECT=HTTP://$/transcodejobqueue

Monday, November 2, 2009

Code: C# Hide Properties When Returning to Web Service

The automatic serialization built into the .Net Framework makes life easy when creating web services because it allows you to just return an object (or list of objects) and the framework will handle generating the XML return structure.  In the case where you have a property on an object that you don’t want returned in your web service method, you can add an an XmlIgnoreAttribute attribute to the property.

Code Snippet
  1. public class ReportInfo
  2. {
  3.     public string Title;
  4.     public decimal p95;
  5.     public DateParts DateBreakDown;
  6.     public List<ReportBase> Data;
  7.     //don't show this in web services
  8.     [System.Xml.Serialization.XmlIgnoreAttribute]
  9.     public List<TranscodingReportData> TranscodingData;
  10. }