0

i make WCF service on server side to return binary (bytes) of file.. i just can return binary of txt file,otherwise it's say "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."

<bindings>
      <basicHttpBinding>
        <binding name="basicHttp" allowCookies="true"
                 maxReceivedMessageSize="2147483647" 
                 maxBufferSize="2147483647"
                 maxBufferPoolSize="2147483647"
          transferMode="Buffered"
          messageEncoding="Text"
          textEncoding="utf-8"
          bypassProxyOnLocal="false"
               useDefaultWebProxy="true" >
        <security mode="None" />
            <readerQuotas maxDepth="2147483647" 
                 maxArrayLength="2147483647"
                 maxStringContentLength="2147483647"
        maxBytesPerRead="2147483647"
        maxNameTableCharCount="2147483647"/>
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

can you give me solution?

i need your help..thanks before :)

here is client code side (app.config)

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IService" />
    </basicHttpBinding>
  </bindings>
  <client>
    <endpoint address="http://localhost:3724/Service.svc" 
              binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_IService"
              contract="ServiceReference1.IService"
              name="BasicHttpBinding_IService" />
  </client>

this client is desktop application not website

Tim
  • 28,212
  • 8
  • 63
  • 76
  • refer to : http://stackoverflow.com/questions/1004717/what-is-the-maximum-size-that-maxreceivedmessagesize-can-be-set-to-for-a-netname – Adam Aug 12 '14 at 19:44
  • See if this helps: [Error: the maximum message size quota for incoming messages (65536) has been exceeded](http://stackoverflow.com/a/24897891/745969) – Tim Aug 12 '14 at 19:48
  • @Tim where i put tag endpoint? :) – Peter Yohanes Aug 12 '14 at 20:11
  • @PeterYohanes It should be another section in your config file. That's where you specify the service ABC - Address, Binding, Contract - for your service. – GalacticCowboy Aug 12 '14 at 20:14
  • @GalacticCowboy i make endpoint tag after bindings tag..but it error..i'm sorry,i never use it before.so i'm confused to apply that.. – Peter Yohanes Aug 12 '14 at 20:37
  • @PeterYohanes - See my answer below. – Tim Aug 12 '14 at 21:08

1 Answers1

0

You need to assign the binding you defined to an endpoint you create. Here's an example:

<bindings>
  <basicHttpBinding>
    <binding name="basicHttp" allowCookies="true"
             maxReceivedMessageSize="2147483647" 
             maxBufferSize="2147483647"
             maxBufferPoolSize="2147483647"
             transferMode="Buffered"
             messageEncoding="Text"
             textEncoding="utf-8"
             bypassProxyOnLocal="false"
             useDefaultWebProxy="true" >
      <security mode="None" />
      <readerQuotas maxDepth="2147483647" 
                    maxArrayLength="2147483647"
                    maxStringContentLength="2147483647"
                    maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647"/>
    </binding>
  </basicHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services> 
  <service> 
    <endpoint address="/Service.svc" binding="basicHttpBinding" 
              bindingCongifuration="basicHttp" 
              contract="service.IService"/> 
  </service> 
</services>

A couple of things to note - in your comment, your service endpoint was using wsHttpBinding, but you defined basicHttpBinding in your <bindings> section. Also, the bindingConfiguration attribute must be the name assigned to the binding defined. My example above is based on the original posted config file.

Alternatively, if you are using .NET 4.0 or later, you can define a binding in the <bindings> setting and set it as the default definition for that binding by omitting the name attribute on the <binding> element.

By default, .NET 4.0+ uses basicHttpBinding for http. You can change this in the config file in the <protocolMapping> section (which is contained in the <system.serviceModel> section). For example, if you wanted to use wsHttpBinding for all http requests, you would do this:

<protocolMapping>
  <add binding="wsHttpBinding" scheme="http" />
</protocolMapping>

Added Client Example

The client side would look very similar, except you'd have a <clients> section instead of a <services> section. Note that some of the settings on the binding apply to the machine (client or server) the application is on, and setting them on one side of the client-server relationship will have no effect on the other side (like maxReceivedMessageSize, for example). Generally the binding type and security have to agree, and in practice it's usually easier to just use the same bindings on both ends, but it is possible to have a scenario where one side would have different buffers or other items.

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IService" allowCookies="true"
             maxReceivedMessageSize="2147483647" 
             maxBufferSize="2147483647"
             maxBufferPoolSize="2147483647"
             transferMode="Buffered"
             messageEncoding="Text"
             textEncoding="utf-8"
             bypassProxyOnLocal="false"
             useDefaultWebProxy="true" >
      <security mode="None" />
      <readerQuotas maxDepth="2147483647" 
                    maxArrayLength="2147483647"
                    maxStringContentLength="2147483647"
                    maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647"/>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="localhost:3724/Service.svc" 
            binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_IService" 
            contract="ServiceReference1.IService" 
            name="BasicHttpBinding_IService" /> 
</client>
Tim
  • 28,212
  • 8
  • 63
  • 76
  • i use .NET 4.0+ and i write my code as your example.. i don't know why,but it not working.. thanks and sorry troubling you Tim :) – Peter Yohanes Aug 12 '14 at 21:40
  • @PeterYohanes - I just reread your question. Is the error appearing on the client (i.e., when you get the data from the server)? If so, you need to make the changes in the client's config, not the server. If this is the case, please post the `` section of your client config in your original question? I'll take a look. – Tim Aug 12 '14 at 22:11
  • sorry to late reply not only error on client,but if d invoke that WCF on server it's error too..can you give me any idea? – Peter Yohanes Aug 13 '14 at 03:37
  • 1
    @PeterYohanes - The binding you define in the client doesn't have any values set, so you're getting the default values. You need to have the binding values match what's on your server, and then use that binding configuration in your client as well. Very similar to my example above, but the endpoint would be in the `` section. – Tim Aug 13 '14 at 04:57
  • in my client side,i have set and then i copy paste all of binding on server to client side? – Peter Yohanes Aug 13 '14 at 05:34
  • yes,thanks Tim.. but it arise new error,it's say "The remote server returned an unexpected response: (413) Request Entity Too Large." why it can show that? :) – Peter Yohanes Aug 13 '14 at 06:44