I follow this MSDN article on how to implement user authentication for WCF services.
in step 5, the attribute: [AspNetCompatibilityRequirements] configured in the service to configure the WCF service for ASP.NET compatibility mode. This is necessary because authentication is performed by the HTTP module, and you should be able to get the basic information and identifier from the HTTP context in order to allow users to either forcefully or declaratively in WCF.
When I start the service, I get this error message:
The service cannot be activated because it does not support ASP.NET compatibility. Compatibility with ASP.NET is included for this application. Disable ASP.NET compatibility mode in the web.config file or add the AspNetCompatibilityRequirements attribute refers to the service type with the RequirementsMode parameter as "Allowed" or "Required."
It seems that although I explicitly declared an attribute that it ignored. What could be the reason for this? Even if I changed the value to AspNetCompatibilityRequirementsMode. However, it does not work. The same error message, which is due to the fact that IIS has no reason to complain!
Services:
namespace MyNamespace.IISServiceHost { [ServiceBehavior(MaxItemsInObjectGraph = int.MaxValue)] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] public class CompanyNameAPIService { public CompanyNameAPIService() { } } }
Interface
namespace MyNamespace { [ServiceContract] public interface ICompanyAPI { [OperationContract] [PrincipalPermission(SecurityAction.Demand, Role="WSIuser")] [ServiceKnownType(typeof(Supplier))] [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.WrappedRequest)] void AddUpdateSuppliers(int companyId, Supplier[] sups); [OperationContract] [PrincipalPermission(SecurityAction.Demand, Role = "WSIuser")] [ServiceKnownType(typeof(Dimension))] [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.WrappedRequest)] void AddUpdateDimension(int companyId, Dimension dims); ... } }
I also set the equivalent in Web.config .
<system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="True" multipleSiteBindingsEnabled="true" /> <service behaviorConfiguration="ServiceBehavior" name="MyNamespace.IISServiceHost.CompanyAPIService"> <endpoint address="" behaviorConfiguration="largeDataBehavior" binding="basicHttpBinding" bindingConfiguration="BasicBindingConfiguration" name="BasicEndpoint" contract="MyNamespace.ICompanyAPI" /> <endpoint address="help" behaviorConfiguration="helpPageBehavior" binding="mexHttpsBinding" bindingConfiguration="" name="MexEndpoint" contract="MyNamespace.ICompanyAPI" kind="mexEndpoint" endpointConfiguration="" /> </service> <bindings> <basicHttpBinding> <binding name="BasicBindingConfiguration"><security mode="Transport" /></binding> </basicHttpBinding> <webHttpBinding> <binding name="webBinding"> <security mode="Transport"><transport clientCredentialType="None" /></security> </binding> </webHttpBinding> </bindings> <behaviors> <endpointBehaviors> <behavior name="largeDataBehavior"> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> <enableWebScript /> </behavior> <behavior name="helpPageBehavior"> <webHttp helpEnabled="true" /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="ServiceBehavior"> <serviceMetadata httpsGetEnabled="true" httpsGetUrl="https://localhost/WSI/service.svc/wsdl" /> <serviceDebug httpsHelpPageEnabled="true" includeExceptionDetailInFaults="true" /> <serviceAuthorization principalPermissionMode="UseAspNetRoles" roleProviderName="WSIRoleProvider"> <authorizationPolicies> <add policyType="myNamespace.AuthorizationPolicy.HttpContextPrincipalPolicy, AuthorizationPolicy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> </authorizationPolicies> </serviceAuthorization> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>