I am trying to Implement some security into my WCF classes but I
am having some problems with using a custom role provider. I seem to
be implementing it correctly vs. everything I have read on how to
implement it but I keep getting an error. If someone could please
point me in the right direction it would be great. Below is the
error, my web.config, and my WCF method. I know the role provider is
working because I have the role access on the page that is calling the
service, and the page loads fine.
Error: Request for principal permission failed.
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_ICalculator"
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="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" /
><reliableSession ordered="true"
inactivityTimeout="00:10:00"
enabled="false" />
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceAuthorization
principalPermissionMode="UseAspNetRoles"
roleProviderName="CustomRoleProvider">
</serviceAuthorization>
<serviceCredentials>
<userNameAuthentication
userNamePasswordValidationMode="MembershipProvider "
membershipProviderName="CustomMembership" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<client>
<endpoint address="http://localhost:8000/ServiceModelSamples/
Service/CalculatorService"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_ICalculator"
contract="ICalculator" name="WSHttpBinding_ICalculator"
behaviorConfiguration="serviceBehavior">
</endpoint>
</client>
</system.serviceModel>
<system.web>
<roleManager enabled="true"
defaultProvider="CustomRoleProvider">
<providers>
<clear/>
<add name="CustomRoleProvider"
type="WCFSecurityTest.CustomRoleProvider, WCFSecurityTest"/>
</providers>
</roleManager>
<membership defaultProvider="CustomMembership" >
<providers>
<clear/>
<add name="CustomMembership"
type="WCFSecurityTest.CustomMembership, WCFSecurityTest"/>
</providers>
</membership>
[PrincipalPermission(SecurityAction.Demand, Role="Admin")]
public double Add(double n1, double n2)
{
//PrincipalPermission p = new
//PrincipalPermission(null, "Admin");
//p.Demand();
double result = n1 + n2;
Console.WriteLine("Received Add({0},{1})", n1, n2);
// Code added to write output to the console window.
Console.WriteLine("Return: {0}", result);
return result;
}