ASP.NET上的.svc主机的WCF配置

时间:2013-07-10 12:24:07

标签: asp.net wcf web-config svc wcftestclient

我有一个WCF Web服务,由ASP.NET托管在.svc文件中。 .svc文件包含以下配置:

<%@ ServiceHost Language="C#" Debug="true" Service="assembly.IPriceListProvider,  assembly" Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf" %>

web.config包含WCF的配置。这是绑定配置:

<binding name="basicHttpBinding_PriceListProvider" maxBufferSize="10485760"
  maxReceivedMessageSize="10485760">
  <readerQuotas maxArrayLength="16384000" />
</binding>

要测试服务,我单击.svc文件并单击F5。 WCF测试客户端已打开。但配置已经改变。我明确定义的值现在具有默认值:

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

为什么配置会发生变化?我如何坚持原始价值?

我听说过简化的.svc配置:即使你没有在web.config中明确指定,也会配置.svc的默认绑定。可以吗?

1 个答案:

答案 0 :(得分:0)

maxBufferSize和maxReceivedMessageSize的值不会传播到服务发布的WSDL文件。这就是为什么wcf测试客户端无法检索它们并采用默认值。

每次启动wcf测试客户端时,仍然可以使用SvcConfigEditor更改值。因此,右键单击wcf测试客户端中的配置文件并查找绑定。但是下次启动客户端时,更改将会丢失。

您还可以使用自编写的客户端测试您的服务,并在其中设置值,如下例所示。

BasicHttpBinding binding= new BasicHttpBinding();
binding.MaxRecievedMessageSize = yourValue;
EndpointAddress endpointAddress = new EndpointAddress("the address");

ClientForContract client= new ClientForContract (binding,endpointAddress);
client.TheMethod();
client.Close(); 

希望这有帮助!