WCF web service error: The service cannot be activated because it does not support ASP.NET compatibility

后端 未结 4 1868
無奈伤痛
無奈伤痛 2021-02-01 12:28

I am trying to create a restful wcf web service. When I try to connect to the service through the client I get the following error:

相关标签:
4条回答
  • 2021-02-01 12:59

    Actually, as per the latest documentation you need to do 2 things,

    1.For your service class:

    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(Namespace = "url")]
    public class Service : IService
    {
    }
    

    2.For web.config

    <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    
    0 讨论(0)
  • 2021-02-01 13:05

    On your main service you could mark your service as:

    [AspNetCompatibilityRequirements(
            RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    

    From http://forums.silverlight.net/t/21944.aspx

    0 讨论(0)
  • 2021-02-01 13:10

    If someone has a lot of services and services are created using custom ServiceHostFactory, then AspNetCompatibilityRequirementsAttribute can also be set in CreateServiceHost method.

    Example:

    public class HostFactory : ServiceHostFactory
    {
        protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        {
            var host = new ServiceHost(serviceType, baseAddresses);
            //other relevent code to configure host's end point etc
            if (host.Description.Behaviors.Contains(typeof(AspNetCompatibilityRequirementsAttribute)))
            {
                var compatibilityRequirementsAttribute = host.Description.Behaviors[typeof(AspNetCompatibilityRequirementsAttribute)] as AspNetCompatibilityRequirementsAttribute;
                compatibilityRequirementsAttribute.RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed;
            }
            else
            {
                host.Description.Behaviors.Add(new AspNetCompatibilityRequirementsAttribute() { RequirementsMode =AspNetCompatibilityRequirementsMode.Allowed});
            }
            return host;
        }
    }
    
    0 讨论(0)
  • 2021-02-01 13:19

    it will work :

    you have change this lines in code or add the line in web.config:

    <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel>
    
    0 讨论(0)
提交回复
热议问题