<netNamedPipeBinding>

為電腦上跨處理序通訊定義安全、可靠且經過最佳化的繫結。 根據預設,這個繫結會產生一個執行階段通訊堆疊,並且具備 WS-ReliableMessaging (提供可靠性)、傳輸安全性、具名管道 (用於訊息傳遞) 和二進位訊息編碼。

<configuration>
  <system.serviceModel>
    <bindings>
      <netNamedPipeBinding>

Syntax

<netNamedPipeBinding>
  <binding closeTimeout="TimeSpan"
           hostNameComparisonMode="StrongWildCard/Exact/WeakWildcard"
           maxBufferPoolSize="Integer"
           maxBufferSize="Integer"
           maxConnections="Integer"
           maxReceivedMessageSize="Integer"
           name="String"
           openTimeout="TimeSpan"
           receiveTimeout="TimeSpan"
           sendTimeout="TimeSpan"
           transactionFlow="Boolean"
           transactionProtocol="OleTransactions/WS-AtomicTransactionOctober2004"
           transferMode="Buffered/Streamed/StreamedRequest/StreamedResponse">
    <security mode="None/Transport">
      <transport protectionLevel="None/Sign/EncryptAndSign" />
    </security>
    <readerQuotas maxArrayLength="Integer"
                  maxBytesPerRead="Integer"
                  maxDepth="Integer"
                  maxNameTableCharCount="Integer"
                  maxStringContentLength="Integer" />
  </binding>
</netNamedPipeBinding>

屬性和項目

下列各節說明屬性、子元素和父元素

屬性

屬性 描述
closeTimeout TimeSpan 值,指定提供用來讓關閉作業完成的時間間隔。 這個值應該大於或等於 Zero。 預設為 00:01:00。
hostNameComparisonMode 指定用於剖析 URI 的 HTTP 主機名稱比較模式。 這個屬性的型別為 HostNameComparisonMode,表示比對 URI 時此主機名稱是否會用來取用服務。 預設值為 StrongWildcard,表示比對時忽略主機名稱。
maxBufferPoolSize 指定此繫結之緩衝區集區大小上限的整數。 預設為 524,288 個位元組 (512 * 1024)。 Windows Communication Foundation (WCF) 的許多部分會使用緩衝區。 每次使用這些組件時建立並終結緩衝區是高度耗費資源的作業,回收緩衝區的記憶體也是如此。 有了緩衝集區,您就可以從集區取出緩衝區來使用,用完後再還給集區, 因此可以避免建立及終結緩衝區的負荷。
maxBufferSize 正整數,指定記憶體中用來儲存訊息的緩衝區大小上限 (以位元組為單位)。 如果緩衝區已滿,超過的資料會保留在基礎通訊端中,直到緩衝區再度有空間為止。 這個值不能小於 maxReceivedMessageSize 屬性。 預設值為 65536。 如需詳細資訊,請參閱MaxBufferSize
maxConnections 整數,指定服務建立/接受的傳出和傳入連線數目上限。 傳入和傳出連線是依據此屬性指定的個別限制來計算的。

超過限制的傳入連線都會排入佇列,直到低於此限制的空間可用為止。

超過限制的傳出連線都會排入佇列,直到低於此限制的空間可用為止。

預設值為 10。
maxReceivedMessageSize 正整數,指定在使用此繫結設定之通道上可以接收的訊息大小上限 (以位元組為單位,包括標頭)。 超出此限制之訊息的寄件者將會收到 SOAP 錯誤。 收件者會捨棄訊息,然後在追蹤記錄檔中建立此事件的項目。 預設值為 65536。
NAME 包含繫結之組態名稱的字串。 這個值應該是唯一的,因為它會當做繫結的識別使用。 從 .NET Framework 4 開始,不需要有名稱的系結和行為。 如需預設設定、無名稱繫結與行為的詳細資訊,請參閱簡化的組態 (部分機器翻譯) 與WCF 服務的簡化組態 (部分機器翻譯)。
openTimeout TimeSpan 值,指定提供用來讓開啟作業完成的時間間隔。 這個值應該大於或等於 Zero。 預設為 00:01:00。
receiveTimeout TimeSpan 值,指定接收作業完成其作業之時間間隔。 這個值應該大於或等於 Zero。 預設為 00:10:00。
sendTimeout TimeSpan 值,指定提供用來讓傳送作業完成的時間間隔。 這個值應該大於或等於 Zero。 預設為 00:01:00。
transactionFlow 指定繫結程序是否支援流動 WS-Transactions 的布林值。 預設值為 false
transactionProtocol 指定要搭配此繫結程序使用的異動通訊協定。 有效值為

