maandag 27 juli 2009

WCF Client Proxy IDisposable - Generic WCF Service Proxy

Matt (I don't know his last name) blogged about an pattern to use to safely dispose WCF interface objects. See the link below, which points to his blog.

http://blog.weminuche.net/2008/08/test-post.html

Thanks Matt!!

dinsdag 21 april 2009

"Stateless": state machine framework

Nicholas Blumhardt mentions on his blog the open source software called Stateless. This is a library that facilitates in creating statemachines in software.

Exception Driven Development

This blog entry below mentions Exception Driven Development. This simply means that if an exception occurs in your software, first fix the exception handling code before solving the actual problem.

The main reason for this is that when the problem is fixed first, the exception handling code can't be tested anymore.

The blog entry also mentions ELMAH, which is an alternative to Windows Error Reporting.

woensdag 30 juli 2008

Omit the default namespace declarations when serializing an object

If you want to omit the default namespace declaration upon serializing an object to file, i.e.

xmlns:xsd="http://www.w3.org/2001/XMLSchema"

and

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance",

you should add a default (empty) namespace to the call to serialize the object. See below:



// Omit the standard namespaces from the output
XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add(string.Empty, string.Empty);

// Write the data to a the temp file using a xml writer
XmlSerializer serializer = new XmlSerializer(typeof(vodData));
using (XmlWriter writer = XmlWriter.Create(sourceFilePath, settings))
{
serializer.Serialize(writer, data, namespaces);
}

zondag 16 december 2007

XQeury with parameter in a DataSet

Today, I had to write a query that would retrieve a customerId from an xml data field in a SQL Server datatable. First of all, I noticed that the XQuery is case sensitive. After figuring this out, I started writing the query in SQL Server Management Studio and it started somewhat like this:
DECLARE @customerId NVARCHAR(1024)
SET @customerId = 'some subscriber id'
SELECT Id, Metadata
FROM Customers
WHERE Metadata.exist('/customerMetadata/subscriber[@Id=”@customerId"]') = 1
But wait… How do I make the distinction between an xml attribute and a variable? After googling for a while, I learned that I had to use the “sql:variable(‘@customerId’) construct for this. So I changed the query to:
DECLARE @customerId NVARCHAR(1024)
SET @customerId = ' some subscriber id '
SELECT Id, Metadata
FROM Customers
WHERE Metadata.exist('/customerMetadata/subscriber[@Id=sql:variable("@customerId")]') = 1
Happy as I was, I copied it into the “TableAdapter Query Configuration” Wizard of Visual Studio 2005. But I got disappointed again. The query wizard ended with the following messages (see picture below):
XQuery: Unable to resolve sql:variable(‘@customerId’). The variable must be declared as a scalar TSQL variable.


What I tried next was to manually add the variable to the variable collection of that query (see below).



And finally it worked! With some hope on better guidance, I tried the same query in Visual Studio 2008. Unfortunately, this had the same result.

woensdag 27 juni 2007

Xslt transformation to ASCII file and unicode characters

Today, I had to create a csv text file in plain ASCII text. The source data was in xml format.

The first solution that comes in mind is the use of an xslt transformation to tranform the xml file into the ASCII text file. However, the xml file can (and will) contain unicode characters. According to the spec, these characters must be replaced by a '^' character in the csv file.

This can be accomplished by specifying an Encoding type with an EncoderReplacementFallback instance. See the code below:

//Create an XsltArgumentList.
XsltArgumentList args = new XsltArgumentList();
...

// Create the transformation class
XslCompiledTransform xslt = new XslCompiledTransform(true);

// Load the xslt file
xslt.Load(config.TransformationFile);

// Create an encoding type so that unicode characters are translated into a '^'
Encoding encoding = Encoding.GetEncoding("us-ascii",
new EncoderReplacementFallback("^"),
new DecoderReplacementFallback("ERROR"));

// Create an XmlTextWriter to output to file.
using (TextWriter writer = new StreamWriter(csvOutputFilename, false, encoding))
xslt.Transform(reader, args, writer);

What happens here is that a 'us-ascii' Encoding type is created with an EncoderReplacementFallback instance. This ensures that all characters that are not part of the 'us-ascii' encoding are replaced by the '^' character.

This encoding is later used for creating the TextWriter with the specified encoding.

For more information see the microsoft documentation:
http://msdn2.microsoft.com/en-us/library/system.text.encoderreplacementfallback.aspx

maandag 18 juni 2007

Hi y'all

Hi everyone. It's me, Raymond Herwarts from Helmond, The Netherlands.

I'm new to blogs and I don't know if I have the patience and time to fill it on a regular basis. But I will give it a try.
(function($){ $(document).ready(function(){ dp.SyntaxHighlighter.BloggerMode(); dp.SyntaxHighlighter.ClipboardSwf = 'http://syntaxhighlighter.googlecode.com/svn/tags/1.5.1/Scripts/clipboard.swf'; dp.SyntaxHighlighter.HighlightAll('code'); }); })(jQuery);