none
WCF - large file transfer RRS feed

  • Question

  • I wrote an app that allowes users to upload files from the browser and send the contents as byte[] to a windows (not IIS) hosted WCF service. This works fine for small files, but larger files thrown the following exception:

    The maximum message size quota for incoming messages has been exceeded for the remote channel. See the server logs for more details.

    The following is the config settings for the service:

    <service behaviorConfiguration="TcpBehavior" name="ADPTS.Services.Services.Attachments.AttachmentService">
            <endpoint address="mex" binding="mexTcpBinding" name="mexTcpApplicationCodeEp"
              contract="IMetadataExchange" />
            <endpoint address="" binding="netTcpBinding" bindingConfiguration=""
              name="TcpAttachmentEp" contract="ADPTS.Services.Interfaces.Attachments.IAttachment">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <host>
              <baseAddresses>
                <add baseAddress="net.tcp://localhost:8029/ADPTS.Services/Attachments/AttachmentService" />
              </baseAddresses>
            </host>
          </service>
        <bindings>
          <netTcpBinding>
            <binding name="TcpAttachmentEp" closeTimeout="00:15:00" openTimeout="00:15:00"
               receiveTimeout="00:15:00" sendTimeout="00:15:00" transactionFlow="false"
               transferMode="Buffered" transactionProtocol="OleTransactions"
               hostNameComparisonMode="StrongWildcard" listenBacklog="10"
               maxBufferPoolSize="65536000" maxBufferSize="2147483647" maxConnections="10"
               maxReceivedMessageSize="2147483647">
              <readerQuotas maxDepth="32" maxStringContentLength="65536000"
                 maxArrayLength="65536000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
              <reliableSession ordered="true" inactivityTimeout="00:10:00"
                 enabled="false" />
              <security mode="Transport">
                <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                <message clientCredentialType="Windows" />
              </security>
            </binding>
          </netTcpBinding>
        </bindings>

    And this is the client config file:

          <endpoint address="net.tcp://localhost:8029/ADPTS.Services/Attachments/AttachmentService"
            binding="netTcpBinding" bindingConfiguration="TcpAttachmentEp"
            contract="AttachmentService.IAttachment" name="TcpAttachmentEp">
            <identity>
              <dns value="localhost" />
            </identity>
          </endpoint>
    
               <binding name="TcpAttachmentEp" closeTimeout="00:15:00" openTimeout="00:15:00"
                  receiveTimeout="00:15:00" sendTimeout="00:15:00" transactionFlow="false"
                  transferMode="Buffered" transactionProtocol="OleTransactions"
                  hostNameComparisonMode="StrongWildcard" listenBacklog="10"
                  maxBufferPoolSize="65536000" maxBufferSize="2147483647" maxConnections="10"
                  maxReceivedMessageSize="2147483647">
                  <readerQuotas maxDepth="32" maxStringContentLength="65536000"
                     maxArrayLength="65536000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                  <reliableSession ordered="true" inactivityTimeout="00:10:00"
                     enabled="false" />
                  <security mode="Transport">
                     <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                     <message clientCredentialType="Windows" />
                  </security>
               </binding>
    

    As you can see, I increased the maxBufferSize and maxReceivedMessageSize in both environments, but the file I'm trying to upload is definately not that large (less than 1MB).

    Are there other settings I need to look for?

    Thanks

    Alex

         
    Monday, October 7, 2013 1:11 PM

Answers

  • When I remove the name from bindingConfiguration="myTcpAttachmentEp" (changed to bindingConfiguration="" ), it works fine. As a matter of fact, it always worked except for the large file issue.  

    Hi,

    By default the data can be transfer is 64kb, so if you remove the name from bindingConfiguration="myTcpAttachmentEp" changed to bindingConfiguration="" , then the data bigger than 64kb can not be transfered.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 15, 2013 5:48 AM
    Moderator
  • <copied>

    As you can see, I increased the maxBufferSize and maxReceivedMessageSize in both environments, but the file I'm trying to upload is definately not that large (less than 1MB).

    <end>

    On the client-side config, what you did is correct to increase settings. But on the service-side config, if all you did was start typing things for bindings thinking that you are giving new settings, then everything is being ignored on the service-side config for bindings.

    You have to make a CustomBinding on  the service-side and point the service to the CustomBinding to override the default settings on the service-side, like readerQuotas, maxReceivedMessageSize, etc etc.

    http://blogs.msdn.com/b/kaevans/archive/2008/01/24/wcf-and-custom-bindings.aspx

    Monday, October 7, 2013 9:12 PM
  • BTW ... just wondering whether you have checked your client configuration file.

    Sometimes Client configuration file set to default values when generating proxy, hence stops you transferring large data.

    Set it to larger value as in your service configuration.


    Tanvir Huda Application Architect/Consultant http://thetechnocrate.wordpress.com/

    Tuesday, October 15, 2013 6:59 AM

