Debug WCF service IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports

If you want to debug a WCF service you may encounter the following error in Visual Studio:

IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used.. ---> System.InvalidOperationException: IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used

This can occur if the virtual directory hosting the service in IIS has both the Intergrated Windows Authentication and Anonymous authentication schemes selected.  In order to get around this so that you can debug your service, you can do the following:

  1. In IIS, uncheck the Annonymous scheme
  2. In IIS, leave Integrated Windows Authentication checked - this is required to run the VS Debugger
  3. Start the debugger from VS
  4. Before you make a request to your service, go back into IIS and check the Annonymous scheme
  5. Make a request to your service and your break point will be hit

System.ServiceModel.CommunicationException: An error occurred while receiving the HTTP response to

We were gettign an error with one of our WCF services "System.ServiceModel.CommunicationException: An error occurred while receiving the HTTP response to..." and needed to get additional information on the problem.  Below are steps to use the built in diagnostics with WCF to find out more info for the error above as well as the overall health of your service.

  1. Add to your web.config:

     <system.diagnostics>
        <sources>
          <source name="System.ServiceModel.MessageLogging">
            <listeners>
              <add name="messages"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData="D:\LogFiles\SalesOrderTrackingService\messages.svclog" />
            </listeners>
          </source>
        </sources>
      </system.diagnostics>

    <system.serviceModel>
        <diagnostics>
          <messageLogging
               logEntireMessage="true"
               logMalformedMessages="false"
               logMessagesAtServiceLevel="true"
               logMessagesAtTransportLevel="false"
               maxMessagesToLog="3000"
               maxSizeOfMessageToLog="2000"/>
        </diagnostics>
    ...
  2. Create the necessary folder and ensure the security is set so IIS/ASP.NET can write to the log file
  3. Use the SvcTraceViewer.exe application to view your log file

    This tool can be found in the SDK directory...for me, this was C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin

System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (400) Bad Request

Recently I had a WCF service call that was returning the error System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (400) Bad Request.

Looking into this, I discivered that the messages we were sending were increasing in size.  We were using the basic http binding and it turns out the default readerQuotas were too small and were causing the"Bad Request" error.

I increased the readerQuotas to the values below and that resolved the error.

 

<basicHttpBinding>
        ...
          <readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000"
            maxBytesPerRead="2000000" maxNameTableCharCount="2000000" />

       ...