如何在 Windows 身份验证中传递默认凭据
How to pass default credentials in Windows Authentication
我正在使用 C#.net 开发 UWP 应用程序,它具有启用了 Windows 身份验证的 WCF 服务。在使用添加服务引用选项使用服务调用后,我努力通过默认 NetworkCredential。
请看下面我的考试。
当我通过正确的 windows 身份验证凭据时,它按预期工作。
var service = new ServiceReference.Service1Client();
service.ClientCredentials.Windows.ClientCredential =new NetworkCredential("pradeep","****");
var test = await service.GetDataAsync(1);
但是,我想在使用我的服务 methis 时传递默认网络凭据
var service = new ServiceReference.Service1Client();
service.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
var test = await service.GetDataAsync(1);
我也尝试了以下选项。
service.ClientCredentials.Windows.ClientCredential = (NetworkCredential)CredentialCache.DefaultCredentials;
当我通过默认凭据时。我低于异常。
The HTTP request is unauthorized with client authentication scheme
'Negotiate'. The authentication header received from the server was
'Negotiate, NTLM'.
我在 WPF 应用程序中使用默认 NetworkCredential 测试了相同的服务调用,它按预期工作。
为了使用 System.Net.CredentialCache.DefaultNetworkCredentials 在 UWP 中传递 WCF Windows 身份验证的默认凭据,首先请确保您已添加企业身份验证和专用网络(客户端和服务器)功能如下:
对于 Enterprise Authentication 功能,这是因为 Windows 域凭据使用户能够使用其凭据登录到远程资源,并且就像用户一样提供了他们的用户名和密码。企业身份验证特殊功能通常用于连接到企业内服务器的业务线应用程序。
对于Private Networks(Client & Server)能力,是因为目前在Windows Runtime中我们只能通过Intranet中的默认凭证。对于 Internet,我们必须使用用户名和密码作为凭据。
有关功能的更多信息,请查看:
https://msdn.microsoft.com/en-us/library/windows/apps/hh464936.aspx.
之后请尝试使用您的计算机名或完全合格的计算机名而不是像这样的 WCF 服务的 IP 地址: http://YourComputerName:YourPortNumber/Service1.svc.
最后请使用另一台计算机作为客户端,使用 System.Net.CredentialCache.DefaultNetworkCredentials 测试 UWP 中的 WCF Windows 身份验证,然后它应该可以正常工作。
谢谢。
我正在使用 C#.net 开发 UWP 应用程序,它具有启用了 Windows 身份验证的 WCF 服务。在使用添加服务引用选项使用服务调用后,我努力通过默认 NetworkCredential。
请看下面我的考试。
当我通过正确的 windows 身份验证凭据时,它按预期工作。
var service = new ServiceReference.Service1Client();
service.ClientCredentials.Windows.ClientCredential =new NetworkCredential("pradeep","****");
var test = await service.GetDataAsync(1);
但是,我想在使用我的服务 methis 时传递默认网络凭据
var service = new ServiceReference.Service1Client();
service.ClientCredentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
var test = await service.GetDataAsync(1);
我也尝试了以下选项。
service.ClientCredentials.Windows.ClientCredential = (NetworkCredential)CredentialCache.DefaultCredentials;
当我通过默认凭据时。我低于异常。
The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate, NTLM'.
我在 WPF 应用程序中使用默认 NetworkCredential 测试了相同的服务调用,它按预期工作。
为了使用 System.Net.CredentialCache.DefaultNetworkCredentials 在 UWP 中传递 WCF Windows 身份验证的默认凭据,首先请确保您已添加企业身份验证和专用网络(客户端和服务器)功能如下:
对于 Enterprise Authentication 功能,这是因为 Windows 域凭据使用户能够使用其凭据登录到远程资源,并且就像用户一样提供了他们的用户名和密码。企业身份验证特殊功能通常用于连接到企业内服务器的业务线应用程序。
对于Private Networks(Client & Server)能力,是因为目前在Windows Runtime中我们只能通过Intranet中的默认凭证。对于 Internet,我们必须使用用户名和密码作为凭据。
有关功能的更多信息,请查看: https://msdn.microsoft.com/en-us/library/windows/apps/hh464936.aspx.
之后请尝试使用您的计算机名或完全合格的计算机名而不是像这样的 WCF 服务的 IP 地址: http://YourComputerName:YourPortNumber/Service1.svc.
最后请使用另一台计算机作为客户端,使用 System.Net.CredentialCache.DefaultNetworkCredentials 测试 UWP 中的 WCF Windows 身份验证,然后它应该可以正常工作。
谢谢。