I am trying to set the a ClientCredentials IEndpointBehavior on my WCF
client (1) but when I try to resolve a proxy of contract type
ICustomerService, I get the following exception:
The value could not be added to the collection, as the collection
already contains an item of the same type:
'System.ServiceModel.Description.ClientCredentials'. This collection
only supports one instance of each type.
Parameter name: item
(obviously this behavior is a built-in one on ChannelFactory<T> and
doesn't let me put another one)
// CODE *****************************************
var binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.Transport;
binding.Security.Transport.ClientCredentialType =
TcpClientCredentialType.Windows;
// (1) *****************************************
var clientCredentials = new ClientCredentials();
clientCredentials.Windows.AllowedImpersonationLevel =
TokenImpersonationLevel.Impersonation;
clientCredentials.Windows.AllowNtlm = true;
// (1) *****************************************
var address = new EndpointAddress(
new Uri("net.tcp://
host.domain.com:8182/Mind2Biz/
CustomerService"),
EndpointIdentity.CreateSpnIdentity("CustomerService/
host.domain.com"));
var clientModel = DefaultClientModel.On(WcfEndpoint
.ForContract<ICustomerService>()
.BoundTo(binding)
.At(address));
var container = new WindsorContainer()
.AddFacility<WcfFacility>()
.Register(
// (1) *****************************************
Component.For<ClientCredentials>().Instance
(clientCredentials),
// (1) *****************************************
Component.For<ICustomerService>().ActAs
(clientModel).LifeStyle.Transient
);
// (2) *****************************************
var proxy = container.Resolve<ICustomerService>();
// (2) *****************************************
Normally, without Castle WCF Facility, I would set that already
existing
Credentials on channel factory like this:
var channelFactory = new ChannelFactory<ICustomerService>(binding,
endpointAddress);
channelFactory.Credentials.Windows.AllowedImpersonationLevel =
TokenImpersonationLevel.Impersonation;
channelFactory.Credentials.Windows.AllowNtlm = true;
How can I modify this existing ClientCredentials on my WCF Channel
Factory using Castle WCF Facility? Thanks!