WCF binding configuration apply only as default but as named it fails

ε祈祈猫儿з 提交于 2019-12-06 04:50:35

问题


We have an interesting problem with WCF binding and streaming transfer mode that we cannot solve:

We have an WCF endpoint configured to the streaming transfer mode. The endpoint receives message much larger then the default size (~65 KB). Therefore we have specified larger message size in the maxReceivedMessageSize attribute on the binding tag.

The problem is when we pair up the endpoint and the binding by the bindingConfiguration attribute on the endpoint tag and the name attribute on the binding tag, we receive the following error: "The remote server returned an error: (400) Bad Request".

As soon as we remove both attributes bindingConfiguration and name it works without an error.

Here is the definition of the service endpoint:

    <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>

So it only works as default binding (without explicitly named key). The strange thing is that we were able to verify by reflection on the Service host that the binding configuration is actually applied (the maxReceivedMessageSize was set correctly) in both scenarios. Could it be a bug in WCF?

The service is self-hosted.

Any ideas are very appreciated?


回答1:


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

The difference is:

transferMode="Streamed"

By default the transfer mode is buffered, so if the client expects buffered and the server uses streamed, then you get a bad request error.




回答2:


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

We removed that part of code and the setting from the web.config got applied.

A stupid error.

Thanks everybody for thier answers



来源:https://stackoverflow.com/questions/9910566/wcf-binding-configuration-apply-only-as-default-but-as-named-it-fails

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