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

Posted: March 22, 2011 in WCF
Tags:

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

This indicates that service authentication is configured as Basic & client authentication should be changed accordingly. Below web.config at client side can help you get rid of this exception

       <webHttpBinding>
        <binding name="ExternalBinding">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Basic"/>
          </security>
        </binding>
      </webHttpBinding>

<client>
<endpoint name="IServices" address="http://xyz.com/Services.svc" binding="webHttpBinding" bindingConfiguration="ExternalBinding" behaviorConfiguration="RESTBehavior" contract="IVendor"></endpoint>
</client>
<behaviors>
   <endpointBehaviors>
    <behavior name="RESTBehavior">
    <webHttp helpEnabled="true"/>
    </behavior>
   </endpointBehaviors>
  </behaviors>

 

Make sure that from client code you supply the necessary credentials through proxy.

VendorProxy client = new VendorProxy();
client.ClientCredentials.UserName.UserName = ConfigurationManager.AppSettings["ServiceUsername"].ToString();
client.ClientCredentials.UserName.Password = ConfigurationManager.AppSettings["ServicePassword"].ToString();
Advertisements
Comments
  1. Balaji says:

    Great it worked!! Thanks…

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