0

I did a search on this issue and at least the exception message is similar to the following article. HTTP Request unauthorized for NTLM

I have a WCF configuration file that is using custom bindings that work for Named Pipes, Tcp, and now I am attempting to use with HTTP. Additionally, I am attempting to connect to the HTTP Service without IIS which is adding to the challenge. I am able to connect my client to the service using the HTTP configuration for http://localhost so this works for the same computer and user. For a moment, I thought everything was working.

When attempting to connect to a remote computer, I get an exception that states 'The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'NTLM''. If I configure Anonymous instead of Ntlm for the httpTransport Authentication Scheme, I get a similar message 'The HTTP request is unauthorized with client authentication scheme 'Anonymous''.

I am experiencing a security problem when connecting to a remote service but I would like to resolve this using the custom bindings that I have configured. I am using custom bindings since 1) this works well with named pipe/Tcp and 2) I am using chunking to exchange large messages (all of which works locally)

I am using a WCF configuration file to generate my service and endpoint. My configuration is as follows.

<configuration>
    <system.serviceModel>
        <services>
            <service behaviorConfiguration="HttpBehavior" name="HttpConnection">
                <endpoint address="Task" behaviorConfiguration="SynchronousBehavior"
                    binding="customBinding" bindingConfiguration="HttpChunkingBinding"
                    name="HttpChunking" contract="MyTask.Interfaces.ITask, Common" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://Server/Test/PerfProject/TaskName" />
                    </baseAddresses>
                </host>
            </service>
            <service behaviorConfiguration="HttpBehavior" name="HttpConnectionNoChunking">
                <endpoint address="Task" behaviorConfiguration="" binding="customBinding"
                    bindingConfiguration="HttpBinding" name="HttpChunking" 
                    contract="MyTask.Interfaces.ITask" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://Server/Test/PerfProject/TaskName" />
                    </baseAddresses>
                </host>
            </service>
         </services>
        <endpointBehaviors>
            <behavior name="SynchronousBehavior">
                <synchronousReceive />
            </behavior>
        </endpointBehaviors   
        <serviceBehaviors>
            <behavior name="DebugBehavior">
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
            <behavior name="limitedAuthBehavior">
                <serviceAuthenticationManager authenticationSchemes="Digest, Negotiate, Basic, 
                Anonymous" />
            </behavior>
            <behavior name="HttpBehavior">
                <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                <serviceCredentials>
                    <userNameAuthentication userNamePasswordValidationMode="Windows" />
                    <windowsAuthentication allowAnonymousLogons="true" />
                </serviceCredentials>
            </behavior>
        </serviceBehaviors>
        <bindings>
           <customBinding>
           <binding name="HttpChunkingBinding" receiveTimeout="00:01:00"
                sendTimeout="00:05:00">
                <chunking />
                <reliableSession />
                <compositeDuplex />
                <oneWay />
                <textMessageEncoding />
                <httpTransport maxReceivedMessageSize="524288" authenticationScheme="Ntlm"
                    maxBufferSize="524288" proxyAuthenticationScheme="Ntlm" 
                    unsafeConnectionNtlmAuthentication="true" />
            </binding>
            <binding name="HttpBinding" receiveTimeout="00:01:00" sendTimeout="00:00:10">
                <transactionFlow transactionProtocol="WSAtomicTransactionOctober2004" />
                <reliableSession />
                <compositeDuplex />
                <oneWay />
                <textMessageEncoding messageVersion="Default">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                </textMessageEncoding>
                <httpTransport maxReceivedMessageSize="524288" authenticationScheme="Ntlm"
                    maxBufferSize="524288" proxyAuthenticationScheme="Ntlm" transferMode="Buffered"
                    unsafeConnectionNtlmAuthentication="true" />
            </binding>
          </customBinding>
          <client>
             <endpoint address="http://Server/Task/Project/TaskName/Task"
                 behaviorConfiguration="SynchronousBehavior" binding="customBinding"
                 bindingConfiguration="HttpChunkingBinding" contract="MyTask.Interfaces.ITask"
                 name="HttpConnection" />
              <endpoint address="http://Server/Test/Project/TaskName/Task"
                 behaviorConfiguration="SynchronousBehavior" binding="customBinding"
                 bindingConfiguration="HttpBinding" contract="MyTask.Interfaces.ITask"
                 name="HttpConnectionNoChunking" />
            </client>
        </system.serviceModel>
   </configuration>

Is there a way that I can secure this connection using my HTTP custom bindings without IIS? I see that Anonymous security will work with basicHttpBinding but I don't know how to move my custom binding to a basicHttpBinding with all the custom settings. Does the fact that I can connect to a local HTTP connection help at all? Do I need to add some authentication using C# after loading the configuration file? If I can get Ntlm to work, I may not need to set unsafeConnectionNtlmAuthentication="true" in my configuration file. Thanks in advance WCF gurus.

Brian C
  • 33
  • 3
  • The remote PC need to use the same Password Server that you are using so the password can be verified. Or you need an account on remote machine so you can logon using username/password. Most application these days use a certificate with TLS 1.2 authentication. – jdweng Sep 04 '20 at 16:28
  • I suggest you use windows authentication, because if the client and the server are not in the same domian, the Ntlm authentication will not work. – Ding Peng Oct 09 '20 at 05:40

0 Answers0