<?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>AB-WebLog.com&#187; service</title>
	<atom:link href="http://www.ab-weblog.com/en/tag/service/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ab-weblog.com/en</link>
	<description>Andreas Breitschopp</description>
	<lastBuildDate>Wed, 18 Mar 2015 09:47:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>RemotingException Using IPC With .NET</title>
		<link>http://www.ab-weblog.com/en/remotingexception-using-ipc-with-net/</link>
		<comments>http://www.ab-weblog.com/en/remotingexception-using-ipc-with-net/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 23:13:49 +0000</pubDate>
		<dc:creator>Andreas Breitschopp</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[IPC]]></category>
		<category><![CDATA[remoting]]></category>
		<category><![CDATA[service]]></category>

		<guid isPermaLink="false">http://www.ab-weblog.com/en/?p=363</guid>
		<description><![CDATA[In a project I&#8217;m using IPC (Inter Process Communication) for sharing objects of a Windows service with a client application. This always worked correctly when the client application started the first time and used the objects of the Windows service. &#8230; <a href="http://www.ab-weblog.com/en/remotingexception-using-ipc-with-net/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In a project I&#8217;m using IPC (Inter Process Communication) for sharing objects of a Windows service with a client application.</p>
<p>This always worked correctly when the client application started the first time and used the objects of the Windows service. But starting the client application (without restarting the service) some minutes later again, resulted in a <em>RemotingException</em> with this strange error message:</p>
<pre class="brush: text; gutter: false">Failed to write to an IPC Port: The pipe is being closed.</pre>
<p>It took me quite long to figure out what the problem was:<br />
as it is important for my service to really have only one instance of the remote object for the whole lifetime of the service, I used <em>RemotingServices.Marshal</em> to register a previously instantiated object. But I did not know that objects registered with this method are only valid for a very short time period (one minute) by default.</p>
<p>To fix that you need to override the <em>MarshalByRefObject.InitializeLifetimeService</em> method within your remote server object like this:</p>
<pre class="brush: csharp; gutter: true">public override Object InitializeLifetimeService()
{
	ILease lease = (ILease)base.InitializeLifetimeService();
	if (lease.CurrentState == LeaseState.Initial)
	{
		lease.InitialLeaseTime = TimeSpan.FromDays(365);
		lease.SponsorshipTimeout = TimeSpan.FromDays(365);
		lease.RenewOnCallTime = TimeSpan.FromDays(365);
	}
	return lease;
}</pre>
<p>And here the same for VB .NET developers:</p>
<pre class="brush: vbnet; gutter: true">Public Overrides Function InitializeLifetimeService() As Object
	Dim lease As ILease = CType(MyBase.InitializeLifetimeService(), ILease)
	If lease.CurrentState = LeaseState.Initial Then
		lease.InitialLeaseTime = TimeSpan.FromDays(365)
		lease.SponsorshipTimeout = TimeSpan.FromDays(365)
		lease.RenewOnCallTime = TimeSpan.FromDays(365)
	End If
	Return lease
End Function</pre>
<p>OK, 365 days are probably a little bit exaggerated, but this way you can be really sure your remote objects won&#8217;t expire very fast. <img src='http://www.ab-weblog.com/en/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Did you come across this problem yourself already, too?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ab-weblog.com/en/remotingexception-using-ipc-with-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->