<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Software Warlock &#187; .NET</title>
	<atom:link href="http://softwareblog.morlok.net/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://softwareblog.morlok.net</link>
	<description></description>
	<lastBuildDate>Sat, 10 Jul 2010 15:34:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Naming collision in ASMX web service</title>
		<link>http://softwareblog.morlok.net/2010/07/02/naming-collision-in-asmx-web-service/</link>
		<comments>http://softwareblog.morlok.net/2010/07/02/naming-collision-in-asmx-web-service/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 20:32:55 +0000</pubDate>
		<dc:creator>Warlock</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://softwareblog.morlok.net/?p=392</guid>
		<description><![CDATA[I ran into an interesting problem today while working on an ASMX web service.
Everything compiled fine, but when I went to view the ASXM in the browser to manually invoke the methods to test it, the normal automatically generated info page didn&#8217;t come up.  Trying to grab the WSDL also gave me a blank [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into an interesting problem today while working on an ASMX web service.</p>
<p>Everything compiled fine, but when I went to view the ASXM in the browser to manually invoke the methods to test it, the normal automatically generated info page didn&#8217;t come up.  Trying to grab the WSDL also gave me a blank page.</p>
<p>I then attached the debugger to IIS to observe what was happening when I tried to view the ASMX info page.  By breaking on exceptions, I was able to uncover the following error:</p>
<p><em>The XML element &#8216;XXX&#8217; from namespace &#8216;http://tempuri.org/&#8217; references a method and a type. Change the method&#8217;s message name using WebMethodAttribute or change the type&#8217;s root element using the XmlRootAttribute.</em></p>
<p>With a little more thinking, I was able uncover what I believe was going on.</p>
<p>I had defined a complex type to return as a response:</p>
<pre name="code" class="c#">
public class FooResponse {...}

[WebMethod]
public FooResponse Foo() {...}
</pre>
<p>Note that here the exact name pairing of Foo/Foo+Response is important. When I changed the method name as follows, the problem went away:</p>
<pre name="code" class="C#">
public class FooResponse {...}

[WebMethod]
public FooResponse Fooxxx() {...}
</pre>
<p>What I believe is happening is .NET is attempting to automatically wrap the response coming from the Foo method with an element named FooResponse. The use of that same name as the object you want to return creates ambiguity. By changing the name of my response object, or the name of my method I was able to avoid this collision.</p>
<p>I have also posted this information in response to a <a href="http://stackoverflow.com/questions/580042/c-web-service-client-multiple-web-service-methods-with-same-complex-return-ty/">question</a> on StackOverflow.</p>
]]></content:encoded>
			<wfw:commentRss>http://softwareblog.morlok.net/2010/07/02/naming-collision-in-asmx-web-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XSLT with Optional Extension Object</title>
		<link>http://softwareblog.morlok.net/2009/12/08/xslt-with-optional-extension-object/</link>
		<comments>http://softwareblog.morlok.net/2009/12/08/xslt-with-optional-extension-object/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 02:41:13 +0000</pubDate>
		<dc:creator>Warlock</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://softwareblog.morlok.net/?p=315</guid>
		<description><![CDATA[Extension objects provide a convenient way to allow an XSL transform to interact with the outside world.  They can also be used to offload computations that are difficult to express in XSL.

Recently, I ran into a scenario where I wanted to write an XSLT that would use an extension object to record some additional [...]]]></description>
			<content:encoded><![CDATA[<p>Extension objects provide a convenient way to allow an XSL transform to interact with the outside world.  They can also be used to offload computations that are difficult to express in XSL.</p>
<p>
Recently, I ran into a scenario where I wanted to write an XSLT that would use an extension object to record some additional information about intermediate steps of the transform.  The extension object was not required, however, and I wanted to leave it up to the user of the XSLT as to if they wanted to use the extension object.
</p>
<p>
The question then became how to conditionally execute calls to the extension object.  Suppose you have the following extension object defined in C#:
</p>
<pre name="code" class="C#">
public class FooExtensionObject
{
  private List&lt;string> recordedValues = new List&lt;string>();

  public void RecordValue(string val)
  {
    recordedValues.Add(val);
  }
}
</pre>
<p>Now suppose this extension object is used in the following XSLT:</p>
<pre name="code" class="xml">
&lt;xsl:transform
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:foo="urn:FooExObj">
  &lt;template match="/">
    ...
    &lt;xsl:value-of select="foo:RecordValue(@bar)"/>
    ...
  &lt;/template>
&lt;/transform>
</pre>
<p>The extension object is supplied to the XSLT through the arguments:</p>
<pre name="code" class="C#">
XslTransform transform = new XslTransform();
transform.Load("SomeFile.xsl");

XsltArgumentList args = new XsltArgumentList();
FooExtensionObject aFoo = new FooExtensionObject();
args.AddExtensionObject("urn:FooExObj", aFoo);

XmlTextWriter myWriter = new XmlTextWriter("output.xml", null);

transform.Transform(xpathDoc, args, myWriter);
</pre>
<p>
In the case where the extension object is not supplied, however, this XSLT will cause an error.  To correct this issue, you can use the <tt>function-available</tt> function.  Change the transform as follows:
</p>
<pre name="code" class="xml">
...
&lt;xsl:if test="function-available('foo:RecordValue')">
  &lt;xsl:value-of select="foo:RecordValue(@bar)"/>
&lt;/xsl:if>
...
</pre>
<p>
The conditional statement blocks out the use of the extension object when it does not exist.  Unfortunately, you must do this where ever you wish to use the extension object.</p>
]]></content:encoded>
			<wfw:commentRss>http://softwareblog.morlok.net/2009/12/08/xslt-with-optional-extension-object/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML Comments</title>
		<link>http://softwareblog.morlok.net/2009/11/24/xml-comments/</link>
		<comments>http://softwareblog.morlok.net/2009/11/24/xml-comments/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 02:21:01 +0000</pubDate>
		<dc:creator>Warlock</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[comment]]></category>
		<category><![CDATA[cref]]></category>
		<category><![CDATA[see]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://softwareblog.morlok.net/?p=309</guid>
		<description><![CDATA[Today I was looking for a reference for the proper notation for the cref attribute of the &#60;see cref="..."&#62; C# XML comment tag, and after finding it, I thought I&#8217;d post it here for future reference.

The cref (code reference) tag is prefaced by a single character, then a colon, followed by the reference in question. [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was looking for a reference for the proper notation for the <tt>cref</tt> attribute of the <tt>&lt;see cref="..."&gt;</tt> C# XML comment tag, and after finding it, I thought I&#8217;d post it here for future reference.</p>
<p>
The <tt>cref</tt> (<em>code reference</em>) tag is prefaced by a single character, then a colon, followed by the reference in question.  The character defines what is being referenced, as defined by the table below.</p>
<table>
<thead>
<tr>
<th>Character</td>
<th>Description</td>
</tr>
<tr>
</thead>
<tbody>
<td>N</td>
<td>Namespace</td>
</tr>
<tr>
<td>T</td>
<td>Type (class, interface, struct, enum, delegate)</td>
</tr>
<tr>
<td>F</td>
<td>Field (member variable, constant, etc)</td>
</tr>
<tr>
<td>P</td>
<td>Property (including indexers and indexed properties)</td>
</tr>
<tr>
<td>M</td>
<td>Method (including special methods like constructors &ndash; <tt>#ctor</tt> &ndash; operators, etc)</td>
</tr>
<tr>
<td>E</td>
<td>Event</td>
</tr>
<tr>
<td>!</td>
<td>Error string</td>
</tr>
</tbody>
</table>
<p>The full reference for the prefixes is available <a href="http://msdn.microsoft.com/en-us/library/fsbx0t7x.aspx">here</a>, with the full XML comment documentation available <a href="http://msdn.microsoft.com/en-us/library/b2s063f7.aspx">here</a>.  The Code Project also has an <a href="http://www.codeproject.com/KB/XML/csharpcodedocumentation.aspx">article on the topic</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://softwareblog.morlok.net/2009/11/24/xml-comments/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mapping Enums to custom strings in NHibernate</title>
		<link>http://softwareblog.morlok.net/2009/07/02/mapping-enums-to-custom-strings-in-nhibernate/</link>
		<comments>http://softwareblog.morlok.net/2009/07/02/mapping-enums-to-custom-strings-in-nhibernate/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 03:16:09 +0000</pubDate>
		<dc:creator>Warlock</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Enum]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Object-relational mapping]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://softwareblog.morlok.net/?p=294</guid>
		<description><![CDATA[
Many times when working with a legacy relation model and a newly developed C# object model that sits on top of the relational model, you may need to map enum values to/from arbitrary strings in the database using NHibernate.


For example, suppose you have a a work order object that three possible states: request, approved, denied. [...]]]></description>
			<content:encoded><![CDATA[<p>
Many times when working with a legacy relation model and a newly developed C# object model that sits on top of the relational model, you may need to map enum values to/from arbitrary strings in the database using NHibernate.
</p>
<p>
For example, suppose you have a a work order object that three possible states: request, approved, denied.  To represent this, you might use the following enum:
</p>
<pre name="code" class="c#">
enum WorkRequestState
{
    Request,
    Approved,
    Denied
};
</pre>
<p>But let&#8217;s assume that the legacy relational model has represented these values as strings: <tt>REQ</tt>, <tt>APR</tt>, <tt>DEN</tt>.  You can&#8217;t change the values for the relational model, and you certainly don&#8217;t want to use these values in your enum because they are not as readable as the values shown above.</p>
<p>By default, NHibernate will automatically convert you enum to a string value that matches the name of the enum values if the table field a string, or it will convert to the integer value for the enum options if the table field is an integer.</p>
<p>To do the above custom mapping we must implement a custom NHibernate type.</p>
<p>First, create a new class that inherits <tt>NHibernate.Type.EnumStringType</tt>.  In your constructor, pass the type of the enum you are handling, and the maximum number of characters that the enum values will be to the base class constructor:</p>
<pre name="code" class="c#">
class WorkRequestStateEnumStringType : NHibernate.Type.EnumStringType
{
    public WorkRequestStateEnumStringType()
        : base( typeof(WorkRequestState), 3)
    {
    }
    ...
}
</pre>
<p>Next, override the <tt>GetValue(...)</tt> method to map the enum value to the equivalent string.</p>
<pre name="code" class="c#">
public override object GetValue(object enm)
{
	if( null == enm )
		return String.Empty;

	switch( (WorkRequestState)enm )
	{
		case WorkRequestState.Request	: return "REQ";
		case WorkRequestState.Approved	: return "APR";
		case WorkRequestState.Denied	: return "DEN";
		default : throw new ArgumentException("Invalid WorkRequestState.");
	}
}
</pre>
<p>Override the <tt>GetInstance(...)</tt> method to map a string value to the equivalent enum value:</p>
<pre name="code" class="c#">
public override object GetInstance(object code)
{
	code = code.ToUpper();

	if( "REQ".Equals(code) )
		return WorkRequestState.Request;
	else if( "APR".Equals(code) )
		return WorkRequestState.Approved;
	else if( "DEN".Equals(code) )
		return WorkRequestState.Denied;

	throw new ArgumentException(
		"Cannot convert code '" + code + "' to WorkRequestState.");
}
</pre>
<p>Finally, in the NHibernate mapping file, specify the property&#8217;s type as the derived <tt>EnumStringType</tt> class.</p>
<pre name="code" class="xml">
&lt;class name="WorkRequest" table="work_request_table"&gt;
  &lt;property
    name="Status"
    column="status_field"
    type="my.namespace. WorkRequestStateEnumStringType, MyAssembly" /&gt;
  ...
&lt;class&gt;
</pre>
<p>Note that when specifying this type, you must use the <a href="http://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname.aspx">assembly-qualified name</a> because the NHibernate code doing the mapping is in a separate assembly from the type you created.</p>
<p>This information has been derived from Jeremy Miller&#8217;s original post <a href="http://codebetter.com/blogs/jeremy.miller/archive/2006/02/20/138732.aspx">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://softwareblog.morlok.net/2009/07/02/mapping-enums-to-custom-strings-in-nhibernate/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WPF Regular Expression Test Utility</title>
		<link>http://softwareblog.morlok.net/2009/06/16/wpf-regular-expression-test-utility/</link>
		<comments>http://softwareblog.morlok.net/2009/06/16/wpf-regular-expression-test-utility/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 01:07:11 +0000</pubDate>
		<dc:creator>Warlock</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Software Development Tools]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regular expression]]></category>

		<guid isPermaLink="false">http://softwareblog.morlok.net/?p=272</guid>
		<description><![CDATA[When working on .NET applications, I frequently need to test regular expressions I&#8217;m using in my code.  There are many good utilities out there to test regular expressions, but most are web-based and rely on Javascript for regular expression processing, which lacks support for .NET&#8217;s named captures.
In response, I built the a regex test [...]]]></description>
			<content:encoded><![CDATA[<p>When working on .NET applications, I frequently need to test regular expressions I&#8217;m using in my code.  There are many good utilities out there to test regular expressions, but most are web-based and rely on Javascript for regular expression processing, which lacks support for .NET&#8217;s named captures.</p>
<p>In response, I built the a regex test utility in WPF that has the following features:</p>
<ul>
<li>.NET syntax for regular expressions</li>
<li>Supports named capture groups</li>
<li>Gives real-time feedback (as you type) for the regular expression and the test input</li>
</ul>
<div id="attachment_273" class="wp-caption aligncenter" style="width: 310px"><a href="http://softwareblog.morlok.net/wp-content/uploads/2009/06/testregexscreenshot.png"><img src="http://softwareblog.morlok.net/wp-content/uploads/2009/06/testregexscreenshot-300x88.png" alt="Screenshot of regex tester." title="TestRegex screenshot" width="300" height="88" class="size-medium wp-image-273" /></a><p class="wp-caption-text">Screenshot of regex tester.</p></div>
<p>The binary requires .NET 3.5 and is available <a href="http://softwareblog.morlok.net/wp-content/uploads/2009/06/testregex.zip">here</a>. The source can be found on GitHub <a href="http://github.com/rmorlok/TestRegexWPF">here</a>.</p>
<p>Also, for those of you working with .NET regular expressions, I&#8217;ve always found <a href="http://www.regular-expressions.info/dotnet.html">this site</a> a great resource.</p>
]]></content:encoded>
			<wfw:commentRss>http://softwareblog.morlok.net/2009/06/16/wpf-regular-expression-test-utility/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ASP.NET 1.1 pages/assemblies take a long time on first load</title>
		<link>http://softwareblog.morlok.net/2009/05/18/aspnet-11-pagesassemblies-take-a-long-time-on-first-load/</link>
		<comments>http://softwareblog.morlok.net/2009/05/18/aspnet-11-pagesassemblies-take-a-long-time-on-first-load/#comments</comments>
		<pubDate>Mon, 18 May 2009 17:35:39 +0000</pubDate>
		<dc:creator>Warlock</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Authenticode]]></category>
		<category><![CDATA[certificate revocation list]]></category>
		<category><![CDATA[CRL]]></category>

		<guid isPermaLink="false">http://softwareblog.morlok.net/?p=229</guid>
		<description><![CDATA[The first time you load a page on an ASP.NET web site, or the first time you access a .NET web service, it may take significantly longer to load than subsequent accesses.  There are several things that can cause this, including the framework compiling the aspx source pages, but there can be an even [...]]]></description>
			<content:encoded><![CDATA[<p>The first time you load a page on an ASP.NET web site, or the first time you access a .NET web service, it may take significantly longer to load than subsequent accesses.  There are several things that can cause this, including the framework compiling the aspx source pages, but there can be an even more significant delay if you are using Authenticode-signed assemblies and your server does not have access to the internet.  In the case of web services, this delay may even be long enough to cause timeouts depending on the configuration of your client programs.</p>
<p>The problem is that as .NET loads Authenticode signed assemblies, it must check for updates on the certificate revocation list (CRL) to verify the signature on the assembly is valid.  If Active Directory is not configured to have the authority for CRLs on the local network and the server in question does not have a connection to the internet, the request for the CRL will time out after approximately 15 seconds, and .NET will continue loading the assembly and consider it to be unsigned.  This problem is discussed in <a href="http://www.dotnetscraps.com/dotnetscraps/post/ASPNET-Response-time-is-very-slow-for-the-first-request-to-application-(452b-seconds).aspx">several</a> <a href="http://blogs.msdn.com/dougste/archive/2008/02/29/should-i-authenticode-sign-my-net-assembly.aspx">articles</a>.</p>
<p>To verify this is what&#8217;s happening, you can use a packet sniffer on the server in question and look for the request for the CRL.  Using <a href="http://www.wireshark.org/">Wireshark</a>, I was able to observe the following behavior after I had stopped the World Wide Publishing service, started the trace, relaunched the World Wide Publishing service, and made a request:</a></p>
<div id="attachment_234" class="wp-caption aligncenter" style="width: 310px"><a href="http://softwareblog.morlok.net/wp-content/uploads/2009/05/packetsniffer.png"><img src="http://softwareblog.morlok.net/wp-content/uploads/2009/05/packetsniffer-300x17.png" alt="Request for CRL" title="Wireshark trace" width="300" height="17" class="size-medium wp-image-234" /></a><p class="wp-caption-text">Request for CRL</p></div>
<p>The above screenshot shows that a request was made for <tt>http://crl.microsoft.com/pki/crl/products/CodeSignPCA2.crl</tt> (IP address 96.17.76.91).</p>
<p>Note that the request will not always be made.  The CRL is always cached for the lifetime of a process, so if the IIS worker processes continue to run you will not get a request for the CRL.  It&#8217;s possible that the CRL is cached for longer, though I haven&#8217;t been able to verify that <a href="http://technet.microsoft.com/en-us/library/bb457027.aspx">this Microsoft Technet article</a> describes many things about the Windows PKI, including CRL caching.  I can replicate the above results when I first stop the World Wide Publishing service, clear the cached data from Internet Explorer, start the trace, start the World Wide Publishing, then make a request to the ASP.NET page/web service.  For computers that are not connected to the internet and have not been for a long time, I would guess any caching for the CRL would expire, and every time an Authenticode signed assembly is loaded Windows would try to refresh the CRL.  On Vista, you can explicitly refresh the CRL cache per <a href="http://blogs.technet.com/pki/archive/2007/09/13/how-to-refresh-the-crl-cache-on-windows-vista.aspx">this article</a>.</p>
<p>Resolving this issue on .NET 2.0 post SP1 is straightforward.  Setting the <tt>generatePublisherEvidence</tt> configuration option to false will skip the CRL check.  This issue is discussed in <a href="http://support.microsoft.com/kb/936707">Microsoft KB936707</a>.</p>
<p>On .NET 1.1, things are not as straightforward.  There isn&#8217;t a configuration setting to disable the authentication behavior.   The only solution is to <a href="http://blogs.msdn.com/alimaz/archive/2008/10/16/check-for-publisher-s-certificate-revocation-slowing-down-sharepoint.aspx">disable CRL checking for the entire machine</a>.  This can be accomplished through the following steps, originally described on <a href="http://digital.ni.com/public.nsf/allkb/18E25101F0839C6286256F960061B282">this website</a>.</p>
<ol>
<li>Open Internet Explorer</li>
<li>Go to <em>Tools</em> &mdash;&gt; <em>Internet Options&#8230;</em></li>
<li>Go to the <em>Advanced</em> tab</li>
<li>Locate the <em>Security</em> section and uncheck the <b>Check for publisher&#8217;s certificate revocation</b> option.<br />
<div id="attachment_233" class="wp-caption aligncenter" style="width: 250px"><a href="http://softwareblog.morlok.net/wp-content/uploads/2009/05/iesettings.png"><img src="http://softwareblog.morlok.net/wp-content/uploads/2009/05/iesettings-240x300.png" alt="Disable Check for publisher&#039;s certificate revocation option." title="IE Settings" width="240" height="300" class="size-medium wp-image-233" /></a><p class="wp-caption-text">Disable Check for publisher's certificate revocation option.</p></div></li>
</ol>
<p>CRL checking can also be disabled throughout the entire organization per <a href="http://technet.microsoft.com/en-us/library/cc738754.aspx">this Microsoft Technet article</a>.</p>
<p>Another option to address the symptoms as opposed to the underlying issue is to change the behavior of the IIS worker processes.   As mentioned previously, the CRL is cached throughout the lifetime of a process, so by managing the lifecyle of the worker process, you can force this timeout to come during non-work hours.</a></p>
<p>In IIS manager, view properties for the app pool under which your ASP.NET application is running.  Go to the <em>Performance</em> tab and disable the idle timeout of the worker processes.</p>
<div id="attachment_232" class="wp-caption aligncenter" style="width: 310px"><a href="http://softwareblog.morlok.net/wp-content/uploads/2009/05/apppool_performance.png"><img src="http://softwareblog.morlok.net/wp-content/uploads/2009/05/apppool_performance-300x283.png" alt="Disable worker process idle timeout" title="App Pool Performance Tab" width="300" height="283" class="size-medium wp-image-232" /></a><p class="wp-caption-text">Disable worker process idle timeout</p></div>
<p>Next, go back to the <em>Recycling</em> tab and set the processes to only recycle at a certain time of day (e.g. 2:00 a.m.).</p>
<div id="attachment_231" class="wp-caption aligncenter" style="width: 310px"><a href="http://softwareblog.morlok.net/wp-content/uploads/2009/05/apppool_recycling.png"><img src="http://softwareblog.morlok.net/wp-content/uploads/2009/05/apppool_recycling-300x283.png" alt="Change app pool recycling to non-business hours" title="App Pool Recycling" width="300" height="283" class="size-medium wp-image-231" /></a><p class="wp-caption-text">Change app pool recycling to non-business hours</p></div>
<p>The last step is to create a custom script that will make a request to your application shortly after the worker processes have been recycled.  This will force the CRL check at a time when it doesn&#8217;t matter how long the first request takes as normal user activity won&#8217;t be interrupted.</p>
]]></content:encoded>
			<wfw:commentRss>http://softwareblog.morlok.net/2009/05/18/aspnet-11-pagesassemblies-take-a-long-time-on-first-load/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enabling Browser-Based Invocation of ASP.NET 1.1 Web Services</title>
		<link>http://softwareblog.morlok.net/2009/04/27/enabling-browser-based-invocation-of-aspnet-11-web-services/</link>
		<comments>http://softwareblog.morlok.net/2009/04/27/enabling-browser-based-invocation-of-aspnet-11-web-services/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 03:15:46 +0000</pubDate>
		<dc:creator>Warlock</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://softwareblog.morlok.net/?p=191</guid>
		<description><![CDATA[
When working with web services it can be helpful to manually invoke them via a browser for testing purposes.  By default, .NET 1.1 is configured to let you do this from the machine on which you are running, but will not let you do it from other machines on the network.


To enable this feature [...]]]></description>
			<content:encoded><![CDATA[<p>
When working with web services it can be helpful to manually invoke them via a browser for testing purposes.  By default, .NET 1.1 is configured to let you do this from the machine on which you are running, but will not let you do it from other machines on the network.
</p>
<div id="attachment_203" class="wp-caption aligncenter" style="width: 310px"><a href="http://softwareblog.morlok.net/wp-content/uploads/2009/04/image002.jpg"><img src="http://softwareblog.morlok.net/wp-content/uploads/2009/04/image002-300x191.jpg" alt="ASP.NET without browser-based webservice invocation" title="feature disabled" width="300" height="191" class="size-medium wp-image-203" /></a><p class="wp-caption-text">ASP.NET without browser-based webservice invocation</p></div>
<div id="attachment_204" class="wp-caption aligncenter" style="width: 310px"><a href="http://softwareblog.morlok.net/wp-content/uploads/2009/04/image001.jpg"><img src="http://softwareblog.morlok.net/wp-content/uploads/2009/04/image001-300x225.jpg" alt="ASP.NET with browser-based webservice invocation enabled" title="feature enabled" width="300" height="225" class="size-medium wp-image-204" /></a><p class="wp-caption-text">ASP.NET with browser-based webservice invocation enabled</p></div>
<p>
To enable this feature from other computers on the network, edit the <tt>machine.config</tt> file located at <tt>C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\CONFIG\machine.config</tt>.  In this file, locate the section <tt>&lt;webServices&gt;</tt>.  In the <tt>&lt;protocols&gt;</tt> sub-section, add the following entry: <tt>&lt;add name="HttpPost"/&gt;</tt>.  This will result in the following configuration:</p>
<p><tt><br />
&lt;webServices&gt;<br />
&nbsp;            &lt;protocols&gt;<br />
&nbsp;&nbsp;              &lt;add name="HttpSoap1.2"/&gt;<br />
&nbsp;&nbsp;              &lt;add name="HttpSoap"/&gt;<br />
&nbsp;&nbsp;              <span style="color: green;">&lt;add name="HttpPost"/&gt;</span><br />
&nbsp;&nbsp;              &lt;add name="HttpGet"/&gt;<br />
&nbsp;&nbsp;              &lt;add name="HttpPostLocalhost" /&gt;<br />
&nbsp;&nbsp;              &lt;add name="Documentation"/&gt;<br />
&nbsp;            &lt;/protocols&gt;<br />
&nbsp;            &lt;soapExtensionTypes&gt;<br />
&nbsp;            &lt;/soapExtensionTypes&gt;<br />
&nbsp;            &lt;soapExtensionReflectorTypes&gt;<br />
&nbsp;            &lt;/soapExtensionReflectorTypes&gt;<br />
&nbsp;            &lt;soapExtensionImporterTypes&gt;<br />
&nbsp;            &lt;/soapExtensionImporterTypes&gt;<br />
&nbsp;            &lt;wsdlHelpGenerator href="DefaultWsdlHelpGenerator.aspx" /&gt;<br />
&nbsp;            &lt;serviceDescriptionFormatExtensionTypes&gt;<br />
&nbsp;            &lt;/serviceDescriptionFormatExtensionTypes&gt;<br />
        &lt;/webServices&gt;<br />
</tt></p>
<p>As a side note, it&#8217;s the <tt>&lt;add name="HttpPostLocalhost" /&gt;</tt> option in the <tt>&lt;protocols&gt;</tt> section that enables invoking the web services locally. All of these configuration settings are documented <a href="http://msdn.microsoft.com/en-us/library/b2c0ew36(VS.85).aspx">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://softwareblog.morlok.net/2009/04/27/enabling-browser-based-invocation-of-aspnet-11-web-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell Import-Csv Error</title>
		<link>http://softwareblog.morlok.net/2009/04/17/powershell-import-csv-error/</link>
		<comments>http://softwareblog.morlok.net/2009/04/17/powershell-import-csv-error/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 22:31:38 +0000</pubDate>
		<dc:creator>Warlock</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Import-Csv]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://softwareblog.morlok.net/?p=188</guid>
		<description><![CDATA[
I ran across the following error while working with a PowerShell script I was developing:


Import-Csv : Cannot process argument because the value of argument "name" is invalid.
Change the value of the "name" argument and run the operation again.


It had me stumped for a while.  The Impor-Csv command was failing, but the file name was [...]]]></description>
			<content:encoded><![CDATA[<p>
I ran across the following error while working with a PowerShell script I was developing:
</p>
<pre style="color: red;">
Import-Csv : Cannot process argument because the value of argument "name" is invalid.
Change the value of the "name" argument and run the operation again.
</pre>
<p>
It had me stumped for a while.  The <a href="http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/import-csv.mspx">Impor-Csv</a> command was failing, but the file name was good (I could cat the files contents to standard out).
</p>
<p>
Long story short, the error came from having trailing blank columns in my CSV.  Import-Csv uses the first row in the CSV as names for the columns (unless you specify otherwise) and when you have blank columns (or at least multiple blank columns) it causes this error as it doesn&#8217;t have a valid name for them.  The underlying culprit for the error was actually Microsoft Excel.  I was exporting a spreadsheet to a CSV and the spreadsheet had previously had some trailing columns.  I values to the columns, but apparently Excel decided they should still show up in the export.  Fully deleting the columns so they didn&#8217;t show up in the CSV resolved the problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://softwareblog.morlok.net/2009/04/17/powershell-import-csv-error/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Retrieving the Logged-in User&#8217;s Email via AD</title>
		<link>http://softwareblog.morlok.net/2009/04/02/retrieving-the-logged-in-users-email-via-ad/</link>
		<comments>http://softwareblog.morlok.net/2009/04/02/retrieving-the-logged-in-users-email-via-ad/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 23:05:42 +0000</pubDate>
		<dc:creator>Warlock</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Active Directory]]></category>

		<guid isPermaLink="false">http://softwareblog.morlok.net/?p=162</guid>
		<description><![CDATA[
I was writing a test utility yesterday and I wanted to get the email address for the user who is currently logged into the computer.  The only way I could think of was to query Active Directory for it, so I ended up with the following code:


using System.DirectoryServices;
using System.DirectoryServices.ActiveDirectory;

private string GetCurrentUserEmailAddress()
{
    [...]]]></description>
			<content:encoded><![CDATA[<p>
I was writing a test utility yesterday and I wanted to get the email address for the user who is currently logged into the computer.  The only way I could think of was to query Active Directory for it, so I ended up with the following code:
</p>
<pre name="code" class="csharp">
using System.DirectoryServices;
using System.DirectoryServices.ActiveDirectory;

private string GetCurrentUserEmailAddress()
{
    string ldapPath = "";
    string filter = "";

       Domain d = Domain.GetCurrentDomain();

       foreach (string e in d.Name.Split('.'))
       {
           if (ldapPath.Length > 0)
               ldapPath += ",";

           ldapPath += "DC=" + e;
       }

       ldapPath = "LDAP://" + ldapPath;
       filter = "(&#038;(objectClass=user)(SAMAccountName="
                     + System.Environment.UserName + "))";

       DirectoryEntry de = new DirectoryEntry(ldapPath);
       DirectorySearcher ds = new DirectorySearcher();
       ds.Filter = filter;

       SearchResult sr = ds.FindOne();

       if (null == sr)
           throw new Exception("Failed to get user for path '"
                    + ldapPath + "' and filter '" + filter + "'.");

       return sr.Properties["mail"][0].ToString();
}
</pre>
<p>
The basic gist of it is as follows:
</p>
<ol>
<li>Use the AD administrative classes to determine the active domain</li>
<li>Convert the domain into a valid LDAP path to act as the root of the query</li>
<li>Create a filter for the LDAP query using the login name of the user</li>
<li>Run the query against AD and pull down the user&#8217;s email address</li>
</ol>
<p>
I&#8217;ve only tested the above code on a few computers but it seems to work.</p>
]]></content:encoded>
			<wfw:commentRss>http://softwareblog.morlok.net/2009/04/02/retrieving-the-logged-in-users-email-via-ad/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Customizing Your Powershell Prompt</title>
		<link>http://softwareblog.morlok.net/2009/03/30/customizing-your-powershell-prompt/</link>
		<comments>http://softwareblog.morlok.net/2009/03/30/customizing-your-powershell-prompt/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 02:52:52 +0000</pubDate>
		<dc:creator>Warlock</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://softwareblog.morlok.net/?p=127</guid>
		<description><![CDATA[
Powershell is a great CLI for Windows and I appreciate it&#8217;s design more and more every time I use it.  As I interactive with for more and more tasks, wanted to customize it a bit so that it looked prettier, and so I could visually distinguish what was going on more easily.



One thing I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p>
Powershell is a great CLI for Windows and I appreciate it&#8217;s design more and more every time I use it.  As I interactive with for more and more tasks, wanted to customize it a bit so that it looked prettier, and so I could visually distinguish what was going on more easily.
</p>
<p><a href="http://softwareblog.morlok.net/wp-content/uploads/2009/03/image001.png"><img src="http://softwareblog.morlok.net/wp-content/uploads/2009/03/image001-300x203.png" alt="" title="my prompt" width="300" height="203" class="aligncenter size-medium wp-image-129" /></a></p>
<p>
One thing I&#8217;ve always done in the *NIX world was add color to my prompt so that it would be easy for me to tell where each command/output sequence started and ended.  To do this you need to edit (or create) the file <a href="http://www.leeholmes.com/blog/TheStoryBehindTheNamingAndLocationOfPowerShellProfiles.aspx"><tt>&lt;My Documents&gt;\WindowsPowerShell\Microsoft.PowerShell_profile.ps1</tt></a>
</p>
<p>
To determine how to render the prompt, Powershell calls a function, <tt>prompt</tt>.  To change the appearance, just implement this function in your profile.  Mine is as shown below:
</p>
<pre>
Write-Host -nonewline "Welcome to PowerShell "
Write-Host -nonewline -foregroundcolor Magenta $env:Username
Write-Host "!"
Write-Host " "

function prompt {
            Write-Host -nonewline -foregroundcolor Magenta "PS "
            Write-Host -nonewline -foregroundcolor Green $(get-location)
            Write-Host -nonewline -foregroundcolor Magenta " >"
            " "
}
</pre>
<p>Note that the output uses the <tt>-foregroundcolor</tt> flag with <tt>Write-host</tt> to change the output color.  Also note that built-in variables are used to determine context information, such as the current location.
</p>
<p><a href="http://mshforfun.blogspot.com/2006/05/perfect-prompt-for-windows-powershell.html">This</a> blog post worked a quick reference for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://softwareblog.morlok.net/2009/03/30/customizing-your-powershell-prompt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
