如何在Windows身份验证中传递默认凭据

编程入门 行业动态 更新时间:2024-10-26 08:33:08
本文介绍了如何在Windows身份验证中传递默认凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用C#开发UWP应用程序,并且它具有启用Windows身份验证的WCF服务。在使用添加服务引用选项使用服务呼叫后,我无法通过默认的NetworkCredential。

I'm developing UWP application using C# and it has WCF service with Windows Authentication enabled. I struggling to pass default NetworkCredential after consume a service call using Add service reference option.

请在我的检查下方找到。

Please find below my examinations.

当我通过正确的Windows身份验证凭据时,它会按预期工作。

When I pass correct windows authentication credentials, it is working as expected.

var service = new ServiceReference.Service1Client(); service.ClientCredentials.Windows.ClientCredential =new NetworkCredential("pradeep","****"); var test = await service.GetDataAsync(1);

但是,我想在使用此服务时传递默认的网络凭据

but, I wanted pass default network credentials while using my service 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;

当我通过默认凭据时。我遇到了例外。

When I pass default credentials. I'm getting below exception.

HTTP请求已通过客户端身份验证方案 Negotiate进行了未授权的操作。从服务器收到的身份验证标头是'Negotiate,NTLM'。

The HTTP request is unauthorized with client authentication scheme 'Negotiate'. The authentication header received from the server was 'Negotiate, NTLM'.

我在默认的NetworkCredential中测试了相同的服务调用WPF应用程序按预期方式工作。

I tested same service call with default NetworkCredential in WPF application which is working as expected.

推荐答案

为了通过使用UWP传递UWP中WCF Windows身份验证的默认凭据, System.Net.CredentialCache.DefaultNetworkCredentials ,首先请确保您已添加企业身份验证和专用网络(客户端和服务器)功能如下所示:

In order to pass the default credentials for the WCF Windows Authentication in UWP by using the System.Net.CredentialCache.DefaultNetworkCredentials, first please make sure that you have added the Enterprise Authentication and Private Networks(Client & Server) capabilities as following:

对于企业身份验证功能,这是因为Windows域凭据使用户可以使用其凭据登录到远程资源,并像用户证明标识了他们的用户名和密码。企业身份验证特殊功能通常用于连接到企业内服务器的业务应用程序中。

For the Enterprise Authentication capability, it is because that Windows domain credentials enable a user to log into remote resources using their credentials, and act as if a user provided their user name and password. The enterprise Authentication special capability is typically used in line-of-business apps that connect to servers within an enterprise.

对于专用网络(客户端和服务器) 功能,这是因为当前在Windows运行时中,我们只能在Intranet中传递默认凭据。对于Internet,我们必须使用用户名和密码作为凭据。

For the Private Networks(Client & Server) capability, it is because that currently in Windows Runtime we can only pass the default credential in the Intranet. For the Internet we have to use the Username and Password as credential.

有关功能的更多信息,请检查: msdn.microsoft/en-us/library/windows/apps/hh464936。 aspx 。

For more information about the Capabilities, please check: msdn.microsoft/en-us/library/windows/apps/hh464936.aspx .

之后,请尝试使用您的计算机名称或完全合格的计算机名称 WCF服务的IP地址,如下所示: http:// YourComputerName:YourPortNumber / Service1.svc 。

After that please try to use your Computer name or Fully Qualified Computer name instead of the IP address for your WCF Services like this: YourComputerName:YourPortNumber/Service1.svc.

最后,请使用另一台计算机作为客户端,使用 System.Net.CredentialCache.DefaultNetworkCredentials 在UWP中测试WCF Windows身份验证,然后应该工作正常。

At last please use another computer as client to test the WCF Windows Authentication in UWP with the System.Net.CredentialCache.DefaultNetworkCredentials, then it should work fine.

谢谢。

更多推荐

如何在Windows身份验证中传递默认凭据

本文发布于:2023-11-17 05:55:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609067.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:凭据   身份验证   如何在   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!