学习 WCF (4)--学会使用配置文件
2011-08-08 15:53
405 查看
无论是Web应用程序还是Win应用程序,我们都会经常用到配置文件。WCF作为分布式开发的基础框架,在定义服务以及定义消费服务的客户端时,都使用了配置文件的方法。配置文件的重要性和实用性是大家所熟知的,它可以给我们WCF开发的灵活性上带来很大的提高。下面说说我学习使用配置文件的所得。
WCF的配置使用.NET Framework的System.Configuration配置系统。在Visual Studio中配置一个WCF服务时,如果是自托管宿主或Windows Services宿主
,则配置文件为App.confing,如果是IIS宿主,则配置文件为Web.config。
先来看看简单的system.ServiceModel结构
Code
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IStuServiceContract" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:39113/WCFServiceText/WCFStudentText.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IStuServiceContract"
contract="IStuServiceContract" name="WSHttpBinding_IStuServiceContract">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
WCF的配置使用.NET Framework的System.Configuration配置系统。在Visual Studio中配置一个WCF服务时,如果是自托管宿主或Windows Services宿主
,则配置文件为App.confing,如果是IIS宿主,则配置文件为Web.config。
先来看看简单的system.ServiceModel结构
Code
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IStuServiceContract" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:39113/WCFServiceText/WCFStudentText.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IStuServiceContract"
contract="IStuServiceContract" name="WSHttpBinding_IStuServiceContract">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
相关文章推荐
- 学习 WCF (4)--学会使用配置文件
- WPF学习笔记--使用配置文件修改控件、面板颜色
- FPGA学习笔记之Altera FPGA使用JIC文件配置固化教程(转)
- 一步步学习SPD2010--第七章节--使用BCS业务连接服务(8)--创建配置文件页面
- 使用powershell通过配置文件config调用wcf(含用户名密码认证)
- lua学习笔记(4)——lua配置文件和table使用
- 初识WCF之使用配置文件部署WCF应用程序
- 完全不使用配置文件构建和使用WCF服务
- WCF系列(一) -- 完全不使用配置文件构建和使用WCF服务
- Solr的学习使用之(二)schema.xml等配置文件的解析
- [Java学习]使用digester 解析xml配置文件
- WCF学习笔记之配置文件
- Spring学习历程---使用配置文件实现AOP
- WCF学习之三, 寄宿方式 代码,配置文件
- WCF系列(一) -- 完全不使用配置文件构建和使用WCF服务
- WCF系列(二) -- 使用配置文件构建和使用WCF服务
- WCF步步为营(三):使用配置文件改变使用服务的方式
- WCF系列(一) -- 完全不使用配置文件构建和使用WCF服务
- ZendFramework学习第三章(核心组件—使用配置数据之从XML配置文件中读取数据)
- 一步步学习SPD2010--附录C--使用SP2010管理任务(6)--配置外部内容类型配置文件页面宿主