Click here to Skip to main content
15,887,434 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello everyone,

I'm facing a configuration issue concerning my WCF Streaming service. I've got a Windows service that self-hosts 3 WCF Services, one of which handles the uploading and downloading of binary content using Streams. The documentation around states that you have to set maxReceivedMessageSize to a suitably high number (eg. 2147483647) to be able to receive larger messages, which is what we did.

Service Config:

HTML
<service name="DocumentService" behaviorConfiguration="DatashopServiceBehavior">
        <endpoint contract="IDocumentService" address="DocumentService"
                  binding="basicHttpBinding" name="basicHttpBinding" bindingConfiguration=""
                  behaviorConfiguration="DatashopServiceEndpointBehavior"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/Datashop/Documents/"/>
          </baseAddresses>
        </host>
      </service>


Binding Config:

HTML
<basicHttpBinding>
<binding name="" transferMode="Streamed" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
                        maxArrayLength="2147483647" maxBytesPerRead="2147483647"
                        maxNameTableCharCount="2147483647" />
        </binding>
</basicHttpBinding>


You'll notice that there is an empty string value for the bindingConfiguration attribute of the endpoint, and an empty string for the name attribute of the binding itself. That's because this is the only way we got it to work. If we explicitly name the binding and reference it from the endpoint using that name, it's as if the maxReceivedMessageSize property is never set and large binary contents give us the following error in the WCF Service Trace Viewer:

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.

My colleague has isolated the streaming service and inspected the configuration at run time using reflection and has found that the maxReceivedMessageSize is set correctly, but somehow doesn't get applied.

While we can fix our current problem by naming and referencing the binding configuration using the emtpy string, it doesn't solve the underlying issue and means if we want to set up a different endpoint on the same service but with a different binding, we can't.

Further info: the EndpointBehavior is WCFExtras to flatten the WSDL and we're not using a service client, instead we're using ChannelFactory<T>

Has anyone experienced this issue before, and what was the solution to it?

Any help will be greatly appreciated.
Posted
Updated 4-May-23 6:56am
v3

The problem lies with the fact that we're self-hosting the services with the hostservice calling:

host.AddDefaultEndpoints();

We were stupidly calling the service with the baseAddress:

http://localhost:8080/Datashop/Documents/

instead of:

http://localhost:8080/Datashop/Documents/DocumentService/

What I still don't understand is why the damn thing worked when the server side had empty strings for the bindingConfiguration name, but at this stage I don't care. I care far more about the vast amounts of beer I'm going to pour down my neck to try and forget the last two days chasing a configuration issue thinking it's a bug in WCF ;)
 
Share this answer
 
HTML
<bindings>
      <basichttpbinding>
        <binding name="FlightInventory_basicHttpBinding" closetimeout="00:20:00" opentimeout="00:20:00">
          receiveTimeout="00:20:00" sendTimeout="00:20:00" allowCookies="false"
          bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
          textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"
          messageEncoding="Text">
          <readerquotas maxdepth="2147483647" maxstringcontentlength="2147483647">
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientcredentialtype="None" proxycredentialtype="None">
              realm="" />
            <message clientcredentialtype="UserName" algorithmsuite="Default" />
          </transport></security>
        </readerquotas></binding>
      </basichttpbinding>
    </bindings>
    <services>
      <service name="FlightInventoryService.FlightInventory" behaviorconfiguration="FlightInventoryService.ServiceBehaviour">
        <endpoint address="" binding="basicHttpBinding" bindingconfiguration="FlightInventory_basicHttpBinding" contract="FlightInventoryService.IFlightInventory">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <servicebehaviors>
        <behavior name="FlightInventoryService.ServiceBehaviour">
          <!-- 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" />
          <datacontractserializer maxitemsinobjectgraph="2147483647" />
        </behavior>
      </servicebehaviors>
    </behaviors>
    <protocolmapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolmapping>
    <servicehostingenvironment aspnetcompatibilityenabled="true" multiplesitebindingsenabled="true" />
 
Share this answer
 
v3
Comments
Nelek 5-Nov-13 6:36am    
If you post HTML please don't forget to use the code tags, if not used the text is totally messed up.

On the other hand... did you realize that you answered to an already solved question from March 2012? If you still want to do it, then please add a tiny explanation. Just a bunch of code brings not much information.
I found a simple solution to this problem

If one configures the variable "maxReceivedMessageSize" in the app.config, it didn't work for me

What I did was do it in the code, as follows:

ServiceX.Service1Client ServMyService = new ServiceX.Service1Client();
ServMyService.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://ipaddress/Service1.svc");
BasicHttpBinding binding1 = new BasicHttpBinding("BasicHttpBinding_IService1");
binding1.MaxReceivedMessageSize = 2147483647;
ServMyService.Endpoint.Binding = binding1;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900