WCF binding configuration is only applied by default, but by name it fails

We have an interesting problem with WCF binding and streaming, which we cannot solve:

We have a WCF endpoint configured for streaming mode. The endpoint receives the message much larger than the default size (~ 65KB). Therefore, we specified a larger message size in the maxReceivedMessageSize attribute in the anchor tag.

The problem is when we connect the endpoint and the binding with the bindingConfiguration attribute in the endpoint tag and the name attribute in the binding tag, we get the following error: "The remote server returned an error: (400) Bad Request."

Once we remove both the bindingConfiguration attributes and the name, it works without errors.

Here is the endpoint service definition:

<service name="Services.DocumentService" behaviorConfiguration="ServiceBehavior"> <endpoint contract="ServiceContracts.IDocumentService" address="DocumentService" binding="basicHttpBinding" name="basicHttpBinding" bindingConfiguration="BindingConfiguration" <---- when this goes away behaviorConfiguration="ServiceEndpointBehavior"/> <host> <baseAddresses> <add baseAddress="http://localhost:8080/Documents/"/> </baseAddresses> </host> </service> 

Here is the binding configuration :

  <binding name="BindingConfiguration" <---- and when this goes away transferMode="Streamed" maxReceivedMessageSize="2147483647" > <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> </binding> 

Thus, it only works as a default binding (without an explicit key). It is strange that we were able to verify by reflecting on the service host that the binding configuration was actually bound (maxReceivedMessageSize was set correctly) in both scenarios. Maybe this is a bug in WCF?

Self service

Any ideas really appreciated?

+4
source share
2 answers

We recently found out that the initialization code explicitly used the default settings and thus ignored the ones in web.config.

We removed this piece of code and set the parameter from web.config.

Stupid mistake.

Thanks everyone for the answers.

0
source

When you remove bindingConfiguration = "BindingConfiguration", it uses the default values, not the values ​​in your binding configuration.

The difference is as follows:

 transferMode="Streamed" 

By default, the transfer mode is buffered, so if the client is waiting for buffering and the server uses streaming, then you get an error with a bad request.

0
source

Source: https://habr.com/ru/post/1403935/


All Articles