WCF Dispose problem with using statement

Posted on

WCF client cannot be used inside a Using block because they may unexpectedly throw an exception. Even if you catch the exception, it is possible that a connection will be left open. Why is this IDisposable implementation so different from all the others in the .NET Framework. The first problem with WCF clients is that […]

How to download MemoryStream as a file in zip

Posted on

Using the SharpZipLib it’s possible to zip and unzip files. This can be a good solution when file size matters. Downloading files that are ziped can save many bandwidth. In this case a object is serialized to XML and put into a ZipOutputStream which belongs to SharpZipLib. public static byte[] RetreiveBytes(IEnumerable<int> Ids) { MemoryStream stream […]

Using the XmlSerializer in multithreaded applications

Posted on

The XmlSerializer can cause serious problems in multithreaded environments. See this piece of code. [ThreadStatic] private static XmlSerializer xmlSerializer = new XmlSerializer(typeof(Mailpack), Namespace); private static string SerialiseAssemblageResultaat(Mailpack mailpack) { StringBuilder xmlString = new StringBuilder(); TextWriter xmlWriter = new StringWriter(xmlString); try { xmlSerializer.Serialize(xmlWriter, mailpack); return xmlString.ToString(); } finally { xmlWriter.Close(); xmlWriter.Dispose(); } } What we see […]

Secure WCF communication with certificates

Posted on

When having hosted a WCF webservice that is secured by a certificate. Opening the service with a browser al the security stuff is handled by the browser. This situation is different. The caller is a .NET Click-once application, that is hosted near the webservice. This application has to handle the use of the certificate by […]

Create and host your own NuGet packages

Posted on

NuGet is a package manager that simplifies the process of discovering, installing and using third-parties .NET libraries. It is free to download, open source and you are able to create your own package and submit them. In this post I’ll show how to create your own package and host them yourself. Requirements Visual Studio 2010 […]