Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
698 views
in Technique[技术] by (71.8m points)

wcf binding - WCF maxReceivedMessageSize not being read from config

I have a the following server side app.config for a WCF service:

  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="default" maxReceivedMessageSize="5000000">
          <readerQuotas maxStringContentLength="5000000" maxArrayLength="5000000" />
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="Core.TOAService.Service1Behavior"
        name="Core.TOAService.TOAService">
        <endpoint address="" binding="wsHttpBinding" contract="Core.TOAService.ITOAService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/Core.TOAService/TOAService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Core.TOAService.Service1Behavior">
          <!-- To avoid disclosing metadata information, 
          set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="True"/>
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

When I try and pass this service a largish file (only ~250KB), I get an exception logged in the svclog file:

The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

As you can see from the binding section at the top of the config, I have tried to set the maxReceivedMessageSize to 5000000 but the service still thinks it is set to the default 65536. Any ideas as to what is wrong or which is the "appropriate" binding element?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There's more settings :-) Try "maxBufferPoolSize" and "maxBufferSize" on the <binding> tag.

But the biggest problem is: your endpoint does not reference that binding configuration!

<endpoint address="" 
          binding="wsHttpBinding" contract="Core.TOAService.ITOAService">

You need to add a reference to it so that it gets useful - just calling it "default" doesn't work.....

<endpoint address="" 
          binding="wsHttpBinding" 
          bindingConfiguration="default"
          contract="Core.TOAService.ITOAService">

You're ahead of your times ;-) In WCF 4 (with .NET 4.0 - sometime later this year 2009), you'll be able to define "default binding configurations" without having to explicitly name and reference them - but for now, you need to create a link between your endpoint and its binding and any binding (or behavior) configuration you have!

Marc


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...