简体   繁体   中英

TransportWithMessageCredential: Windows credentials are not being passed to WCF service

I'm having problems setting up TransportWithMessageCredential on my wcf service.

Using the wcf Configuraton Editor, I set the Mode to TransportWithMessageCredential and the transportClientCredentialType to Windows in the web.config for the service and the app.config for my executable. I installed a self signed Cert on the erver and configured IIS to use it.

When I run my test app, I receive the following error: System.InvalidOperationException: The username is not provided. Specify username in ClientCredentials.

It appears that the Windows credentials are not being passed to the wcf service and when i check the credentialCache.defaultCredentials, they are null. Any clues and/or tips on why this is and how to fix it? Thanks in advance

server 2003 / IIS 6.0 on an active directory domain.

web.config for service

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

<basicHttpBinding>
    <binding name="WindowsTransportCredentialBinding" maxBufferSize="524288"
     maxReceivedMessageSize="524288">
        <readerQuotas maxDepth="128" maxStringContentLength="1048576" />
        <security mode="TransportWithMessageCredential">
            <transport clientCredentialType="Windows" proxyCredentialType="Windows" />
        </security>
    </binding>

app.config for executable

<client>
<endpoint address="https://U-WM-3vIntegr8/test/Web/Services/Diagnostic.svc"
    binding="basicHttpBinding" bindingConfiguration="ClientHttpEndpoint"
    contract="Test.IDiagnostic" name="ClientDiagnosticEndpoint" />
</client>


<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">
      <readerQuotas maxDepth="32" maxStringContentLength="1048576"
        maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="TransportWithMessageCredential">
        <transport clientCredentialType="Windows" proxyCredentialType="Windows"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
</basicHttpBinding>

...Called from client

public static IDiagnostic GetDiagnosticService()
{
    return new ChannelFactory<IDiagnostic>("ClientDiagnosticEndpoint").CreateChannel();
}

you need to manually fill in the credentials, they will not be automatically passed in this configuration. if that's what you look for you should set clientCredentialType to "Windows" on both client and server. Right now you need to set it manually:

proxy.ClientCredentials.Username.User = ""
proxy.ClientCredentials.Username.Password = ""

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM