Skip to content

Commit

Permalink
Merge pull request #322 from jberezanski/wcf-client-channel-disposal
Browse files Browse the repository at this point in the history
Fix disposal of faulted WCF client channels
  • Loading branch information
jonorossi authored Sep 11, 2017
2 parents 5df1e1f + 769a0d6 commit 3df6e60
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2090,6 +2090,36 @@ public void CanDiscoverServiceEndpointInManagedMode()
}
}
}

[Test]
public void WillNotThrowUponClientContainerDisposalIfServerDies()
{
using (var serviceContainer = new WindsorContainer()
.AddFacility<WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
.Register(Component.For<Operations>()
.DependsOn(new { number = 28 })
.AsWcfService(new DefaultServiceModel()
.AddEndpoints(WcfEndpoint.ForContract<IOperations>()
.BoundTo(new NetTcpBinding { PortSharingEnabled = true })
.At("net.tcp://localhost/Operations2")
)
)))
{
using (var clientContainer = new WindsorContainer()
.AddFacility<TypedFactoryFacility>()
.AddFacility<WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero))
{
var factory = clientContainer.Resolve<IWcfClientFactory>();

var client = factory.GetClient<IOperations>(new Uri("net.tcp://localhost/Operations2"));

Assert.AreEqual(28, client.GetValueFromConstructor());
serviceContainer.Dispose();
factory.Release(client);
}
}
}

protected void RegisterLoggingFacility(IWindsorContainer container)
{
var logging = new LoggingFacility(LoggerImplementation.ExtendedLog4net);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ public WcfClientActivator(ComponentModel model, IKernelInternal kernel,

protected override void ApplyDecommissionConcerns(object instance)
{
base.ApplyDecommissionConcerns(instance);

// WCF channels have a _peculiar_ IDisposable implementation, which will throw if the channel is not closed gracefully.
// IWcfChannelHolder knows how to close/abort the channel properly, so it needs to be invoked first.
var channelHolder = (IWcfChannelHolder)instance;
channelHolder.Dispose();

base.ApplyDecommissionConcerns(instance);
}

protected override object Instantiate(CreationContext context)
Expand Down

0 comments on commit 3df6e60

Please sign in to comment.