none
wsDualHttpBinding says 'Failed to allocate a managed memory buffer ...' RRS feed

  • Question

  • Hello,

    I am trying to upload a large object (300 MB) from client to service using 'wsDualHttpBinding'.

    Using 'basicHttpBinding', I able to upload large object (1.5 GB file).

    I need to use 'wsDualHttpBinding'. But, using 'wsDualHttpBinding', I able to upload 28 MB only.

    If I upload 100 MB object, it says ''Failed to allocate a managed memory buffer ...'

    Could you tell me, how to upload large object (300 MB) using 'wsDualHttpBinding'.

    Thanks In Advance,

    Murugan

    FYI

    My Service -Config                

      <system.web>

        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime  maxRequestLength="2147483647"
                      useFullyQualifiedRedirectUrl="true"
                      targetFramework="4.5"
                      executionTimeout="14400" />
      </system.web>
      <system.serviceModel>
        <bindings>   

          <wsDualHttpBinding>
            <binding name="Test"
                closeTimeout="04:10:00"
                openTimeout="04:10:00"
                receiveTimeout="04:10:00"
                sendTimeout="04:10:00"
                bypassProxyOnLocal="false"
                transactionFlow="false"
                hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="2147483647"
                maxReceivedMessageSize="2147483647"
                messageEncoding="Mtom"
                textEncoding="utf-16"
                useDefaultWebProxy="true">

              <readerQuotas maxDepth="2147483647"
                 maxStringContentLength="2147483647"
                 maxArrayLength="2147483647"
                 maxBytesPerRead="2147483647"
                 maxNameTableCharCount="2147483647" />

              <reliableSession
                  ordered="true"
                  inactivityTimeout="04:10:00" />
              <security mode="Message">
                <message clientCredentialType="Windows"
                         negotiateServiceCredential="true" />
              </security>
            </binding>
          </wsDualHttpBinding>
        </bindings>    
        <behaviors>
          <serviceBehaviors>
            <behavior name="FileUploaderServiceBehavior">
              <serviceMetadata httpGetEnabled="true" policyVersion="Default"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
              <dataContractSerializer maxItemsInObjectGraph="2147483647" />
              <serviceCredentials>
                <userNameAuthentication userNamePasswordValidationMode="Windows"></userNameAuthentication>
              </serviceCredentials>
              <serviceTimeouts transactionTimeout="01:00:00" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <protocolMapping>
            <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>    
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

        <services>
          <service name="HelloWcfService.FileUploaderService" behaviorConfiguration="FileUploaderServiceBehavior">

            <endpoint address=""
                      binding="wsDualHttpBinding"
                      bindingConfiguration="Test"
                      contract="HelloWcfService.IFileUploaderService">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>

            <endpoint
                address="mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange" />
          </service>

        </services>
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <!--
            To browse web app root directory during debugging, set the value below to true.
            Set to false before deployment to avoid disclosing web app folder information.
          -->
        <directoryBrowse enabled="true"/>
        <security>
          <requestFiltering>
            <requestLimits maxAllowedContentLength="2147483647" />
          </requestFiltering>
        </security>
        <validation validateIntegratedModeConfiguration="false" />    
      </system.webServer>

    Client Config

        <security>
          <requestFiltering>
            <requestLimits maxAllowedContentLength="2147483647" />
          </requestFiltering>
        </security>

    <system.serviceModel>
        <bindings>
          <wsDualHttpBinding>
            <binding name="Test" closeTimeout="04:10:00" openTimeout="04:10:00"
              receiveTimeout="04:10:00" sendTimeout="04:10:00" bypassProxyOnLocal="false"
              maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
              messageEncoding="Mtom" useDefaultWebProxy="true">
              <reliableSession inactivityTimeout="04:10:00" />
            </binding>
          </wsDualHttpBinding>
        </bindings>

        <client>
          <endpoint address="http://localhost/hellowcf/FileUploaderService.svc"
            binding="wsDualHttpBinding" bindingConfiguration="Test" contract="FileUploaderSvc.IFileUploaderService"
            name="WSDualHttpBinding_IFileUploaderService">
            <identity>
              <dns value="localhost" />
            </identity>
          </endpoint>
        </client>
      </system.serviceModel>

        [ServiceContract(CallbackContract = typeof(IFileUploaderServiceCallBack))]
        public interface IFileUploaderService
        {
            [OperationContract]
            void Upload(MyFileInfo remoteFileInfo);
        }

        public interface IFileUploaderServiceCallBack
        {
            [OperationContract(IsOneWay = true)]
            void OnNotificationSend(string message);
        }

        [MessageContract]
        public class MyFileInfo : IDisposable
        {
            [MessageBodyMember(Order = 1)]
            public System.IO.Stream FileByteStream;

            public void Dispose()
            {
                if (FileByteStream != null)
                {
                    FileByteStream.Close();
                    FileByteStream = null;
                }
            }
        }

    namespace HelloWcfService
    {
        [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant, InstanceContextMode = InstanceContextMode.Single)] 
        public class FileUploaderService : IFileUploaderService
        {
            public void Upload(MyFileInfo remoteFileInfo)
            {   
            }

            public IFileUploaderServiceCallBack Proxy
            {
                get
                {
                    return OperationContext.Current.GetCallbackChannel<IFileUploaderServiceCallBack>();
                }
            }
        }
    }

    --------------

                string file = @"D:\huge_dummy_file221";
                long sizeInMB = 300;

                //while (true)
                {
                    using (FileStream fs = new FileStream(file, FileMode.Create))
                    {
                        fs.Seek(sizeInMB * 1024 * 1024, SeekOrigin.Begin);
                        fs.WriteByte(0);
                        fs.Flush();
                        fs.Close();
                    }

                    using (FileStream fs = new FileStream(file, FileMode.Open))
                    {
                        var ctx = new InstanceContext(new NotificationServiceCallBack());
                        FileUploaderSvc.FileUploaderServiceClient client = new FileUploaderSvc.FileUploaderServiceClient(ctx, "WSDualHttpBinding_IFileUploaderService");

                        client.Open();
                        client.Upload(fs);
                        client.Close();
                        client = null;

                        fs.Close();
                    }
                }



    Murugan

    Thursday, August 13, 2015 12:41 PM

Answers

  • Hi Murugan,

    According to your description, and I try to do it. But I find if we want to

    upload large file with Wsdualhttpbinding, this is a false choice. Because

    the Wsdualhttpbinding  not support transfermode with streamed and  

    buffer. That  means we can't sent or receive large file with Wsdualhttpbinding.

    So, I suggest you can use nettcphttpbing which always support transfermode 

    and duplex.

    For more information, please refer to the following articles:

    1.Large data transfer using wsDualHttpbinding fails

    2.Large Data and Streaming

    3.Duplex Service in WCF

    I hope that will be helpful to you.

    Best Regards,

    Tracy Grady


    Friday, August 14, 2015 7:57 AM
    Moderator

All replies