Asp.Net教程,WinForm教程,Asp.Net MVC,vs2008教程,vs2010教程,Silverlight技术,源码下载,Asp.Net视频教程
全站热门标签
vs2010 Silverlight 存储过程 水晶报表 ADO.NET JavaScript LINQ AjaxPro DataGridView 面向对象 Extjs GridView XML DevExpress HTML教程 Oracle jQuery 分页 GDI+ Visual C++2010 MySQL Office2010 WPF MVC Dojo WCF4.0 VB.NET Sql2005 textbox cookie WCF WinForm Discuz!NT SQL经典语句 T-SQL checkbox ASPxGridView F# asp.net SQL VS2008新特性 DropDownList Access TreeView Ajax VS2008 页面执行时间 Flex 字符串 回调 VB2005 DataSet C#时间 ASP.NET性能优化 用户在线检测 动画
Framework C#技术 VB.NET VC.NET WCFWPF
当前位置: 主页 > WinForm教程 > WPF >

WCF学习序列(十一):配置文件

时间:2010-01-28 20:38来源:未知 作者:admin 点击:

WCF 的配置文件并不复杂,相对于手工编写配置文件,我更倾向于使用 SDK 所附带的工具 —— "Service Configuration Editor"。使用这个工具,我们可以非常方便地创建或修改和客户端的配置文件。


WCF 配置文件基本元素:

<system.ServiceModel>
  <services>
    <service>
      <endpoint/>
    </service>
  </services>
  <bindings>
    <!-- Specify one or more of the system-provided binding elements,
     for example, <basicHttPBinding> --> 
    <!-- Alternatively, <customBinding> elements. -->
    <binding>
    <!-- For example, a <BasicHttpBinding> element. -->
    </binding>
  </bindings>
  <behaviors>
    <!-- One or more of the system-provided or custom behavior elements. -->
    <behavior>
    <!-- For example, a <throttling> element. -->
    </behavior>
  </behaviors>
</system.ServiceModel>

  WCF 的配置信息必须写在 App.config 或 Web.config 中,我觉得像 Remoting 那样可以使用单独的配置文件应该更好一些。现在的项目开发中,各种各样的组件都往 App.config 中写信息,感觉非常凌乱,不便于维护。

在编写服务器端配置文件时,记得添加 serviceMetadata Behaviors,否则我们无法使用 SVCutil.exe 或 VS2005 创建客户端代理文件。

  以下配置文件的演示:

  Server App.config

<?XML version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <services>
      <service behaviorConfiguration="NewBehavior" name="Learn.Library.WCF.MyService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/MyService" />
          </baseAddresses>
        </host>
        <endpoint address="" binding="basicHttPBinding"
          contract="Learn.Library.WCF.IContract" />
        <endpoint address="mex" binding="mexHttpBinding"
          contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="NewBehavior">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

 


Service Configuration Editor 使用方法 图文演示

  1. 打开编辑器,创建新的配置文件。

2. 创建新的服务设置。
 
 

3. 手工输入,或使用 "Browser..." 选择服务所在程序集。
 

4. 确认契约是否正确。
 

5. 选择通讯方式。
 
(责任编辑:admin)
Tags:WCF配置文件
责任编辑:admin
返回顶部
------分隔线----------------------------
推荐内容
骆驼户外男 真皮磨砂日常休闲鞋 低帮 2011秋冬新款 专柜正品特价 骆驼户外男 真皮磨砂日常休闲鞋 低帮 2011秋冬新款 专柜正品特价