4

現在、wcf プロジェクトで TransportWithMessageCredentials と https を使用しようとしています。クライアントとサーバーの両方のセキュリティ mode="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 に答える