0 Comments

Let’s say you created a ASP .NET 4.0 website that uses a WCF service to get data from a Microsoft SQL Server database.

The website uses anonymous authentication and you are asked to show data on the website from another WCF service that use anonymous authentication:

 

image

 

By default wsHttpBinding uses windows authentication, so if you want to use wsHttpBinding in this scenario, you will have to disable authentication on both the WCF Server [A] binding as the WCF Service [B] binding.

This can be done, by setting the security mode to none on the binding and setting clientCredentialType to None on the transport and message nodes:

 

WCF Service [A] Web.config:

<system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_IMyServiceB" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
          <security mode="None">
            <transport clientCredentialType="None" />
            <message clientCredentialType="None" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:64043/MyServiceB.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyServiceB" contract="ADAICT.IMyServiceB" name="WSHttpBinding_IMyServiceB" />
    </client>

 

WCF Service [B] Web.config

<system.serviceModel>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
        <bindings>
            <wsHttpBinding>
                <binding name="AnonymousBinding">
                  <security mode="None">
                    <transport clientCredentialType="None" />
                    <message clientCredentialType="None" />
                  </security>
                </binding>
            </wsHttpBinding>
        </bindings>

 <service behaviorConfiguration="WcfServiceBehavior" name="MyServiceB">
            <endpoint binding="wsHttpBinding" bindingConfiguration="AnonymousBinding"
              contract="IMyServiceB" />
            <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
              contract="IMetadataExchange" />
            <host>
              <timeouts openTimeout="23:59:59" />
            </host>
          </service>

This allows the WCF Service [A] to communicate with WCF Service [B] on wsHttpBinding with anonymous access.

One Reply to “Using anonymous authentication on a .NET 4.0 WCF service that calls another WCF service

  1. Hi Roel,

    Great article!
    Do you perhaps know if it is possible to host a wcf-service, whitout IIS, AND anonymous authentication?

    I keep getting a 403 (forbidden), because ‘anonymous’ is not allowed.

    Local in VS everythings works, but when I run it in 2 different servers (host andclient) then I get the error.

    Thanks!

    Roelant

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts