Hello everyone,
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.service Model>
<bindings>
<wsHttpBindin g>
<binding name="WSHttpBin ding_ICalculato r"
closeTimeout="0 0:01:00"
openTimeout="00 :01:00" receiveTimeout= "00:10:00"
sendTimeout="00 :01:00"
bypassProxyOnLo cal="false" transactionFlow ="false"
hostNameCompari sonMode="Strong Wildcard"
maxBufferPoolSi ze="524288"
maxReceivedMess ageSize="65536"
messageEncoding ="Text" textEncoding="u tf-8"
useDefaultWebPr oxy="true"
allowCookies="t rue">
<readerQuotas maxDepth="32" maxStringConten tLength="8192"
maxArrayLength= "16384"
maxBytesPerRead ="4096" maxNameTableCha rCount="16384" /
<reliableSessio n ordered="true"
inactivityTimeo ut="00:10:00"
enabled="false" />
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehavio rs>
<behavior name="serviceBe havior">
<serviceAuthori zation
principalPermis sionMode="UseAs pNetRoles"
roleProviderNam e="CustomRolePr ovider">
</serviceAuthoriz ation>
<serviceCredent ials>
<userNameAuthen tication
userNamePasswor dValidationMode ="MembershipPro vider"
membershipProvi derName="Custom Membership" />
</serviceCredenti als>
</behavior>
</serviceBehavior s>
</behaviors>
<client>
<endpoint address="http://localhost:8000/ServiceModelSam ples/
Service/CalculatorServi ce"
binding="wsHttp Binding"
bindingConfigur ation="WSHttpBi nding_ICalculat or"
contract="ICalc ulator" name="WSHttpBin ding_ICalculato r"
behaviorConfigu ration="service Behavior">
</endpoint>
</client>
</system.serviceM odel>
<system.web>
<roleManager enabled="true"
defaultProvider ="CustomRolePro vider">
<providers>
<clear/>
<add name="CustomRol eProvider"
type="WCFSecuri tyTest.CustomRo leProvider, WCFSecurityTest "/>
</providers>
</roleManager>
<membership defaultProvider ="CustomMembers hip" >
<providers>
<clear/>
<add name="CustomMem bership"
type="WCFSecuri tyTest.CustomMe mbership, WCFSecurityTest "/>
</providers>
</membership>
[PrincipalPermis sion(SecurityAc tion.Demand, Role="Admin")]
public double Add(double n1, double n2)
{
//PrincipalPermis sion p = new
//PrincipalPermis sion(null, "Admin");
//p.Demand();
double result = n1 + n2;
Console.WriteLi ne("Received Add({0},{1})", n1, n2);
// Code added to write output to the console window.
Console.WriteLi ne("Return: {0}", result);
return result;
}
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.service Model>
<bindings>
<wsHttpBindin g>
<binding name="WSHttpBin ding_ICalculato r"
closeTimeout="0 0:01:00"
openTimeout="00 :01:00" receiveTimeout= "00:10:00"
sendTimeout="00 :01:00"
bypassProxyOnLo cal="false" transactionFlow ="false"
hostNameCompari sonMode="Strong Wildcard"
maxBufferPoolSi ze="524288"
maxReceivedMess ageSize="65536"
messageEncoding ="Text" textEncoding="u tf-8"
useDefaultWebPr oxy="true"
allowCookies="t rue">
<readerQuotas maxDepth="32" maxStringConten tLength="8192"
maxArrayLength= "16384"
maxBytesPerRead ="4096" maxNameTableCha rCount="16384" /
>
inactivityTimeo ut="00:10:00"
enabled="false" />
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehavio rs>
<behavior name="serviceBe havior">
<serviceAuthori zation
principalPermis sionMode="UseAs pNetRoles"
roleProviderNam e="CustomRolePr ovider">
</serviceAuthoriz ation>
<serviceCredent ials>
<userNameAuthen tication
userNamePasswor dValidationMode ="MembershipPro vider"
membershipProvi derName="Custom Membership" />
</serviceCredenti als>
</behavior>
</serviceBehavior s>
</behaviors>
<client>
<endpoint address="http://localhost:8000/ServiceModelSam ples/
Service/CalculatorServi ce"
binding="wsHttp Binding"
bindingConfigur ation="WSHttpBi nding_ICalculat or"
contract="ICalc ulator" name="WSHttpBin ding_ICalculato r"
behaviorConfigu ration="service Behavior">
</endpoint>
</client>
</system.serviceM odel>
<system.web>
<roleManager enabled="true"
defaultProvider ="CustomRolePro vider">
<providers>
<clear/>
<add name="CustomRol eProvider"
type="WCFSecuri tyTest.CustomRo leProvider, WCFSecurityTest "/>
</providers>
</roleManager>
<membership defaultProvider ="CustomMembers hip" >
<providers>
<clear/>
<add name="CustomMem bership"
type="WCFSecuri tyTest.CustomMe mbership, WCFSecurityTest "/>
</providers>
</membership>
[PrincipalPermis sion(SecurityAc tion.Demand, Role="Admin")]
public double Add(double n1, double n2)
{
//PrincipalPermis sion p = new
//PrincipalPermis sion(null, "Admin");
//p.Demand();
double result = n1 + n2;
Console.WriteLi ne("Received Add({0},{1})", n1, n2);
// Code added to write output to the console window.
Console.WriteLi ne("Return: {0}", result);
return result;
}