WCF配置文件

时间:2023-03-10 07:33:12
WCF配置文件

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

服务端配置

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

<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>

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

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

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

客户端配置

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

<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>

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