Why is my WCF Service not loading my Binding config?

北城以北 提交于 2019-12-04 20:51:54

问题


I have the problem with the following error: "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."

So I did some research and found that I needed to increase the buffer and message size, here's my WCF Service config file:

<system.serviceModel>
    <bindings>
      <wsHttpBinding>
          <binding name="default" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"/>
      </wsHttpBinding>
    </bindings>
    <services>
      <service name="WCF.Service.Service">
        <endpoint address="ws" name="ws" bindingConfiguration="default" binding="wsHttpBinding" contract="WCF.Service.Contracts.IService" />
        <endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- 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 run the service in the WCF Test Client and look at the generated client config file it doesn't have my binding:

<configuration>
<system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="ws" closeTimeout="00:01:00" openTimeout="00:01:00"
                receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
                transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <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" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:37444/Service.svc/ws" binding="wsHttpBinding"
            bindingConfiguration="ws" contract="IService" name="ws">
            <identity>
                <userPrincipalName value="username@domain" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

I'm lost to as why my binding configuration is NOT getting applied!? The WCF Test Client is set to always regenerate the config as well. I've also tried updating the service reference in a consuming front end application, but it does not get the updated binding configuration either. Any suggestions would be greatly appreciated. Thanks!


回答1:


WCF does not import all settings from your server. There's no switch to turn that on, either. While it might make sense in many cases, it wouldn't always be a good idea to just duplicate all settings from the server-side to the client.

So in your case, what you need to do is add that binding configuration to your client side proxy, too, and reference it from your client endpoint.

If you control both ends of the wire, you can ease your work a bit: externalize the binding configuration into a separate file and reference it.

So create a file bindings.config that contains:

<?xml version="1.0" ?>
<bindings>
    <wsHttpBinding>
        <binding name="default" 
                 maxBufferPoolSize="2147483647" 
                 maxReceivedMessageSize="2147483647"/>
  </wsHttpBinding>
</bindings>

and then you can copy that file both into the server and the client project, and reference it from within your service and client config:

<system.serviceModel>
    <bindings configSource="bindings.config" />
    <services>
      <service name="WCF.Service.Service">
        <endpoint address="ws" name="ws" bindingConfiguration="default" binding="wsHttpBinding" contract="WCF.Service.Contracts.IService" />
        <endpoint address="mex" binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
      </service>
    </services>

and on your client side:

<system.serviceModel>
    <bindings configSource="bindings.config" />
    <client>
        <endpoint  name="ws"
            address="http://localhost:37444/Service.svc/ws" 
            binding="wsHttpBinding"
            bindingConfiguration="default" 
            contract="IService">
            <identity>
                <userPrincipalName value="username@domain" />
            </identity>
        </endpoint>
    </client>
</system.serviceModel>

That way, you can have your configuration for the bindings done once, and used in both places.




回答2:


The maxBufferPoolSize and maxReceivedMessageSize are not exposed to the client, only the server is aware of them. the sizes the client is using are defaults, just change them to be whatever size you want. obviously this is problematic if you are regenerating it alot, but i don't think there is much alternative.



来源:https://stackoverflow.com/questions/4035846/why-is-my-wcf-service-not-loading-my-binding-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!