- OleTransactions
- WS-AtomicTransactionOctober2004

預設值為 OleTransactions。 此屬性的型別為 TransactionProtocol
transferMode TransferMode 值,指定訊息要經過緩衝處理或資料流處理,或為要求或回應。

子元素

元素 描述
<security> 定義繫結的安全性設定。 此項目的型別為 NetNamedPipeBindingElement
<readerQuotas> 定義 SOAP 訊息複雜度的條件約束,而這些條件約束可由以此繫結所設定的端點處理。 此項目的型別為 XmlDictionaryReaderQuotasElement

父項目

元素 描述
<bindings> 這個項目會保存標準和自訂繫結的集合。

備註

根據預設,NetNamedPipeBinding 會產生執行階段通訊堆疊,此堆疊使用傳輸安全性、具名管道 (用於訊息傳遞) 和二進位訊息編碼。 此繫結為適當的 Windows Communication Foundation (WCF) 系統提供的現成選擇,可用於電腦通訊。 它也支援交易。

NetNamedPipeBinding 的預設組態類似於 NetTcpBinding 所提供的組態,但較為簡單,因為 WCF 實作只針對電腦應用,所以公開的功能不多。 最顯著的差異在於,securityMode 設定只提供 NoneTransport 選項。 SOAP 安全性支援並非包含的選項。 安全性行為可以使用選擇性的 securityMode 屬性進行設定。

範例

下列範例示範 netNamedPipeBinding 繫結,這會在相同電腦上提供跨處理序通訊。 具名通道不會跨電腦作業。

用戶端和服務的組態檔中會指定繫結。 繫結型別是在 binding 項目的 <endpoint> 屬性中指定。 如果您要設定 netNamedPipeBinding 繫結,並變更其部分設定,則您必須定義繫結組態。 端點必須使用 bindingConfiguration 屬性,按照名稱參考繫結組態。 在這個範例中,繫結組態的名稱為 Binding1。

<configuration>
  <system.serviceModel>
    <services>
      <service name="Microsoft.ServiceModel.Samples.CalculatorService"
               behaviorConfiguration="CalculatorServiceBehavior">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8000/ServiceModelSamples/service" />
          </baseAddresses>
        </host>
        <!-- this endpoint is exposed at the base address provided by host: net.pipe://localhost/ServiceModelSamples/service  -->
        <endpoint address="net.pipe://localhost/ServiceModelSamples/service"
                  binding="netNamedPipeBinding"
                  contract="Microsoft.ServiceModel.Samples.ICalculator" />
        <!-- the mex endpoint is exposed at http://localhost:8000/ServiceModelSamples/service/mex -->
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>
    <bindings>
      <netNamedPipeBinding>
        <binding closeTimeout="00:01:00"
                 openTimeout="00:01:00"
                 receiveTimeout="00:10:00"
                 sendTimeout="00:01:00"
                 transactionFlow="false"
                 transferMode="Buffered"
                 transactionProtocol="OleTransactions"
                 hostNameComparisonMode="StrongWildcard"
                 maxBufferPoolSize="524288"
                 maxBufferSize="65536"
                 maxConnections="10"
                 maxReceivedMessageSize="65536">
          <security mode="Transport">
            <transport protectionLevel="EncryptAndSign" />
          </security>
        </binding>
      </netNamedPipeBinding>
    </bindings>
    <!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
    <behaviors>
      <serviceBehaviors>
        <behavior name="CalculatorServiceBehavior">
          <serviceMetadata httpGetEnabled="True" />
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

另請參閱