Reputation: 65
I'm currently trying to use TransportWithMessageCredentials and https on my wcf project. I have set both the client and the server security mode="TransportWithMessageCredential" and the clientCredentialType="Windows".
When I go to get the credentials from CredentialCache.DefaultNetworkCredentials, the username, password and domain are all empty.
Any reason why these would be empty? If they will always be empty, where would I get the credentials to pass?
How would I pass the logged in user credentials to the service without prompting them for a login?
Client binding
<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>
Server binding
<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>
Code to set the username and password
ChannelFactory<IDiagnostic> test = new ChannelFactory<IDiagnostic>(DIAGNOSTIC_ENDPOINT_NAME);
test.Credentials.UserName.UserName = "TestUser";
test.Credentials.UserName.Password = "User";
return test.CreateChannel();
Upvotes: 5
Views: 6608
Reputation: 897
The ICredentials instance returned by DefaultCredentials cannot be used to view the user name, password, or domain of the current security context.
Upvotes: 1