Hello everyone,
I am trying toImplement some security into my WCF classes but Iam 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 theerror, my web.config, and myWCF 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> |
| <bindingname="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"> |
| <readerQuotasmaxDepth="32"maxStringContentLength="8192"maxArrayLength="16384" |
| maxBytesPerRead="4096"maxNameTableCharCount="16384"/> |
| <reliableSessionordered="true"inactivityTimeout="00:10:00" |
| enabled="false"/> |
| </binding> |
| </wsHttpBinding> |
| </bindings> |
| <behaviors> |
| <serviceBehaviors> |
| <behaviorname="serviceBehavior"> |
| <serviceAuthorizationprincipalPermissionMode="UseAspNetRoles"roleProviderName="CustomRoleProvider"> |
| </serviceAuthorization> |
| <serviceCredentials> |
| <userNameAuthenticationuserNamePasswordValidationMode="MembershipProvider"membershipProviderName="CustomMembership"/> |
| </serviceCredentials> |
| </behavior> |
| </serviceBehaviors> |
| |
| |
| </behaviors> |
| <client> |
| <endpointaddress="http://localhost:8000/ServiceModelSamples/Service/CalculatorService" |
| binding="wsHttpBinding"bindingConfiguration="WSHttpBinding_ICalculator" |
| contract="ICalculator"name="WSHttpBinding_ICalculator"behaviorConfiguration="serviceBehavior"> |
| </endpoint> |
| </client> |
| </system.serviceModel> |
| |
| <system.web> |
| <roleManagerenabled="true"defaultProvider="CustomRoleProvider"> |
| <providers> |
| <clear/> |
| <addname="CustomRoleProvider"type="WCFSecurityTest.CustomRoleProvider,WCFSecurityTest"/> |
| </providers> |
| </roleManager> |
| <membershipdefaultProvider="CustomMembership"> |
| <providers> |
| <clear/> |
| <addname="CustomMembership"type="WCFSecurityTest.CustomMembership,WCFSecurityTest"/> |
| </providers> |
|
| </membership> |
| [PrincipalPermission(SecurityAction.Demand,Role="Admin")] |
| publicdoubleAdd(doublen1,doublen2) |
| { |
| //PrincipalPermissionp=new |
| //PrincipalPermission(null,"Admin"); |
| //p.Demand(); |
| doubleresult=n1+n2; |
| Console.WriteLine("ReceivedAdd({0},{1})",n1,n2); |
| //Codeaddedtowriteoutputtotheconsolewindow. |
| Console.WriteLine("Return:{0}",result); |
| returnresult; |
| } |
Thank you.