Search KB Filter article types
WCF: Service Authentication
Categories: Configuration
Tags: Developers, 2. Intermediate, 3. Advanced, Customization, WCF, Pre v6.3, v6.3, v6.4 and Later
Revision: 1
Posted: 06/Jan/2009
Updated: 06/Jan/2009
Status: Publish
Types: Article

Hello everyone:

I hope this help for anyone who trying to work with WCF web services.

When you need to use web services, you have problems to configure it. Why? because the default configuration generate code for wsHttpBinding and not for a basicHttpBinding.

The difference is the authentication type.
wsHttpBinding works on "windows authentication" and the basicHttpBinding works on "forms authentication".

Due to this, I have prepared the examples of the web.config file for the server and for the client.

1.- For the server side (web service hosted on a sub domain) on the web.config, you need to establish <authentication mode="Forms" /> and the next part:

<system.serviceModel>
    <serviceHostingEnvironment>
       <baseAddressPrefixFilters>
          <add prefix="http://services.mydomain.com.mx" />
       </baseAddressPrefixFilters>
    </serviceHostingEnvironment>
    <services>
       <service name="svcRef.Service" behaviorConfiguration="ServiceBehavior">
          <endpoint address="http://services.mydomain.com.mx/Service.svc" binding="basicHttpBinding" contract="svcRef.IService" >
             <identity>
                <dns value="http://services.mydomain.com.mx"/>
             </identity>
          </endpoint>
          <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
       </service>
    </services>
    <behaviors>
       <serviceBehaviors>
          <behavior name="ServiceBehavior">
             <serviceMetadata httpGetEnabled="true"/>
             <serviceDebug includeExceptionDetailInFaults="false"/>
          </behavior>
       </serviceBehaviors>
    </behaviors>
</system.serviceModel>

IMPORTANT NOTES: you need to change the binding type to "basicHttpBinding" and the identity of the endpoint to <dns value="http://services.mydomain.com.mx"/>

2.- For the client side on the web.config you need these part:

<system.serviceModel>
    <bindings>
       <basicHttpBinding>
          <binding name="Servicios" closeTimeout="00:01:00" openTimeout="00:01:00"
             receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
             bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
             maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
             messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
             useDefaultWebProxy="true">
             <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
               maxBytesPerRead="4096" maxNameTableCharCount="16384" />
             <security mode="None">
                <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
                <message clientCredentialType="UserName" algorithmSuite="Default" />
             </security>
          </binding>
       </basicHttpBinding>
    </bindings>
    <client>
       <endpoint address="http://services.mydomain.com.mx/Service.svc" binding="basicHttpBinding"
         bindingConfiguration="Servicios" contract="svcRef.IService" name="Servicios" >
         <identity>
            <userPrincipalName value="SERVER\mydomain.co_web" />
         </identity>
       </endpoint>
    </client>
</system.serviceModel>

IMPORTANT NOTES: You need the same binding type to "basicHttpBinding" in the endpoint. The bindings service model change to basicHttpBinding. You may obtain the user <userPrincipalName value="SERVER\mydomain.co_web" /> running th svcutil. for example: c:\program files\microsoft sdks\windows\v6.0A\bin\svcutil http://service.mydomain.com.mx/Service.svc?wsdl /language:VB these line generate 2 files, output.config and service.vb. In the output.config you can find the user.

The difference between basicHttpBinding and wsHttpBinding is the authentication: on first type you pass the user name <userPrincipalNamevalue = "SERVER\mydomain.co_web" /> to the service and you don't need any more authentication, and on wsHttpBinding you need to do an authentication via windows and domain. If you try to wsHttpBinding type you have multiple errors like (405) Method not allowed by the service and "caller was not authenticated by the service"

Thanks

About the author

Related Articles

Configuration  
Title Update Author
Visual WebGui version 6.2 features complete integration into the Microsoft Visual Studio development system, a consolidated installation process, and the opportunity to use Microsoft Visual Studio Express Editions for software evaluation and trials. Attend this webcast to learn how the Visual WebGui...
Tags: Developers, Visual WebGui Pipeline, Visual Studio, 1. Beginner, 2. Intermediate, 3. Advanced, Integration, Pre v6.3, v6.3, v6.4 and Later
11/Jan/2008    2008/01/11
Tags: Architects, Developers, XML, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
29/Oct/2010    2010/10/29
Tags: Architects, Developers, XML, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
23/July/2010    2010/07/23
Tags: Architects, Developers, XML, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
23/July/2010    2010/07/23
Tags: Architects, Developers, XML, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
23/July/2010    2010/07/23
Tags: Architects, Developers, XML, 1. Beginner, 2. Intermediate, 3. Advanced, Pre v6.3, v6.3, v6.4 and Later
04/Dec/2010    2010/12/04