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:
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;
}
}