共用方式為


<basicHttpBinding>

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.

<system.serviceModel>

  <bindings>

    <basicHttpBinding>

                                    
                                    <basicHttpBinding>
                                
                                    
                                       <binding 
                                
                                    
                                           allowCookies="Boolean"
                                
                                    
                                           bypassProxyOnLocal="Boolean"
                                
                                    
                                           closeTimeout="TimeSpan" 
                                
                                    
                                           envelopeVersion="None/Soap11/Soap12"
                                
                                    
                                           hostNameComparisonMode="StrongWildCard/Exact/WeakWildcard"
                                
                                    
                                           maxBufferPoolSize="Integer"
                                
                                    
                                           maxBufferSize="Integer"
                                
                                    
                                           maxReceivedMessageSize="Integer"
                                
                                    
                                           messageEncoding="Text/Mtom"
                                
                                    
                                               
                                    
                                           name="string" 
                                
                                    
                                           openTimeout="TimeSpan" 
                                
                                    
                                           proxyAddress="URI"
                                
                                    
                                         
                                    
                                           receiveTimeout="TimeSpan"
                                
                                    
                                           sendTimeout="TimeSpan"
                                
                                    
                                               
                                    
                                           textEncoding="UnicodeFffeTextEncoding/Utf16TextEncoding/Utf8TextEncoding"
                                
                                    
                                               
                                    
                                           transferMode="Buffered/Streamed/StreamedRequest/StreamedResponse"
                                
                                    
                                           useDefaultWebProxy="Boolean"
                                
                                    
                                           <security mode="None/Transport/Message/TransportWithMessageCredential/TransportCredentialOnly">
                                
                                    
                                               <transport clientCredentialType="None/Basic/Digest/Ntlm/Windows/Certificate"
                                
                                    
                                                      proxyCredentialType="None/Basic/Digest/Ntlm/Windows"
                                
                                    
                                                          
                                    
                                                      realm="string" />
                                
                                    
                                               <message  algorithmSuite="Aes128/Aes192/Aes256/Rsa15Aes128/ Rsa15Aes256/TripleDes"
                                
                                    
                                                          
                                    
                                                      clientCredentialType="UserName/Certificate"/>
                                
                                    
                                           </security>
                                
                                    
                                           <readerQuotas maxDepth="Integer" 
                                
                                    
                                                maxStringContentLength="Integer"
                                
                                    
                                                maxByteArrayContentLength="Integer"
                                
                                    
                                                maxBytesPerRead="Integer"
                                
                                    
                                                maxNameTableCharCount="Integer" />
                                
                                    
                                       </binding>
                                
                                    
                                    </basicHttpBinding>
                                

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.

Attributes

Attribute Description

allowCookies

A Boolean value that indicates whether the client accepts cookies and propagates them on future requests. The default is false.

You can use this property when you interact with ASMX Web services that use cookies. In this way, you can be sure that the cookies returned from the server are automatically copied to all future client requests for that service.

bypassProxyOnLocal

A Boolean value that indicates whether to bypass the proxy server for local addresses. The default is false.

An Internet resource is local if it has a local address. A local address is one that is on same computer, the local LAN or intranet and is identified, syntactically, by the lack of a period (.) as in the URIs "http://webserver/" and "https://localhost/".

Setting this attribute determines whether endpoints configured with the BasicHttpBinding use the proxy server when accessing local resources. If this attribute is true, requests to local Internet resources do not use the proxy server. Use the host name (rather than localhost) if you want clients to go through a proxy when talking to services on the same machine when this attribute is set to true.

When this attribute is false, all Internet requests are made through the proxy server.

closeTimeout

A TimeSpan value that specifies the interval of time provided for a close operation to complete. This value should be greater than or equal to Zero. The default is 00:01:00.

envelopeVersion

Specifies the version of SOAP that is used for messages that are processed by this binding. The only valid value is Soap11.

hostnameComparisonMode

Specifies the HTTP hostname comparison mode used to parse URIs. This attribute is of type HostnameComparisonMode, which indicates whether the hostname is used to reach the service when matching on the URI. The default value is StrongWildcard, which ignores the hostname in the match.

maxBufferPoolSize

An integer value that specifies the maximum amount of memory that is allocated for use by the manager of the message buffers that receive messages from the channel. The default value is 524288 (0x80000) bytes.

The Buffer Manager minimizes the cost of using buffers by using a buffer pool. Buffers are required to process messages by the service when they come out of the channel. If there is not sufficient memory in the buffer pool to process the message load, the Buffer Manager must allocate additional memory from the CLR heap, which increases the garbage collection overhead. Extensive allocation from the CLR garbage heap is an indication that the buffer pool size is too small and that performance can be improved with a larger allocation by increasing the limit specified by this attribute.

