0

我有一个 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 的默认绑定。可以吗?

4

1 回答 1

0

The values for maxBufferSize and maxReceivedMessageSize are not propagated to the WSDL file that is published by your service. That´s why the wcf test client is unable to retrieve them and takes default values.

You can still change the values with the SvcConfigEditor every time you start the wcf test client. Therefor perform a right click on the config file in the wcf test client and look for bindings. But the changes will be lost, the next time you start the client.

You can also test your service with a self written client and set the values there like shown in the following example.

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

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

Hope this helps!

于 2013-07-10T12:52:42.257 回答