gpt4 book ai didi

wcf - 使用 TransportWithMessageCredential 时 CredentialCache.DefaultNetworkCredentials 为空

转载 作者:行者123 更新时间:2023-12-03 17:56:31 25 4
gpt4 key购买 nike

我目前正在尝试在我的 wcf 项目中使用 TransportWithMessageCredentials 和 https。我设置了客户端和服务器安全模式="TransportWithMessageCredential"和clientCredentialType="Windows"。

当我从 CredentialCache.DefaultNetworkCredentials 获取凭据时,用户名、密码和域都是空的。

有什么理由为什么这些会是空的?如果它们始终为空,我将在哪里获得要通过的凭据?

如何在不提示他们登录的情况下将登录的用户凭据传递给服务?

客户端绑定(bind)

<basicHttpBinding>
<binding name="ClientHttpEndpoint" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:02:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="4194304" maxBufferPoolSize="524288" maxReceivedMessageSize="4194304"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>

服务器绑定(bind)
<basicHttpBinding>
<binding name="WindowsTransportCredentialBinding" maxBufferSize="524288"maxReceivedMessageSize="524288">
<readerQuotas maxDepth="128" maxStringContentLength="1048576" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>

...

<service name="Test.DiagnosticService">
<endpoint binding="basicHttpBinding" bindingConfiguration="WindowsTransportCredentialBinding" name="ClientDiagnosticEndpoint" contract="Test.IDiagnostic" />
</service>

设置用户名和密码的代码
ChannelFactory<IDiagnostic> test = new ChannelFactory<IDiagnostic>(DIAGNOSTIC_ENDPOINT_NAME);
test.Credentials.UserName.UserName = "TestUser";
test.Credentials.UserName.Password = "User";
return test.CreateChannel();

最佳答案

DefaultCredentials 返回的 ICredentials 实例不能用于查看当前安全上下文的用户名、密码或域。

http://msdn.microsoft.com/en-us/library/system.net.credentialcache.defaultcredentials%28v=vs.90%29.aspx

关于wcf - 使用 TransportWithMessageCredential 时 CredentialCache.DefaultNetworkCredentials 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10744548/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com