maxBufferSize

An integer value that specifies the maximum size, in bytes, of a buffer that stores messages while they are processed for an endpoint configured with this binding. The default value is 65,536 bytes.

maxReceivedMessageSize

A positive integer that defines the maximum message size, in bytes, including headers, for a message that can be received on a channel configured with this binding. The sender receives a SOAP fault if the message is too large for the receiver. The receiver drops the message and creates an entry of the event in the trace log. The default is 65,536 bytes.

messageEncoding

Defines the encoder used to encode the SOAP message. Valid values include the following:

  • Text: Use a text message encoder.

  • Mtom: Use a Message Transmission Organization Mechanism 1.0 (MTOM) encoder.

The default is Text. This attribute is of type WSMessageEncoding.

messageVersion

Specifies the message version used by clients and services configured with the binding. This attribute is of type MessageVersion.

name

A string that contains the configuration name of the binding. This value should be unique because it is used as an identification for the binding. Each binding has a name and namespace attribute that together uniquely identify it in the metadata of the service. In addition, this name is unique among bindings of the same type.

namespace

Specifies the XML namespace of the binding. The default value is "http://tempuri.org/Bindings". Each binding has a name and namespace attribute that together uniquely identify it in the metadata of the service.

openTimeout

A TimeSpan value that specifies the interval of time provided for an open operation to complete. This value should be greater than or equal to Zero. The default is 00:01:00.

proxyAddress

A URI that contains the address of the HTTP proxy. If useSystemWebProxy is set to true, this setting must be null. The default is null.

receiveTimeout

A TimeSpan value that specifies the interval of time provided for a receive operation to complete. This value should be greater than or equal to Zero. The default is 00:10:00.

sendTimeout

A TimeSpan value that specifies the interval of time provided for a send operation to complete. This value should be greater than or equal to Zero. The default is 00:01:00.

textEncoding

Sets the character set encoding to be used for emitting messages on the binding. Valid values include the following:

  • BigEndianUnicode: Unicode BigEndian encoding.

  • Unicode: 16-bit encoding.

  • UTF8: 8-bit encoding

The default is UTF8. This attribute is of type Encoding.

transferMode

A valid TransferMode value that specifies whether messages are buffered or streamed on a request or response.

useDefaultWebProxy

A Boolean value that specifies whether the auto-configured HTTP proxy of the system should be used, if available. The default is true.

Child Elements

Element Description

<security> of <basicHttpBinding>

Defines the security settings for the binding. This element is of type BasicHttpSecurityElement.

<readerQuotas>

Defines the constraints on the complexity of SOAP messages that can be processed by endpoints configured with this binding. This element is of type XmlDictionaryReaderQuotasElement.

Parent Elements


Element Description

<bindings>

This element holds a collection of standard and custom bindings. Each entry is identified by its unique name. Services use bindings by linking them using the name.

Remarks

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 consume. 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 services configured with the BasicHttpBinding.

Security is turned off by default, but can be added setting the mode attribute of the <security> of <basicHttpBinding> child element to a value other than None. It uses a "Text" message encoding and UTF-8 text encoding by default.

Example

The following example demonstrates the use of basicHttpBinding that provides HTTP communication and maximum interoperability with first- and second-generation Web services. The binding is specified in the configuration files for the client and service. The binding type is specified using the binding attribute of the <endpoint> element. If you want to configure the basic binding and change some of its settings, it is necessary to define a binding configuration. The endpoint must reference the binding configuration by name by using the bindingConfiguration attribute of the <endpoint> element, as shown in the following configuration code for the service.

<system.serviceModel> 
  <services>
    <service 
        type="Microsoft.ServiceModel.Samples.CalculatorService"
        behaviorConfiguration="CalculatorServiceBehavior">
       <endpoint address=""
             binding="basicHttpBinding"
             bindingConfiguration="Binding1" 
             contract="Microsoft.ServiceModel.Samples.ICalculator" />
    </service>
  </services>
  <bindings>
     <basicHttpBinding>
        <binding name="Binding1" 
               hostNameComparisonMode="StrongWildcard" 
               receiveTimeout="00:10:00"
               sendTimeout="00:10:00"
               openTimeout="00:10:00"
               closeTimeout="00:10:00"
               maxMessageSize="65536" 
               maxBufferSize="65536" 
               maxBufferPoolSize="524288" 
               transferMode="Buffered" 
               messageEncoding="Text" 
               textEncoding="utf-8"
               bypassProxyOnLocal="false"
               useDefaultWebProxy="true" >
              <security mode="None" />
         </binding>
     </basicHttpBinding>
  </bindings>
</system.serviceModel>

See Also

Reference

BasicHttpBinding

Footer image

Send comments about this topic to Microsoft.
© Microsoft Corporation. All rights reserved.