[WcfFacility] Setting ClientCredentials client endpoint behavior

312 views
Skip to first unread message

Huseyin Tufekcilerli

unread,
Jun 1, 2009, 2:23:09 PM6/1/09
to Castle Project Users
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!

Craig Neuwirt

unread,
Jun 1, 2009, 2:42:51 PM6/1/09
to castle-pro...@googlegroups.com
You should be able to achieve the same thing by registering an implementation of IChannelFactoryAware and doing your 

channelFactory.Credentials.Windows.AllowedImpersonationLevel =
TokenImpersonationLevel.Impersonation;
channelFactory.Credentials.Windows.AllowNtlm = true;

in the Create method

Huseyin Tufekcilerli

unread,
Jun 2, 2009, 2:37:44 AM6/2/09
to Castle Project Users
Thanks, that seemed to be working :)

On Jun 1, 9:42 pm, Craig Neuwirt <cneuw...@gmail.com> wrote:
> You should be able to achieve the same thing by registering an
> implementation of IChannelFactoryAware and doing your
> channelFactory.Credentials.Windows.AllowedImpersonationLevel =
> TokenImpersonationLevel.Impersonation;
> channelFactory.Credentials.Windows.AllowNtlm = true;
>
> in the Create method
>
Reply all
Reply to author
Forward
0 new messages