All replies

  • Can you post the error message?  It seems like the error is coming from the underlying transport and not from WCF.

    If my response was helpful, please vote it as helpful. If I have answered the question being asked, please mark my post as the answer.

    Monday, October 7, 2013 6:55 PM
  • <copied>

    As you can see, I increased the maxBufferSize and maxReceivedMessageSize in both environments, but the file I'm trying to upload is definately not that large (less than 1MB).

    <end>

    On the client-side config, what you did is correct to increase settings. But on the service-side config, if all you did was start typing things for bindings thinking that you are giving new settings, then everything is being ignored on the service-side config for bindings.

    You have to make a CustomBinding on  the service-side and point the service to the CustomBinding to override the default settings on the service-side, like readerQuotas, maxReceivedMessageSize, etc etc.

    http://blogs.msdn.com/b/kaevans/archive/2008/01/24/wcf-and-custom-bindings.aspx

    Monday, October 7, 2013 9:12 PM
  • Hi,

    It seems that you have configured the configure file in both the server and client side to transfer the large data, but it still meet error. So please try to enable the wcf tracing to find the cause.

    The following configuration taken from MSDN can be applied to enable tracing on your wcf service.

    <configuration>
      <system.diagnostics>
        <sources>
          <source name="System.ServiceModel"
                  switchValue="Information, ActivityTracing"
                  propagateActivity="true" >
            <listeners>
                 <add name="xml"/>
            </listeners>
          </source>
          <source name="System.ServiceModel.MessageLogging">
            <listeners>
                <add name="xml"/>
            </listeners>
          </source>
          <source name="myUserTraceSource"
                  switchValue="Information, ActivityTracing">
            <listeners>
                <add name="xml"/>
            </listeners>
          </source>
        </sources>
        <sharedListeners>
            <add name="xml"
                 type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="Error.svclog" />
        </sharedListeners>
      </system.diagnostics>
    </configuration>
    Best Regards,
    Amy Peng

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 8, 2013 4:40 AM
    Moderator
  • Here is the error:

    <InnerException>
    <ExceptionType>System.ServiceModel.QuotaExceededException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
    <Message>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.</Message>
    <StackTrace>
    at System.ServiceModel.Channels.ServerSessionPreambleConnectionReader.ServerFramingDuplexSessionChannel.ServerSessionConnectionReader.DecodeMessage(Byte[] buffer, Int32&amp; offset, Int32&amp; size, Boolean&amp; isAtEof, TimeSpan timeout)
    at System.ServiceModel.Channels.SessionConnectionReader.DecodeMessage(TimeSpan timeout)
    at System.ServiceModel.Channels.SessionConnectionReader.OnAsyncReadComplete(Object state)
    at System.ServiceModel.Channels.StreamConnection.OnRead(IAsyncResult result)
    at System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
    at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
    at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
    at System.Net.Security.NegotiateStream.ProcessFrameBody(Int32 readBytes, Byte[] buffer, Int32 offset, Int32 count, AsyncProtocolRequest asyncRequest)
    at System.Net.Security.NegotiateStream.ReadCallback(AsyncProtocolRequest asyncRequest)
    at System.Net.AsyncProtocolRequest.CompleteRequest(Int32 result)
    at System.Net.FixedSizeReader.CheckCompletionBeforeNextRead(Int32 bytes)
    at System.Net.FixedSizeReader.ReadCallback(IAsyncResult transportResult)
    at System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
    at System.ServiceModel.Channels.ConnectionStream.IOAsyncResult.OnAsyncIOComplete(Object state)
    at System.ServiceModel.Channels.TracingConnection.TracingConnectionState.ExecuteCallback()
    at System.ServiceModel.Channels.TracingConnection.WaitCallback(Object state)
    at System.ServiceModel.Channels.SocketConnection.FinishRead()
    
    at System.ServiceModel.Channels.SocketConnection.OnReceiveAsync(Object sender, SocketAsyncEventArgs eventArgs)
    at System.ServiceModel.Channels.SocketConnection.OnReceiveAsyncCompleted(Object sender, SocketAsyncEventArgs e)
    at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs e)
    at System.Net.Sockets.SocketAsyncEventArgs.FinishOperationSuccess(SocketError socketError, Int32 bytesTransferred, SocketFlags flags)
    at System.Net.Sockets.SocketAsyncEventArgs.CompletionPortCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
    at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)
    </StackTrace>
    <ExceptionString>System.ServiceModel.QuotaExceededException: 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.</ExceptionString>
    </InnerException>
    
    So I think dartnold may be correct, so I'll take a look at the serive custombinding next. 
    Tuesday, October 8, 2013 3:30 PM
  • So I now understand that I need to set bindingConfiguration  and update the binding name:

          <service behaviorConfiguration="TcpBehavior" name="ADPTS.Services.Services.Attachments.AttachmentService">
            <endpoint address="mex" binding="mexTcpBinding" name="mexTcpApplicationCodeEp"
              contract="IMetadataExchange" />
            <endpoint address="" binding="netTcpBinding" bindingConfiguration="myTcpAttachmentEp"
              name="TcpAttachmentEp" contract="ADPTS.Services.Interfaces.Attachments.IAttachment">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <host>
              <baseAddresses>
                <add baseAddress="net.tcp://localhost:8029/ADPTS.Services/Attachments/AttachmentService" />
              </baseAddresses>
            </host>
          </service>
    
        </services>
    
        <bindings>
          <netTcpBinding>
            <binding name="myTcpAttachmentEp" closeTimeout="00:15:00" openTimeout="00:15:00"
               receiveTimeout="00:15:00" sendTimeout="00:15:00" transactionFlow="false"
               transferMode="Buffered" transactionProtocol="OleTransactions"
               hostNameComparisonMode="StrongWildcard" listenBacklog="10"
               maxBufferPoolSize="65536000" maxBufferSize="2147483647" maxConnections="10"
               maxReceivedMessageSize="2147483647">
              <readerQuotas maxDepth="32" maxStringContentLength="65536000"
                 maxArrayLength="65536000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
              <reliableSession ordered="true" inactivityTimeout="00:10:00"
                 enabled="false" />
              <security mode="Transport">
                <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
                <message clientCredentialType="Windows" />
              </security>
            </binding>
          </netTcpBinding>
        </bindings>
    

    But I now get the following exception:

    There is already a listener on IP endpoint 0.0.0.0:8029. This could happen if there is another application already listening on this endpoint or if you have multiple service endpoints in your service host with the same IP endpoint but with incompatible binding configurations.

    I've been looking around and it seems that this is a 4.5 issue, but I'm on 4.0.

    Can you provide some example on how I should update my service configuration?

    Thank you

    Tuesday, October 8, 2013 7:35 PM
  • The exception was added above - thanks.
    Tuesday, October 8, 2013 7:35 PM
  • Hi

    Please see this blog post related to large data transfer

    But the exception your getting is related to TCP/IP port sharing. There must be other application running on this port or port is not opened for listenting.

    • Enable TCP/IP port sharing service.
    • Enable the port in your firewall to receive inbound and outbound request.

    Tanvir Huda Application Architect/Consultant http://thetechnocrate.wordpress.com/

    Tuesday, October 8, 2013 10:58 PM
  • When I remove the name from bindingConfiguration="myTcpAttachmentEp" (changed to bindingConfiguration="" ), it works fine. As a matter of fact, it always worked except for the large file issue.  

    Wednesday, October 9, 2013 12:55 PM
  • How can it be working fine if it's blowing up on large data amounts travelling over the wire.
    Wednesday, October 9, 2013 2:00 PM
  • When I remove the name from bindingConfiguration="myTcpAttachmentEp" (changed to bindingConfiguration="" ), it works fine. As a matter of fact, it always worked except for the large file issue.  

    Hi,

    By default the data can be transfer is 64kb, so if you remove the name from bindingConfiguration="myTcpAttachmentEp" changed to bindingConfiguration="" , then the data bigger than 64kb can not be transfered.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 15, 2013 5:48 AM
    Moderator
  • BTW ... just wondering whether you have checked your client configuration file.

    Sometimes Client configuration file set to default values when generating proxy, hence stops you transferring large data.

    Set it to larger value as in your service configuration.


    Tanvir Huda Application Architect/Consultant http://thetechnocrate.wordpress.com/

    Tuesday, October 15, 2013 6:59 AM