Last post Nov 19, 2018 02:46 AM by UnVandy
Nov 13, 2018 04:24 AM|UnVandy|LINK
Dear all programmer !
when client request to my wcf url they need to login with header if username and password are wrong they can not use my wcf service
Have any resource please help share me !
Nov 14, 2018 09:58 AM|Abraham Qian|LINK
You could authenticate the client via windows identity,
I have made a demo, wish it is useful to you.
static void Main(string args)
Uri uri = new Uri("http://localhost:900");
WebHttpBinding binding = new WebHttpBinding();
binding.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
using (ServiceHost sh = new ServiceHost(typeof(MyService), uri))
ServiceEndpoint se = sh.AddServiceEndpoint(typeof(IService), binding, uri);
smb = sh.Description.Behaviors.Find<ServiceMetadataBehavior>();
smb = new ServiceMetadataBehavior()
HttpGetEnabled = true
Binding mexbinding = MetadataExchangeBindings.CreateMexHttpBinding();
sh.AddServiceEndpoint(typeof(IMetadataExchange), mexbinding, "mex");
Console.WriteLine("Service is ready");
public interface IService
public class MyService : IService
public string SayHello()
return "Hello Friend";
Nov 15, 2018 03:48 AM|UnVandy|LINK
I mean that when user request to my wcf service like http://localhost:50961/Service.svc it will show login form to authentication it is not when user request to url of method.
so if user input right username and password they will see and can use all my operation contract or method that have in my service
Thank for your help hope you can explain me again
i am waiting your answer Abraham Qian
Nov 15, 2018 07:30 AM|Abraham Qian|LINK
The SVC address is used to publish metadata address by default. If you want to protect the metadata, you can disable publishing the metadata. WCF authentication framework is the protection of WCF services, these two ideas are a little similar, but the client
authentication does not include metadata page. It is impossible that we achieve it via framework itself.
Nov 15, 2018 08:12 AM|UnVandy|LINK
I mean when user request to my wcf service or svc file it will show pop up dialog to login with username and password
Nov 16, 2018 07:59 AM|Abraham Qian|LINK
Yes, you could. Please refer to the above code, it will show the login dialog when you first access the website whose base address is
If you host the WCF service on the IIS, It corresponds to the IIS authentication mode.
Nov 19, 2018 02:46 AM|UnVandy|LINK
Dear Abraham Qian,
Thank you so much for your answer finally my wcf work with authentication by enable basic authentication and window authentication
Thank you !