The HTTP request is unauthorized with client authentication scheme ‘Anonymous’. The authentication header received from the server was ‘Basic

I’m working on a Microsoft ESB Toolkit project this morning that needs to lock down the ESB SOAP On Ramp to use Basic authentication. Too easy! I created a new application under IIS 7.0 as per the existing SOAP ESB itinery services On Ramp web service. I then tweaked the authentication for the web service to turn off anonymous and enable basic. I then wrote a simple C# test client that looks something like below.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            ESBOnRamp.ProcessSoapClient requestBroker = new ESBOnRamp.ProcessSoapClient();
            System.Xml.XmlDocument requestDocument = new System.Xml.XmlDocument();
            
            // Load a sample document
            requestDocument.LoadXml("<ns0:ShipConf xmlns:ns0='http://contoso.org/samples'><ns0:OrderID>SSOTest</ns0:OrderID></ns0:ShipConf>");

            // Set the credentials for basic authentication
            requestBroker.ClientCredentials.UserName.UserName = @"domain\username";
            requestBroker.ClientCredentials.UserName.Password = "password";

            // Submit the sample document to the ESB On Ramp
            requestBroker.SubmitRequest(null, requestDocument.FirstChild);
        }
    }
}

To my surprise this failed with the below error!

{“The HTTP request is unauthorized with client authentication scheme ‘Anonymous’. The authentication header received from the server was ‘Basic realm=\”localhost\”‘.”}

So I cracked open Fiddler to check the headers and yep, no authentication header. After making the following corrections to the app.config of my test client all was good.


 <bindings>
       <basicHttpBinding>
               <security mode="TransportCredentialOnly">
                     <transport clientCredentialType="Basic" proxyCredentialType="None" realm="" />
                     <message clientCredentialType="UserName" algorithmSuite="Default" />
               </security>
              </binding>
          </basicHttpBinding>
      </bindings>

Advertisements
This entry was posted in .NET. Bookmark the permalink.

2 Responses to The HTTP request is unauthorized with client authentication scheme ‘Anonymous’. The authentication header received from the server was ‘Basic

  1. Tim says:

    Thanks! This helped me solve an issue that I was having today!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s