WCF自托管需要身份验证 [英] WCF self hosting require authentication
问题描述
如果能有一个如何使客户端必须提供特定的用户名和密码才能使用wcf服务的问候示例,我将不胜感激.我正在自我托管我的服务,因此它不在IIS上.
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. I am self hosting my service therefore it is not on IIS.
我有服务器A和客户端B.它们是同一网络上的不同计算机.
I have Server A and Client B. They are different computers on the same network.
我正在使用Visual Studio在创建新的WCF类库时创建的默认 Service1
类.因此,我在服务器A上创建了该服务.
I am using the default Service1
class that visual studio creates when creating a new WCF Class Library. So I create that service on Server A.
然后在客户端B上,向该地址添加一个服务引用,该地址恰好是: http://10.10.1.135:8732/Design_Time_Addresses/WcfServiceLibrary1/Service1/mex
(客户端B是控制台应用程序)
Then on Client B I 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)
为了使用该服务,我必须要做:
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
}
请注意,我必须使用域用户的用户名和密码.如何使用自定义密码执行类似的操作?我不想提供这些凭据,也不想在Windows上创建新用户.如果我可以针对数据库进行验证,那就太好了.
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. It will be nice if I could validate against a database.
推荐答案
只需对其进行Google搜索:
Just Google it:
简单的:
http://www.codeproject.com/Articles/431358/Selfhosted-Secure-WCF-by-Id-password-custom-valida
这篇关于WCF自托管需要身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!