2011年7月21日 星期四

WCF教學(2) - 變更預設的Binding

延續WCF教學(1) - 建立WCF服務

當你建立WCF Service Library專案時,預設會使用wsHttpBinding,本練習將修改為basicHttpBinding,並透過組態檔設定進階的Binding資訊。
  • 組態工具
image
  • 修改預設的wsHttpBinding為basicHttpBinding
image
  • 新增組態設定
image
  • 選basicHttpBinding
image
  • 設SendTimeOut為10分
image
  • 在服務套用binding
image
  • CTRL+S 儲存
image
  • 目前app.config內容如下
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="NewBinding0" sendTimeout="00:10:00" />
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="WcfServiceLibrary1.Calc">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="NewBinding0"
          contract="WcfServiceLibrary1.IMyService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information,
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes,
          set the value below to true.  Set to false before deployment
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>
  • F5, Run,可以正確執行運算
 image

沒有留言:

總瀏覽量