共用方式為


<netNamedPipeBinding>

定義一種安全、可靠且優化於機器跨程序通訊的綁定。 預設情況下,它會產生一個執行時通訊堆疊,包含 WS-ReliableMessaging 以提升可靠性、傳輸安全性以保障傳輸安全、命名管線用於訊息傳遞,以及二進位訊息編碼。

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

語法

<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>

屬性和項目

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

Attributes

Attribute Description
結束 時間 一個 TimeSpan 指定緊密操作完成所需時間間隔的值。 此值應大於或等 Zero於 。 預設值是 00:01:00。
hostNameComparisonMode 指定用於解析 URI 的 HTTP 主機名稱比較模式。 此屬性的型別 HostNameComparisonMode為 ,表示在 URI 匹配時是否使用主機名稱來存取服務。 預設值為 StrongWildcard,忽略了配對中的主機名稱。
maxBufferPoolSize 一個整數,指定此綁定的最大緩衝池大小。 預設為 524,288 位元組(512 × 1024)。 Windows 通訊基礎(WCF)的許多部分都使用緩衝區。 每次使用緩衝區都建立與銷毀成本高昂,緩衝區的垃圾回收也同樣昂貴。 使用緩衝池時,你可以從緩衝池中取一個緩衝區,使用完畢後再歸還給池。 因此避免了建立與銷毀緩衝區的開銷。
最大緩衝區大小 一個正整數,指定用於儲存訊息的緩衝區最大大小(以位元組為單位)。 若緩衝區已滿,多餘資料會留在底層插槽中,直到緩衝區再次有空間。 這個值不能小於 maxReceivedMessageSize 屬性。 預設是 65536。 如需詳細資訊,請參閱MaxBufferSize
最大連接數 一個整數,指定服務將建立/接受的最大出站與入站連線數量。 進出連線會依據此屬性指定的獨立限制計算。

超出限制的入站連線會排隊,直到有空位低於限制為止。

超出限制的出站連線會排隊,直到有空間低於限制。

預設值為 10。
最大接收訊息大小 一個正整數,指定在設定此綁定的通道上可接收的最大訊息大小(以位元組計,包括標頭)。 超過此限制的訊息發送者將收到 SOAP 錯誤。 接收端會丟棄訊息,並在追蹤日誌中建立事件的條目。 預設是 65536。
名稱 一個包含綁定設定名稱的字串。 這個值應該是唯一的,因為它是用來識別裝訂的。 從 .NET Framework 4 開始,綁定和行為不再需要名稱。 欲了解更多關於預設設定及無名綁定與行為的資訊,請參閱簡化設定與簡化配置(Simplified Configuration for WCF Services)。
openTimeout 一個 TimeSpan 指定開啟操作完成所需時間區間的值。 此值應大於或等 Zero於 。 預設值是 00:01:00。
收到Timeout 一個 TimeSpan 指定接收操作完成所需時間區間的值。 此值應大於或等 Zero於 。 預設值是 00:10:00。
sendTimeout 一個 TimeSpan 指定傳送操作完成所需時間間隔的值。 此值應大於或等 Zero於 。 預設值是 00:01:00。
transactionFlow 一個布林值,指定綁定是否支援流動的 WS-Transactions。 預設值為 false
transactionProtocol 指定與此綁定一起使用的交易協定。 有效的數值為

- OleTransactions
- WS-AtomicTransactionOctober2004

預設為 OleTransactions。 此屬性的類型 TransactionProtocol為 。
傳輸模式 一個 TransferMode 指定訊息是緩衝、串流、請求還是回應的值。

子專案

元素 Description
<安全> 定義綁定的安全設定。 此元素的類型 NetNamedPipeBindingElement為 。
<讀者配額> 定義了由端點可處理的 SOAP 訊息複雜度的限制,這些訊息可由配置為此綁定的端點所能處理。 此元素的類型 XmlDictionaryReaderQuotasElement為 。

父項目

元素 Description
<裝訂> 此元素包含標準與自訂裝訂的集合。

備註

預設會 NetNamedPipeBinding 產生執行時通訊堆疊,使用傳輸安全性、命名管線進行訊息傳遞,以及二進位訊息編碼。 此綁定是 Windows 通訊基金會(WCF)系統提供的機器上通訊適宜選擇。 它也支援交易。

預設 NetNamedPipeBinding 配置與 所提供的 NetTcpBinding配置相似,但更簡單,因為 WCF 實作僅供機器上使用,因此暴露功能較少。 最顯著的差異是設定 securityMode 只提供 NoneTransport 選項。 SOAP 安全支援並非包含在內的選項。 安全性行為可透過可選 securityMode 屬性進行配置。

Example

以下範例展示了 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>

另請參閱