HI,
I'm trying to implement username authentication for a WCF service
(hosted in ServiceHost, not IIS) and once service starts it gets to
Faulted state if i specify:
tcpBinding.Security.Message.ClientCredentialType =
MessageCredentialType.UserName;
Here's the piece of code where service is being started (all settings,
e.g. endpoints, behaviors are set in code - there is no app.config in
the project):
//////-------------------------------
urlService = "http://localhost:8000/MyService";
host = new ServiceHost(typeof(ServiceLibrary.service1));
host.Opening += new EventHandler(host_Opening);
host.Opened += new EventHandler(host_Opened);
host.Closing += new EventHandler(host_Closing);
host.Closed += new EventHandler(host_Closed);
host.Faulted += new EventHandler(host_Faulted);
WSHttpBinding tcpBinding = new WSHttpBinding();
tcpBinding.TransactionFlow = false;
tcpBinding.Security.Mode = SecurityMode.Message;
tcpBinding.Security.Message.ClientCredentialType =
MessageCredentialType.UserName;
// Add a endpoint
host.AddServiceEndpoint(typeof(ServiceLibrary.ISer vice1), tcpBinding,
urlService);
ServiceMetadataBehavior metadataBehavior;
metadataBehavior =
host.Description.Behaviors.Find<ServiceMetadataBeh avior>();
if (metadataBehavior == null)
{
metadataBehavior = new ServiceMetadataBehavior();
metadataBehavior.HttpGetUrl = new
Uri("http://localhost:8000/MyService");
metadataBehavior.HttpGetEnabled = true;
host.Description.Behaviors.Add(metadataBehavior);
}
ServiceCredentials serviceCred =
host.Description.Behaviors.Find<ServiceCredentials >();
if (serviceCred == null)
{
serviceCred = new ServiceCredentials();
serviceCred.UserNameAuthentication.UserNamePasswor dValidationMode =
UserNamePasswordValidationMode.Custom;
serviceCred.UserNameAuthentication.CustomUserNameP asswordValidator = new
MyCustomUserNameValidator();
host.Description.Behaviors.Add(serviceCred);
}
host.Open();
//-------------------------------------------------------------------
If i don't put "tcpBinding.Security.Message.ClientCredentialT ype =
MessageCredentialType.UserName;" service starts and works (if i exclude
authentication) but of cource authentication doesn't work.
Any ideas what might be wrong?
Thank you,
MuZZy