Thursday, April 9, 2009

Integrating SqlMemberShip security with WCF Services

I was always wondering how easy/difficult it will be to make a WCF Service secured with preexisting SqlMemberShipProvider credentials. It is very very simple than I first thought.

Assuming we have configured SqlMemberShipProvider section in Web.Config of the client application (In our case web application is considered to be a client for WCF Service application), we just need a way to pass the user/password credentials user entered to WCF Service.

Certain binding types like wsHttpBinding allows to pass user credentials. The following section helps to do that.

<system.serviceModel>
<bindings>
<wsHttpBinding>
<!-- Set up a binding that uses UserName as the client credential type -->
<binding name="MembershipBinding">
<security mode ="Message">
<message clientCredentialType ="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>

Once the Security is configured, we just need to let the Service know to use MemberShipProvider. The following section does exactly that.

<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode ="MembershipProvider"
membershipProviderName ="SqlMembershipProvider"/>
</serviceCredentials>


For more information refer to this link.


Happy WCF Learning!!!

No comments:

Post a Comment