[英]WCF self hosting require authentication
I will appreciate if I can have a hello world example of how can I make a client have to supply a specific username and password in order to consume a wcf service. 如果能有一个如何使客户端必须提供特定的用户名和密码才能使用wcf服务的例子,我将不胜感激。 I am self hosting my service therefore it is not on IIS.
我正在自我托管我的服务,因此它不在IIS上。
I have Server A and Client B. They are different computers on the same network. 我有服务器A和客户端B。它们是同一网络上的不同计算机。
I am using the default Service1
class that visual studio creates when creating a new WCF Class Library. 我正在使用Visual Studio在创建新的WCF类库时创建的默认
Service1
类。 So I create that service on Server A. 因此,我在服务器A上创建了该服务。
Then on Client BI add a service reference to that address which happens to be: http://10.10.1.135:8732/Design_Time_Addresses/WcfServiceLibrary1/Service1/mex
(Client B is a console app) 然后在客户端BI上添加对该地址的服务引用,该地址恰好是:
http://10.10.1.135:8732/Design_Time_Addresses/WcfServiceLibrary1/Service1/mex
: http://10.10.1.135:8732/Design_Time_Addresses/WcfServiceLibrary1/Service1/mex
: http://10.10.1.135:8732/Design_Time_Addresses/WcfServiceLibrary1/Service1/mex
(客户端B是控制台应用程序)
In order to consume that service I have to do: 为了使用该服务,我必须做:
static void Main(string[] args)
{
ServiceReference1.Service1Client svc = new ServiceReference1.Service1Client();
svc.ClientCredentials.Windows.ClientCredential.UserName = "MyUserName";
svc.ClientCredentials.Windows.ClientCredential.Password = "MyPassword";
var a = svc.GetData(5); // consume the service
}
Note I had to use the username and password of the domain user. 注意我必须使用域用户的用户名和密码。 How can I do something similar using a custom password?
如何使用自定义密码执行类似的操作? I do not want to have to provide those cridentials and I also do not want to create new users on windows.
我不想提供这些证书,也不想在Windows上创建新用户。 It will be nice if I could validate against a database.
如果我可以针对数据库进行验证,那就太好了。
Just Google it: 只是谷歌它:
http://codebetter.com/petervanooijen/2010/03/22/a-simple-wcf-service-with-username-password-authentication-the-things-they-don-t-tell-you/ http://codebetter.com/petervanooijen/2010/03/22/a-simple-wcf-service-with-username-password-authentication-the-things-they-don-t-tell-you/
Simple ones: 简单的:
http://blogs.msdn.com/b/pedram/archive/2007/10/05/wcf-authentication-custom-username-and-password-validator.aspx http://blogs.msdn.com/b/pedram/archive/2007/10/05/wcf-authentication-custom-username-and-password-validator.aspx
http://www.codeproject.com/Articles/431358/Selfhosted-Secure-WCF-by-Id-password-custom-valida http://www.codeproject.com/Articles/431358/Selfhosted-Secure-WCF-by-Id-password-custom-valida
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.