Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Configuring WCF in code (basic HTTP)
public class Configuration
{
public static void ConfigureForHttp<T>(ServiceConfiguration config)
{
var existingBehaviour = config.Description.Behaviors.FirstOrDefault(x => x is AspNetCompatibilityRequirementsAttribute);
if (existingBehaviour != null)
{
config.Description.Behaviors.Remove<AspNetCompatibilityRequirementsAttribute>();
}
config.Description.Behaviors.Add(new AspNetCompatibilityRequirementsAttribute { RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed });
config.Description.Behaviors.Add(new ServiceMetadataBehavior { HttpGetEnabled = true });
config.Description.Behaviors.Add(new ServiceDebugBehavior { IncludeExceptionDetailInFaults = true });
config.EnableProtocol(new BasicHttpBinding());
config.EnableProtocol(new BasicHttpsBinding());
//config.EnableProtocol(MetadataExchangeBindings.CreateMexHttpBinding());
config.AddServiceEndpoint(typeof(T), new BasicHttpBinding() { MaxReceivedMessageSize = 5242880 }, "basic");
}
}
// Example usage:
public class PizzaService : IPizzaService
{
public static void Configure(ServiceConfiguration config)
{
Configuration.ConfigureForHttp<IPizzaService>(config);
}
public void OrderPizza(string toppings)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.