# Tuesday, May 19, 2009
Recently I tried to add a WCF based service channel to my NT-Service to be able to handle client requests from a GUI. I never noticed any problems with that kind of stuff so the more I was surprised as I got that error from the headline... Well the difference was that I usually worked (as developers mostly do ; ) with an useraccount which had administrative privileges. The service instead runs as a Network Service... interesting... even if it would be able to open a port and listen to it - it was not abled to use WCF to listen on an httpBinding. I found a few infos in the web but they were mostly regarding problems under Windows Vista and their solutions were all using netsh - which on my system (WinXP SP3) worked totally different so I skipped those experiments. Finally I found a much better Blogpost which featured some more solutions. On my system I succeeded by using the HttpNamespaceManager and adding the base-address (with that strange http://+:port/ Syntax) with access to the Network Service. So thx for that blog : )
Anyway - it might seem a little strange that a network service program can open any port and listen to it and maybe handle http-protocol by itself but not use some sort of windows-aided http-listening. So this may be more of a feature restriction than a real security issue I think...

Supplemental: I worked around that stuff by now with using a net.tcp binding instead of a Http. So - even it seems possible to add these http-stuff programmatically in the installer - this may be an alternative for someone too.
posted on Tuesday, May 19, 2009 10:39:48 AM (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Monday, March 30, 2009
Today I was adding a simple timeout functionality that should stop a thread after a period of time by calling thread.Abort(). It always did the right thing in my testProject so the more I was wondering why my actual thread survived the abort by just catching the exception instead of the usual pattern that even if the ThreadAbortException is caught it automatically will be re-thrown at the end of the catch (or at the end of the finally...) unless you disarm it by calling Thread.ResetAbort(). I did not call ResetAbort at all so I took a closer look to what I was doing in this thread... I was using IKVM to create a .NET library out of an JAVA-jar-file to use it from C#. The clou is, that ikvmc compiles java-Catch-Blocks to C# with an additional MapperCall and this will call ResetAbort which avoids rethrowing after the fellowing nested catch blocks. Not exactly what I expected but you deal with this behaviour easily since the exception is still thrown so you can add an extra catch Block for ThreadAbortException and exit as wanted.

posted on Monday, March 30, 2009 7:45:18 PM (W. Europe Daylight Time, UTC+02:00)  #    Comments [0]
# Friday, February 20, 2009
Since I was using ODBC to read/write Excel documents recently I was surprised not to have too much problems with it. Today a problem occured - funny thing because I was nearly through with changing the application to finally use SqlCE as persistency layer...
The problem was that we needed some large texts placed in some columns but excel just truncated it down to 255 chars (256 if you count the ' thats visible in excel). I didn't had much time to write some workaround at this point so I tested a little bit hoping to find a shorter workaround.
Of Course todays excel can handle more than 256 chars in a cell but when you save the document you'll get a warning for some incompatibility issues. Nice - file saved in "new" format - opened my program again - inserted a large text and ye......no - again truncated to 256 chars. So the ODBC driver seemed to switch back to old format. Since the driver seemed capable of handling xls files of office 12.0 (2007) according to the descriptions in the ODBC-Administration dialog I was looking for a simple way to make him use the new format. Finally I found something on the web saying that the driver determines the format by scanning some rows and while reading this I rememberd something I red earlier; there is an option "Rows to scan" in the ODBC-config and/or in the connection-string which was always set to 8. Well putting a large text in one cell in the first 8 rows and SUCCESS now even my application can write texts with more than 256 chars...
At this point I stopped testing so maybe it is possible to increase the RowsToScan variable to a max value or something - for me my quick and dirty workaround was done here ;-)

posted on Friday, February 20, 2009 5:52:47 PM (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
# Thursday, February 19, 2009
Today I wanted to Show a Modal Dialog until something was stored in the FormClosing event. For some reason at another point in an UnhandledExeptionHandler I called Application.Exit(). The result was another Exception "Collection was modified; enumeration operation may not execute"...
I was abled to reproduce this effect in a very simple WinForms-example with two forms and a button:
 private void button1_Click(object sender, EventArgs e)
 {
     Application.Exit();
 }

 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     using (var frm = new Form2())
     {
         frm.ShowDialog();
     }
 }
So the clue is that Application.Exit enumerates its forms and raises the FormClosing event - which... opens a window on its own and so modifies the Applications Form Enumeration which led to this bug.
btw a MessageBox.Show did NOT produce this problem maybe because its just mapped to an Win32 API-Call that wont modify the .NET-Applications-Formlist.
I worked around that problem by simply Closing the Window instead (or just before App.Exit).

posted on Thursday, February 19, 2009 12:06:51 PM (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
# Tuesday, February 03, 2009
A few days ago I was about to use the linq to SQL column property "Delay Loaded" for the first time. I wanted to return some plain data objects with an (propably larger) Image field left empty to load it later only if the entity would be selected in the GUI. So I used one Method to give me a set of objects with an empty image field and later another method to give me a specific image.
I already knew this Delay Loaded-Property would cause the creaton of a System.Data.Linq.Link<T> internally. So I thought as soon as I would do a read-access to that image-column the full content would be loaded from the database (though even write-accesses will imply a pre-read of that data so dont think about avoiding loading huge data by setting the field to another value).
I used my datacontext in a using block where I typically set the ObjectTrackingEnabled to false because I dont needed that if I only do readings to the DB. But in fact it turned out that this would also avoid loading fields that are "Delay Loaded" - so ObjectTrackingEnabled set back to true and everything worked fine as long as I initially accessed the image field inside the using-construct (ok that makes sense easily..).
I checked against the documentation where I found a short page about how to retrieve information as read-only and found out that setting OTE to false will also set DeferredLoadingEnabled to false and that would skip the expanding of one-to-one and one-to-many relations - BUT no word about Linq.Links :-)
Looking into the docs of DeferredLoadingEnabled also told me that if OTE is false DLE is not only set to false - its ignored completely - and again nothing about Delay-Loaded Fields. So maybe this info was helpful..

posted on Tuesday, February 03, 2009 3:54:21 PM (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
# Thursday, January 29, 2009
While using the Web Service Software Factory Modelling Edition to build up some WCF-Services I stumbled across a little Bug which was hard to find in the first place. While I was using the Host-Explorer to create my TestClient Proxies I noticed that some Endpoints led to creating wrong proxies where i.e. all Guids had been replaced by strings and many other stuff. Even with the Visual Studio Proxy generator some strange stuff occured such as generating classes like DoSomethingRequest1 which contained only one property of the Type DoSomethingRequest - so it seemed a bit of doublewrapped..
Finally I figured out what led to such behaviours: if you're designing a ServiceContract and putting more than one Message Part into a message you will get an Error saying that you have to set the "Is Wrapped"-Property of the message to True. This seems to be not a problem as long as the Request the message belongs to does not have another message associated (i.e. Request and Response) which has its "Is wrapped"-Property to False because it may have less than two Parts. Only if message is "wrapped" and one is not this problem occures so don't trap into that one ;-)

posted on Thursday, January 29, 2009 7:01:26 PM (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
# Wednesday, January 21, 2009
after a long journey of trying to get several WCF-STS-examples to run all at the latest failing at my selfmade certificates and endless hours of experimenting without exactly knowing what I was doing finally I found a simple but well explained blogentry which handles the basics of this stuff.
Part 1
Part 2

posted on Wednesday, January 21, 2009 6:00:19 PM (W. Europe Standard Time, UTC+01:00)  #    Comments [0]
-