您的位置:首页 > 其它

学习 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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: