WCF配置文件

由于要上传较大的图片,WCF传递数组的默认的最大数组16KB就不够了。如下讲解配置内容。数组

服务端配置

这里一个WCF项目中有1个服务,配置文件以下(位于system.serviceModel标签中):ide

<behaviors>
  <serviceBehaviors>
    <behavior name="MyBehavior">
      <!– 为避免泄漏元数据信息,请在部署前将如下值设置为 false 并删除上面的元数据终结点 –>
      <serviceMetadata httpGetEnabled="true" />
      <!– 要接收故障异常详细信息以进行调试,请将如下值设置为 true。在部署前设置为 false 以免泄漏异常信息 –>
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<services>
  <!– The name of the service –>
  <service name="OnlineShopService.Service.ProductService" behaviorConfiguration="MyBehavior">
    <endpoint binding="basicHttpBinding" bindingConfiguration="higherMessageSize" contract ="OnlineShopService.Service.IProductService">
    </endpoint>
  </service>
</services>

<bindings>
  <basicHttpBinding>
    <binding name="higherMessageSize" maxReceivedMessageSize ="6553600″>"
      <readerQuotas maxDepth="32″" maxStringContentLength="8192″" maxArrayLength="1638400″" maxBytesPerRead="4096″" maxNameTableCharCount="16384″ />"
    </binding>
  </basicHttpBinding>
</bindings>
View Code

原本用默认配置的话这些都不用写了,但由于ProductService这个服务要扩大一下数据流大小限制,发现其它两个服务也不能不写了,只得把它们也配置出来。ui

service标签中的name是服务类的彻底限定名称,包括命名空间、类名。behaviorConfiguration也要配。service中的endpoint若使用默认配置,就不须要配bindingConfiguration属性了。注意,这里bindingConfiguration的配置是对应下面bindings标签的内容的。contract是服务类继承的接口。spa

bindings标签中的内容凭借名字能够明白意思,就不须要赘述了。详见使用配置文件配置服务调试

客户端配置

客户端的配置再添加对服务的引用后便会自动生成默认的。这里将ProductService这个服务修改以下:code

<binding name="BasicHttpBinding_IProductService" closeTimeout="00:01:00″" openTimeout="00:01:00″" receiveTimeout="00:10:00″" sendTimeout="00:01:00″" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="6553600" maxBufferPoolSize="524288″" maxReceivedMessageSize="6553600" messageEncoding="Text" textEncoding="utf-8″" transferMode="Buffered" useDefaultWebProxy="true">
  <readerQuotas maxDepth="32″" maxStringContentLength="8192″" maxArrayLength="1638400" maxBytesPerRead="4096″" maxNameTableCharCount="16384″ />"
  <security mode="None">
    <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
    <message clientCredentialType="UserName" algorithmSuite="Default" />
  </security>
</binding>
View Code

下划线是修改的地方,只是加了两个0.blog

相关文章
相关标签/搜索