WCF client binding configuration in program code

Posted by smarsha on Stack Overflow See other posts from Stack Overflow or by smarsha
Published on 2011-01-13T22:36:45Z Indexed on 2011/01/13 22:53 UTC
Read the original article Hit count: 248

Filed under:

I have the following class that configures security, encoding, and token parameters but I am having trouble adding a BasicHttpBinding to specify a MaxReceivedMessageSize. Any insight would be appreciated.

    public class MultiAuthenticationFactorBinding
{
    public static Binding CreateMultiFactorAuthenticationBinding()
    {
        HttpsTransportBindingElement httpTransport = new HttpsTransportBindingElement();
        CustomBinding binding = new CustomBinding();
        binding.Name = "myCustomBinding";

        TransportSecurityBindingElement messageSecurity = TransportSecurityBindingElement.CreateUserNameOverTransportBindingElement();
        messageSecurity.AllowInsecureTransport = true;
        messageSecurity.EnableUnsecuredResponse = true;
        messageSecurity.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12;
        messageSecurity.SecurityHeaderLayout = SecurityHeaderLayout.Strict;
        messageSecurity.IncludeTimestamp = true;
        messageSecurity.SetKeyDerivation(false);

        TextMessageEncodingBindingElement Quota = new TextMessageEncodingBindingElement(MessageVersion.Soap11, System.Text.Encoding.UTF8);
        Quota.ReaderQuotas.MaxDepth = 32;
        Quota.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
        Quota.ReaderQuotas.MaxArrayLength = 16384;
        Quota.ReaderQuotas.MaxBytesPerRead = 4096;
        Quota.ReaderQuotas.MaxNameTableCharCount = 16384;


        X509SecurityTokenParameters clientX509SupportingTokenParameters = new X509SecurityTokenParameters();
        clientX509SupportingTokenParameters.InclusionMode = SecurityTokenInclusionMode.AlwaysToRecipient;
        clientX509SupportingTokenParameters.RequireDerivedKeys = false;
        messageSecurity.EndpointSupportingTokenParameters.Endorsing.Add(clientX509SupportingTokenParameters);
        //binding.ReceiveTimeout = new TimeSpan(0,0,300);
        binding.Elements.Add(Quota);
        binding.Elements.Add(messageSecurity);
        binding.Elements.Add(httpTransport);
        return binding;
    }
}

© Stack Overflow or respective owner

Related posts about wcf