<customBinding>

對使用者提供訊息堆疊的完整控制權。Provides full control over the messaging stack for the user.

<configuration>
  <system.serviceModel>
    <bindings>
      <customBinding>

語法Syntax

<customBinding>
  <binding name="String"
           closeTimeout="TimeSpan"
           openTimeout="TimeSpan"
           receiveTimeout="TimeSpan"
           sendTimeout="TimeSpan">
    <compositeDuplex clientBaseAddress="Uri" />
    <reliableSession acknowledgementInterval="TimeSpan"
                     advancedFlowControl="Boolean"
                     bufferedMessagesQuota="Integer"
                     inactivityTimeout="TimeSpan"
                     maxPendingChannels="Integer"
                     maxRetryCount="Integer"
                     ordered="Boolean" />
    <pnrpPeerResolver />
    <windowsStreamSecurity protectionLevel="None/Sign/EncryptAndSign" />
    <sslStreamSecurity requireClientCertificate="Boolean" />
    <transactionFlow transactionProtocol="OleTransactions/WSAtomicTransactionOctober2004" />
    <security defaultAlgorithmSuite="Basic128/Basic192/Basic256/Basic128Rsa15/Basic256Rsa15/TripleDes/TripleDesRsa15/Basic128Sha256/Basic192Sha256/TripleDesSha256/Basic128Sha256Rsa15/Basic192Sha256Rsa15/Basic256Sha256Rsa15/TripleDesSha256Rsa15"
              authenticationMode="UserNameForAnonymous"
              contextMode="Cookie"
              defaultProtectionLevel="Sign"
              enableKeyDerivation="false"
              keyEntropyMode="ClientEntropy"
              messageProtectionOrder="SignBeforeEncryptAndEncryptSignature"
              securityVersion="WSSecurityXXX2005">
      <localClientSettings cacheCookies="false"
                           detectReplays="false"
                           maxCookieCachingTime="00:07:24" />
      <localServiceSettings replayCacheSize="9"
                            maxClockSkew="00:00:03"
                            replayWindow="00:07:22.2190000" />
    </security>
    <binaryMessageEncoding maxReadPoolSize="Integer"
                           maxWritePoolSize="Integer"
                           maxSessionSize="Integer" />
    <httpsTransport manualAddressing="Boolean"
                    maxMessageSize="Integer"
                    authenticationScheme="Negotiate"
                    bypassProxyOnLocal="Boolean"
                    hostNameComparisonMode="Exact"
                    mapAddressingHeadersToHttpHeaders="Boolean"
                    proxyaddress="Uri"
                    realm="String"
                    requireClientCertificate="Boolean" />
    <peerTransport manualAddressing="false"
                   maxMessageSize="20002"
                   listenIPAddress="202.10.1.9"
                   messageAuthentication="false"
                   peerNodeAuthenticationMode="None"
                   port="1000" />
    <security defaultAlgorithmSuite="Basic128/Basic192/Basic256/Basic128Rsa15/Basic256Rsa15/TripleDes/TripleDesRsa15/Basic128Sha256/Basic192Sha256/TripleDesSha256/Basic128Sha256Rsa15/Basic192Sha256Rsa15/Basic256Sha256Rsa15/TripleDesSha256Rsa15"
              authenticationMode="UserNameForAnonymous"
              bootstrapBindingConfiguration="String"
              bootstrapBindingSectionName="String"
              defaultProtectionLevel="None/Sign/EncryptAndSign"
              requireDerivedKeys="Boolean"
              securityHeaderLayout="Strict/Lax/LaxTimestampFirst/LaxTimestampLast"
              includeTimestamp="Boolean"
              keyEntropyMode="ClientEntropy/ServerEntropy/CombinedEntropy"
              messageProtectionOrder="SignBeforeEncrypt/SignBeforeEncryptAndEncryptSignature/EncryptBeforeSign"
              protectTokens="Boolean"
              requireSecurityContextCancellation="Boolean"
              securityVersion=" WSSecurityJan2004/WSSecurityXXX2005"
              requireSignatureConfirmation="Boolean">
      <localClientSettings cacheCookies="Boolean"
                           detectReplays="Boolean"
                           replayCacheSize="Integer"
                           maxClockSkew="TimeSpan"
                           maxCookieCachingTime="TimeSpan"
                           replayWindow="TimeSpan"
                           sessionKeyRenewalInterval="TimeSpan"
                           sessionKeyRolloverInterval="TimeSpan"
                           reconnectOnTransportFailure="Boolean"
                           timestampValidityDuration="TimeSpan"
                           cookieRenewalThresholdPercentage="Integer" />
      <localServiceSettings detectReplays="Boolean"
                            issuedCookieLifeTime="TimeSpan"
                            maxStatefulNegotiations="Integer"
                            replayCacheSize="Integer"
                            maxClockSkew="TimeSpan"
                            negotiationTimeout="TimeSpan"
                            replayWindow="TimeSpan"
                            inactivityTimeout="TimeSpan"
                            sessionKeyRenewalInterval="TimeSpan"
                            sessionKeyRolloverInterval="TimeSpan"
                            reconnectOnTransportFailure="Boolean"
                            maxConcurrentSessions="Integer"
                            timestampValidityDuration="TimeSpan" />
      <federationParameters trustVersion="WSTrustApr2004/WSTrustFeb2005" />
    </security>
    <security defaultAlgorithmSuite="Basic128/Basic192/Basic256/Basic128Rsa15/Basic256Rsa15/TripleDes/TripleDesRsa15/Basic128Sha256/Basic192Sha256/TripleDesSha256/Basic128Sha256Rsa15/Basic192Sha256Rsa15/Basic256Sha256Rsa15/TripleDesSha256Rsa15"
              authenticationMode="UserNameForAnonymous"
              bootstrapBindingConfiguration="String"
              bootstrapBindingSectionName="String"
              defaultProtectionLevel="None/Sign/EncryptAndSign"
              requireDerivedKeys="Boolean"
              securityHeaderLayout="Strict/Lax/LaxTimestampFirst/LaxTimestampLast"
              includeTimestamp="Boolean"
              keyEntropyMode="ClientEntropy/ServerEntropy/CombinedEntropy"
              messageProtectionOrder="SignBeforeEncrypt/SignBeforeEncryptAndEncryptSignature/EncryptBeforeSign"
              protectTokens="Boolean"
              requireSecurityContextCancellation="Boolean"
              securityVersion=" WSSecurityJan2004/WSSecurityXXX2005"
              requireSignatureConfirmation="Boolean" >
      <localClientSettings cacheCookies="Boolean"
                           detectReplays="Boolean"
                           replayCacheSize="Integer"
                           maxClockSkew="TimeSpan"
                           maxCookieCachingTime="TimeSpan"
                           replayWindow="TimeSpan"
                           sessionKeyRenewalInterval="TimeSpan"
                           sessionKeyRolloverInterval="TimeSpan"
                           reconnectOnTransportFailure="Boolean"
                           timestampValidityDuration="TimeSpan"
                           cookieRenewalThresholdPercentage="Integer" />
      <localServiceSettings detectReplays="Boolean"
                           issuedCookieLifeTime="TimeSpan"
                           maxStatefulNegotiations="Integer"
                           replayCacheSize="Integer"
                           maxClockSkew="TimeSpan"
                           negotiationTimeout="TimeSpan"
                           replayWindow="TimeSpan"
                           inactivityTimeout="TimeSpan"
                           sessionKeyRenewalInterval="TimeSpan"
                           sessionKeyRolloverInterval="TimeSpan"
                           reconnectOnTransportFailure="Boolean"
                           maxConcurrentSessions="Integer"
                           timestampValidityDuration="TimeSpan" />
      <federationParameters trustVersion="WSTrustApr2004/WSTrustFeb2005" />
      <genericIssuedTokenParameters>
        <localIssuerIssuedTokenParameters keyType="SymmetricKey/PublicKey"
                                          keySize="Integer"
                                          tokenType="String" />
        <issuedTokenParametersEndpointAddress address="URI"
                                              bindingConfiguration="String"
                                              binding="String" />
        <issuedTokenClient localIssuerChannelBehaviors="String"
                           cacheIssuedTokens="Boolean"
                           maxIssuedTokenCachingTime="TimeSpan"
                           keyEntropyMode="ClientEntropy/ServerEntropy/CombinedEntropy" />
        <issuedTokenClientBehavior issuerAddress="String"
                                   behaviorConfiguration="String" />
        <issuedTokenClientBehavior address="URI"
                                   bindingConfiguration="String"
                                   binding="String" />
      </genericIssuedTokenParameters>
    </security>
  </binding>
