Skip to content

Instantly share code, notes, and snippets.

@hanssens
Created December 5, 2016 12:18
Show Gist options
  • Save hanssens/700862b3338866b092bf4c7dd4db691b to your computer and use it in GitHub Desktop.
Save hanssens/700862b3338866b092bf4c7dd4db691b to your computer and use it in GitHub Desktop.
BindingFactory - Helpers for adding WsHttpBinding/WsHttpsBinding to dotnet core projects.
public static class BindingFactory
{
/// <summary>
/// A poor man's implementation for dotnet-core support of WsHttpBinding (plain, http).
/// </summary>
/// <param name="endpointAddress">Full http endpoint address.</param>
public static System.ServiceModel.Channels.Binding CreateWsHttpBinding(string endpointAddress)
{
var result = new System.ServiceModel.Channels.CustomBinding();
var textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
result.Elements.Add(textBindingElement);
var httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement
{
AllowCookies = true,
MaxBufferSize = int.MaxValue,
MaxReceivedMessageSize = int.MaxValue
};
result.Elements.Add(httpBindingElement);
return result;
}
/// <summary>
/// A poor man's implementation for dotnet-core support of WsHttpsBinding (secured, https).
/// </summary>
/// <param name="endpointAddress">Full https endpoint address.</param>
public static System.ServiceModel.Channels.Binding CreateWsHttpsBinding(string endpointAddress)
{
var result = new System.ServiceModel.Channels.CustomBinding();
var textBindingElement = new System.ServiceModel.Channels.TextMessageEncodingBindingElement();
result.Elements.Add(textBindingElement);
var httpsBindingElement = new System.ServiceModel.Channels.HttpsTransportBindingElement
{
AllowCookies = true,
MaxBufferSize = int.MaxValue,
MaxReceivedMessageSize = int.MaxValue
};
result.Elements.Add(httpsBindingElement);
return result;
}
}
@hanssens
Copy link
Author

hanssens commented Dec 5, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment