Skip to content

Instantly share code, notes, and snippets.

@yetanotherchris
Created May 3, 2015 20:54
Show Gist options
  • Save yetanotherchris/6ee7819a5fe3f42f0cc0 to your computer and use it in GitHub Desktop.
Save yetanotherchris/6ee7819a5fe3f42f0cc0 to your computer and use it in GitHub Desktop.
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