</customBinding>

屬性和項目Attributes and Elements

下列各節說明屬性、子元素和父元素The following sections describe attributes, child elements, and parent elements

屬性Attributes

屬性Attribute 描述Description
closeTimeoutcloseTimeout TimeSpan 值,指定提供用來讓關閉作業完成的時間間隔。A TimeSpan value that specifies the interval of time provided for a close operation to complete. 這個值應該大於或等於 ZeroThis value should be greater than or equal to Zero. 預設為 00:01:00。The default is 00:01:00.
NAMEname 包含繫結之組態名稱的字串。A string that contains the configuration name of the binding. 這個值是使用者定義的字串,它會充當自訂繫結的識別字串。This value is a user-defined string that acts as the identification string for the custom binding. 從 .NET Framework 4 開始,系結和行為都不需要有名稱。Starting with .NET Framework 4, bindings and behaviors are not required to have a name. 如需預設設定和無相關系結和行為的詳細資訊,請參閱簡化的設定和WCF 服務的簡化設定。For more information about default configuration and nameless bindings and behaviors, see Simplified Configuration and Simplified Configuration for WCF Services.
openTimeoutopenTimeout TimeSpan 值,指定提供用來讓開啟作業完成的時間間隔。A TimeSpan value that specifies the interval of time provided for an open operation to complete. 這個值應該大於或等於 ZeroThis value should be greater than or equal to Zero. 預設為 00:01:00。The default is 00:01:00.
receiveTimeoutreceiveTimeout TimeSpan 值,指定接收作業完成其作業之時間間隔。A TimeSpan value that specifies the interval of time provided for a receive operation to complete. 這個值應該大於或等於 ZeroThis value should be greater than or equal to Zero. 預設為 00:01:00。The default is 00:01:00.
sendTimeoutsendTimeout TimeSpan 值,指定提供用來讓傳送作業完成的時間間隔。A TimeSpan value that specifies the interval of time provided for a send operation to complete. 這個值應該大於或等於 ZeroThis value should be greater than or equal to Zero. 預設為 00:01:00。The default is 00:01:00.

