WCF service attributes not counted

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> 
+6
source share
1 answer

I finally got my service. I am posting this if someone encounters this problem. There were several problems, so I answered them one by one.

Service Attributes Ignored

My Visual Studio solution contains both a Service-Project and a ServiceHost project. The service project has app.config , and ServiceHost has web.config .

What I did not know was that, although the service is defined in web.config, not all settings are met, so instead you have to make configurations in the app.config file. This was so confusing to me because the app.config file disappears when the service is published to IIS. I still don’t know how it works, but it is.

Service attribute attribute

After I fixed the first problem, the service was published successfully, and I could access it using a browser. WSDL configuration was also available (good). But when I tried to call any of the public service methods, I got " 404 not found " or " There was no channel actively listening at 'xxx' ".

After a long time finding the problem, I found this error in the trace log: No matching <service> tag was found .

This was strange because I knew that the service and its endpoints were configured correctly.

The problem was the name of the service. According to numerous questions here in StackOverflow, the name should be in the format " Complete.Namespace.Classname ". This seems to be wrong if the service is hosted on IIS. Then, instead of the service name, there should be a value found in the @ServiceHost Service tag property in the service.svc file

+2
source

Source: https://habr.com/ru/post/957690/


All Articles