Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix disposal of faulted WCF client channels #322

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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