子元素Child Elements

元素Element 描述Description
<compositeDuplex> 指定自訂繫結的雙向傳訊。Specifies two-way messaging to the custom binding. 它是和本身不允許雙工通訊的傳輸一起使用,例如 HTTP。It is used with transports that do not allow duplex communications natively, for example, HTTP. 相反地,TCP 本身就允許雙工通訊,因此不需要使用這個繫結項目也可讓服務將訊息傳回用戶端。TCP, by contrast, allows duplex communications natively, and does not require the use of this binding element for the service to send messages back to a client.

用戶端必須公開位址,才能讓服務接觸並建立連接。The client must expose an address for the service to make contact and establish a connection. 這個用戶端位址是由 ClientBaseAddress 屬性提供。This client address is provided by the ClientBaseAddress attribute.

此項目的型別為 CompositeDuplexElementThis element is of type CompositeDuplexElement.
<pnrpPeerResolver> 指定對等名稱解析通訊協定 (PNRP) 對等名稱解析程式。Specifies a Peer Name Resolution Protocol (PNRP) peer name resolver. 此項目的型別為 PnrpPeerResolverElementThis element is of type PnrpPeerResolverElement.
<reliableSession> 指定 WS-Reliable 訊息設定。Specifies the setting for WS-Reliable Messaging. 將這個項目新增至自訂繫結時,產生的通道可支援確實傳送一次保證。When this element is added to a custom binding, the resulting channel can support exactly-once delivery assurances. 此項目的型別為 ReliableSessionElementThis element is of type ReliableSessionElement.
<security> 指定自訂繫結的安全性選項。Specifies the options for security of the custom binding. 此項目的型別為 SecurityElementThis element is of type SecurityElement.
<sslStreamSecurity> 指定 SSL 資料流繫結的安全性設定。Specifies the security settings for a SSL stream binding. 此項目的型別為 SslStreamSecurityElementThis element is of type SslStreamSecurityElement.
<transactionFlow> 指定繫結應支援交易流程,並指定 transactionProtocol 屬性使用的通訊協定。Specifies that the binding supports transaction flow, and the protocol to be used by the transactionProtocol attribute. 此項目的型別為 TransactionFlowElementThis element is of type TransactionFlowElement.
<windowsStreamSecurity> 指定自訂繫結的資料流 (Streaming) 安全性選項。Specifies the options for streaming security of the custom binding. 此項目的型別為 WindowsStreamSecurityElementThis element is of type WindowsStreamSecurityElement.

