WCF使用net.tcp綁定時的注意事項


IIS Express沒有net.tcp綁定功能,本地測試的話只能使用本機的IIS進行承載,並且需要相應的配置(參見上一篇文章)。

算了,直接舉一個配置例子吧,懶得寫了。。。

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <!--默認http綁定的配置,這里提高了最大傳輸信息的大小,如不需要可以不設置綁定配置-->
        <binding name="DefaultBasicHttpBinding"  maxBufferSize="10485760" maxReceivedMessageSize="10485760" />
      </basicHttpBinding>
      <netTcpBinding>
        <!--默認net.tcp綁定的配置,貌似必須要對net.tcp方式綁定進行配置-->
        <binding name="DefaultNetTcpBinding" portSharingEnabled="true" transferMode="Buffered">
          <security mode="None" />
        </binding>
      </netTcpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 為避免泄漏元數據信息,請在部署前將以下值設置為 false -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <!-- 要接收故障異常詳細信息以進行調試,請將以下值設置為 true。在部署前設置為 false 以避免泄漏異常信息-->
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="WcfTest.DataService">
        <!-- endpoint 的 address 屬性:
              1、使用絕對路徑(網址);
              2、如果使用相對路徑(網址),則將根據 host 的 baseAddress 確定最終路徑(網址)。 -->
        
        <!--http綁定方式-->
        <endpoint address="" binding="basicHttpBinding" contract="WcfTest.IDataService" bindingConfiguration="DefaultBasicHttpBinding" />
        <!--net.tcp綁定方式-->
        <endpoint address=""  binding="netTcpBinding" contract="WcfTest.IDataService" bindingConfiguration="DefaultNetTcpBinding" />

        <!-- 元數據交換(mex)終結點供相應的服務用於向客戶端做自我介紹。此終結點不使用安全綁定,應在部署前確保其安全或將其刪除 -->
        
        <!--為http綁定提供元數據-->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <!--為net.tcp綁定提供元數據-->
        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
        
        <!--承載WCF服務的基地址。
            注:當使用ASP.NET網站承載WCF服務時,網站需要使用svc文件進行承載服務,此時基地址將變成svc文件的地址。
        -->
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/Design_Time_Addresses/DataService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM