Why doesn't WCF Service Reference keep some settings after metadata exchange?

696 Views Asked by At

I'm defining a binding like this in my WCF Service's app.config file:

<bindings>
  <netTcpBinding>
    <binding name="Binding1"
             closeTimeout="00:01:00"
             openTimeout="00:01:00"
             receiveTimeout="00:10:00"
             sendTimeout="00:01:00"
             transactionFlow="false"
             transferMode="Buffered"
             transactionProtocol="OleTransactions"
             hostNameComparisonMode="StrongWildcard"
             listenBacklog="10"
             maxBufferPoolSize="524288"
             maxBufferSize="524288"
             maxConnections="10"
             maxReceivedMessageSize="524288">
      <readerQuotas maxDepth="32"
                    maxStringContentLength="8192"
                    maxArrayLength="16384"
                    maxBytesPerRead="4096"
                    maxNameTableCharCount="16384" />
      <reliableSession ordered="true"
                       inactivityTimeout="00:10:00"
                       enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
        <message clientCredentialType="Windows" algorithmSuite="Default" />
      </security>
    </binding>
  </netTcpBinding>
</bindings>

Note that I have set maxBufferSize and maxReceivedMessageSize to be 524288 bytes. In my client project, when I click "Add Service Reference" I am able to discover and add my service. But it fills out my client's app.config file like this

<bindings>
  <netTcpBinding>
    <binding name="NetTcpBinding_AgileService" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
      hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
      maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
        enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
        <message clientCredentialType="Windows" algorithmSuite="Default" />
      </security>
    </binding>
  </netTcpBinding>
</bindings>

I'm curious why maxBufferSize and maxReceivedMessageSize have reverted back to their defaults in my client's app.config. Do these settings apply separately to the client and server? In other words, can the client and server each have their own message size limits?

Is there anything else that I need to do on the client to make sure that the client will be willing to send messages of 524288 bytes? (I only care about client -> server communication)

2

There are 2 best solutions below

1
On BEST ANSWER

Yes, the settings are specific to the client or the server (depending on which config you're dealing with). MaxReceivedMessageSize applies only to the size of the message being received by the service or the client, not the size of the message being sent.

You may neeed to increase MaxStringContentLength in the ReaderQuotas as well to handle a larger message. Also, you'll need to make sure you reference your Binding1 configuration in your endpoint on your service (via the bindingConfiguration attribute) in your service's config file, otherwise your service will revert to the default settings for NetTcpBinding.

Example:

<services>
  <service behaviorConfiguration="MyBehavior" name="MyService">
    <endpoint address="" binding="netTcpBinding"
              bindingConfiguration="Binding1"
              contract="MyService.IMyContract" />
  </service>
</services>
0
On

Notice the name of MaxReceivedMessageSize. Its about the size of the data the receiver of the data is prepared to accept. It is, therefore, likely that the client and service will want different values - so these are not part of the generated values from the metadata