父項目Parent Elements

元素Element 描述Description
繫結bindings 包含 Windows Communication Foundation 應用程式的所有繫結。Contains all bindings for Windows Communication Foundation applications.

備註Remarks

自訂繫結會提供對於 WCF 訊息堆疊的完整控制權。Custom bindings provide full control over the WCF messaging stack. 您可以新增特定實體的組態項目,來建立特別量身訂作的繫結。Special tailored bindings can be created my adding the configuration elements for specific entities. 例如,使用者可結合 httpsTransport 區段、reliableSession 區段和 security 區段來建立可靠且安全的 https 繫結。For example, the user can combine the httpsTransport section, reliableSession section and the security section to create a reliable and secure https based binding.

個別繫結定義訊息堆疊的方式,是依據堆疊項目在堆疊中的出現順序來指定其組態項目。An individual binding defines the message stack by specifying the configuration elements for the stack elements in the order they appear on the stack. 每個項目都會定義及設定堆疊的一個項目。Each element defines and configures the one element of the stack. 各個自訂繫結中一定要出現一個而且是唯一一個的傳輸項目。There must be one and only one transport element in each custom binding. 如果沒有這個項目,訊息堆疊就不完整。Without this element, the messaging stack is incomplete.

項目在堆疊中的出現順序很重要,因為這是作業套用至訊息的順序。The order in which elements appear in the stack matters, because it is the order in which operations are applied to the message. 建議的堆疊項目順序如下所示:The recommended order of stack elements is the following:

  1. 交易 (選擇性)Transactions (optional)

  2. 可信賴傳訊 (選擇性)Reliable Messaging (optional)

  3. 安全性 (選擇性)Security (optional)

  4. 傳輸Transport

  5. 編碼器 (選擇性)Encoder (optional)

當系統提供的其中一個繫結程序不符合服務的需求時,請使用自訂繫結程序。Use a custom binding when one of the system-provided bindings does not meet the requirements of your service. 例如,若要在服務端點上啟用新的傳輸或新的編碼器,可以使用自訂繫結。A custom binding could be used, for example, to enable the use of a new transport or a new encoder at a service endpoint.

在建構自訂繫結時,會使用依據特定順序堆疊之繫結項目集合中的其中一個 CustomBindingA custom binding is constructed using one of the CustomBinding from a collection of binding elements that are "stacked" in a specific order:

下表摘要列出每一層的選項。The following table summarizes the options for each layer.

階層Layer 選項Options 必要Required
異動流程Transaction Flow TransactionFlowBindingElement No
可靠性Reliability ReliableSessionBindingElement No
安全性Security 對稱、不對稱、傳輸層級Symmetric, Asymmetric, Transport-Level No
形狀變更Shape Change CompositeDuplexBindingElement No
傳輸升級Transport Upgrades SSL 資料流、Windows 資料流、對等解析程式SSL stream, Windows stream, Peer Resolver No
編碼Encoding 文字、二進位、MTOM、自訂Text, Binary, MTOM, Custom Yes
傳輸Transport TCP、具名管道、HTTP、HTTPS、MSMQ 的類別、自訂TCP, Named Pipes, HTTP, HTTPS, flavors of MSMQ, Custom Yes

此外,您也可以定義自己的繫結項目,並將其插入上述任何定義層之間。In addition, you can define your own binding elements and insert them between any of the preceding defined layers.

如需如何使用自訂系結來修改系統提供之系結的討論,請參閱如何:自訂系統提供的系結。For a discussion on how to use a custom binding to modify a system-provided binding, see How to: Customize a System-Provided Binding.

另請參閱See also