4

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

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

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

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

客户端绑定

<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>

服务器绑定

<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();
4

1 回答 1

0

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

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

于 2013-12-04T12:22:57.977 回答