This documentation is archived and is not being maintained.

WSHttpBindingBase Class

Provides the base class with members common to the WSHttpBinding and the WSFederationHttpBinding.

Namespace:  System.ServiceModel
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public abstract class WSHttpBindingBase : Binding, 

The WSHttpBindingBase provides some basic functionality for the bindings used to configure secure, reliable, and interoperable Web services, such as that implemented by the WSHttpBinding for non-duplex service contracts, and more particularly, for the secure and interoperable WSFederationHttpBinding that supports the WS-Federation protocol.

By default it generates a run-time stack that uses WS-Security for message security and authentication, HTTP for message delivery, and a Text/XML message encoding. It can be configured to also use WS-ReliableMessaging for reliability.

The use of WS-ReliableMessaging is configurable using the optional reliableSessionEnabled parameter.

The following example shows how to use the functionality provided by the WSHttpBindingBase class with the derived classes, WSHttpBinding and WSFederationHttpBinding.

    // Define a service contract for the calculator.
    public interface ICalculator
        [OperationContract(IsOneWay = false)]
        double Add(double n1, double n2);
        [OperationContract(IsOneWay = false)]
        double Subtract(double n1, double n2);
        [OperationContract(IsOneWay = false)]
        double Multiply(double n1, double n2);
        [OperationContract(IsOneWay = false)]
        double Divide(double n1, double n2);

    // Service class which implements the service contract. 
    public class CalculatorService : ICalculator
        public double Add(double n1, double n2)
            double result = n1 + n2;
            return result;

        public double Subtract(double n1, double n2)
            double result = n1 - n2;
            return result;

        public double Multiply(double n1, double n2)
            double result = n1 * n2;
            return result;

        public double Divide(double n1, double n2)
            double result = n1 / n2;
            return result;

        // Create and configure bindings within this EXE console application. 
        public static void Main()
            // Create a WSHttpBinding
            WSHttpBinding binding1 = new WSHttpBinding();

	    binding1.BypassProxyOnLocal =  true;

	    EnvelopeVersion envelopeVersion =

	    HostNameComparisonMode hostnameComparisonMode =

	    long maxBufferPoolSize =

	    long maxReceivedMessageSize =

	    WSMessageEncoding messageEncoding =

	    Uri proxyAddress =

	    XmlDictionaryReaderQuotas readerQuotas =

	    OptionalReliableSession reliableSession =

	    string scheme = binding1.Scheme;

	    Encoding textEncoding =

	    bool transactionFlow =

	    bool useDefaultWebProxy =

	    BindingElementCollection bindingElements = 

            // Set WSHttpBinding binding property values
            binding1.Name = "Binding1";
            binding1.HostNameComparisonMode =
            binding1.Security.Mode = SecurityMode.Message;
            binding1.ReliableSession.Enabled = false;
            binding1.TransactionFlow = false;
           // binding1.Security.Message.DefaultProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign; 

            // Enumerate properties of the binding1.
            Console.WriteLine("WSHttpBinding binding1 properties:");
            Console.WriteLine("      - name:\t\t\t{0}", binding1.Name);
            Console.WriteLine("      - hostname comparison:\t{0}", binding1.HostNameComparisonMode);
            Console.WriteLine("      - security mode:\t\t{0}", binding1.Security.Mode);
            Console.WriteLine("      - RM enabled:\t\t{0}", binding1.ReliableSession.Enabled);
            Console.WriteLine("      - transaction flow:\t{0}", binding1.TransactionFlow);
            //Console.WriteLine("      - message security:\t{0}", binding1.Security.Message.DefaultProtectionLevel);
            Console.WriteLine("      - transport scheme:\t{0}", binding1.Scheme);
            Console.WriteLine("      - max message size:\t{0}", binding1.MaxReceivedMessageSize);
            Console.WriteLine("      - default text encoding:\t{0}", binding1.TextEncoding);

            // Create a WSFederationBinding with a message security mode 
            // and with a reliable session enabled.
            WSFederationHttpBinding binding3 = new WSFederationHttpBinding(WSFederationHttpSecurityMode.Message, true);

            // Enumerate properties of the binding2.
            Console.WriteLine("WSFederationBinding binding3 properties:");
            Console.WriteLine("      - security mode:\t\t{0}", binding3.Security.Mode);
            Console.WriteLine("      - RM enabled:\t\t{0}", binding3.ReliableSession.Enabled);
            Console.WriteLine("Press <ENTER> to terminate.");


	static void SnippetReceiveSynchronously ()
		WSHttpBinding binding = new WSHttpBinding();
		IBindingRuntimePreferences s  =
					       (new BindingParameterCollection());
		bool receiveSynchronously = s.ReceiveSynchronously;



Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0