Created
May 3, 2015 20:54
-
-
Save yetanotherchris/6ee7819a5fe3f42f0cc0 to your computer and use it in GitHub Desktop.
Configuring WCF in code (basic HTTP)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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