BasicHttpBinding Class

Represents a binding that a Windows Communication Foundation (WCF) service can use to configure and expose endpoints that are able to communicate with ASMX-based Web services and clients and other services that conform to the WS-I Basic Profile 1.1.

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

'Declaration
Public Class BasicHttpBinding _
	Inherits Binding _
	Implements IBindingRuntimePreferences
'Usage
Dim instance As BasicHttpBinding

The BasicHttpBinding uses HTTP as the transport for sending SOAP 1.1 messages. A service can use this binding to expose endpoints that conform to WS-I BP 1.1, such as those that ASMX clients access. Similarly, a client can use the BasicHttpBinding to communicate with services exposing endpoints that conform to WS-I BP 1.1, such as ASMX Web services or Windows Communication Foundation (WCF) services configured with the BasicHttpBinding.

Security is turned off by default, but can be added setting the BasicHttpSecurityMode to a value other than None in the BasicHttpBinding(BasicHttpSecurityMode) constructor. It uses a "Text" message encoding and UTF-8 text encoding by default.

The following example shows how to configure the BasicHttpBinding in an application configuration file.

<system.serviceModel>
  <services>
    <service
        name="Microsoft.ServiceModel.Samples.CalculatorService"
        behaviorConfiguration="CalculatorServiceBehavior">
      <!-- use base address provided by host -->
      <!-- specify BasicHttp binding and a binding configuration to use -->
      <endpoint address=""
                binding="basicHttpBinding"
                bindingConfiguration="Binding1"
                contract="Microsoft.ServiceModel.Samples.ICalculator" />
    </service>
  </services>

  <bindings>
    <!-- 
          Following is the expanded configuration section for a BasicHttpBinding.
          Each property is configured with the default value.
          See the TransportSecurity, and MessageSecurity samples in the
          Basic directory to learn how to configure these features.
          -->
    <basicHttpBinding>
      <binding name="Binding1"
               hostNameComparisonMode="StrongWildcard"
               receiveTimeout="00:10:00"
               sendTimeout="00:10:00"
               openTimeout="00:10:00"
               closeTimeout="00:10:00"
               maxReceivedMessageSize="65536"
               maxBufferSize="65536"
               maxBufferPoolSize="524288"
               transferMode="Buffered"
               messageEncoding="Text"
               textEncoding="utf-8"
               bypassProxyOnLocal="false"
               useDefaultWebProxy="true" >
        <security mode="None" />
      </binding>
    </basicHttpBinding>
  </bindings>

  <!--For debugging purposes set the returnUnknownExceptionsAsFaults attribute to true-->
  <behaviors>
    <serviceBehaviors>
      <behavior name="CalculatorServiceBehavior">
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>

</system.serviceModel>

The following example shows how to programmatically configure BasicHttpBinding.

   <ServiceContract(Namespace:="http://UE.ServiceModel.Samples")> _
   Public Interface ICalculator

       <OperationContract()> _
       Function Add(ByVal n1 As Double, ByVal n2 As Double) As Double
       <OperationContract()> _
       Function Subtract(ByVal n1 As Double, ByVal n2 As Double) As Double
       <OperationContract()> _
       Function Multiply(ByVal n1 As Double, ByVal n2 As Double) As Double
       <OperationContract()> _
       Function Divide(ByVal n1 As Double, ByVal n2 As Double) As Double 
   End Interface 

   ' Service class which implements the service contract. 
   ' Added code to write output to the console window 
   Public Class CalculatorService
       Implements ICalculator

       Public Function Add(ByVal n1 As Double, ByVal n2 As Double) As Double _
Implements ICalculator.Add

           Dim result As Double = n1 + n2
           Console.WriteLine("Received Add({0},{1})", n1, n2)
           Console.WriteLine("Return: {0}", result)
           Return result
       End Function 

       Public Function Subtract(ByVal n1 As Double, ByVal n2 As Double) As Double _
Implements ICalculator.Subtract

           Dim result As Double = n1 - n2
           Console.WriteLine("Received Subtract({0},{1})", n1, n2)
           Console.WriteLine("Return: {0}", result)
           Return result
       End Function 

       Public Function Multiply(ByVal n1 As Double, ByVal n2 As Double) As Double _
Implements ICalculator.Multiply

           Dim result As Double = n1 * n2
           Console.WriteLine("Received Multiply({0},{1})", n1, n2)
           Console.WriteLine("Return: {0}", result)
           Return result
       End Function 

       Public Function Divide(ByVal n1 As Double, ByVal n2 As Double) As Double _
Implements ICalculator.Divide

           Dim result As Double = n1 / n2
           Console.WriteLine("Received Divide({0},{1})", n1, n2)
           Console.WriteLine("Return: {0}", result)
           Return result
       End Function 

       Public Shared Sub Main()
           Dim binding As BasicHttpBinding = New BasicHttpBinding()
           binding.Name = "binding1"
           binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard
           binding.Security.Mode = BasicHttpSecurityMode.None

           Dim baseAddress As Uri = New Uri("http://localhost:8000/servicemodelsamples/service")
           Dim address As Uri = New Uri("http://localhost:8000/servicemodelsamples/service/calc")

           ' Create a ServiceHost for the CalculatorService type and provide the base address. 
           Using serviceHost As ServiceHost = New ServiceHost(GetType(CalculatorService), baseAddress)

               serviceHost.AddServiceEndpoint(GetType(ICalculator), binding, address)

               ' Open the ServiceHost to create listeners and start listening for messages.
               serviceHost.Open()

               ' The service can now be accessed.
               Console.WriteLine("The service is ready.")
               Console.WriteLine("Press <ENTER> to terminate service.")
               Console.WriteLine()
               Console.ReadLine()

               ' Close the ServiceHost to shutdown the service.
               serviceHost.Close()
           End Using 
       End Sub 
   End Class

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, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

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

.NET Compact Framework

Supported in: 3.5
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft