locked
Consume WCF contract with big byte[] arguments RRS feed

  • Question

  • Hi everyone. 

    I have a WCF service exposing methods that need to return binary data. Typical size of my binary data is 4-7 Mb.

    I can consume the service from desktop applications after tweaking quotas on client. When trying to consume it from a Windows Store app, the remote calls just hang (no exceptions, but they never return). 

    I have to control who and when can download the binary data for security reasons.

    WCF, Windows Store, 4-7 MB arguments.

    What are possible/recommended scenarios in this case? 

    Sunday, October 13, 2013 8:17 AM

Answers

  • Hi Dmitry,

    In default, the WCF data size could only be 64KB, but you could use following code to enlarge the MaxReceivedMessageSize:

    Uri baseAddress = new Uri("http://localhost:8080/Test");
    var serviceHost = new ServiceHost(typeof(TestService));
    var basicHttpBinding = new BasicHttpBinding();
    basicHttpBinding.MaxReceivedMessageSize = int.MaxValue;
    serviceHost.AddServiceEndpoint(typeof(IService), basicHttpBinding, baseAddress);

    Best Regards,

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Dmitry Kim Monday, October 14, 2013 7:13 AM
    Monday, October 14, 2013 3:08 AM
    Moderator

All replies

  • Hi Dmitry,

    In default, the WCF data size could only be 64KB, but you could use following code to enlarge the MaxReceivedMessageSize:

    Uri baseAddress = new Uri("http://localhost:8080/Test");
    var serviceHost = new ServiceHost(typeof(TestService));
    var basicHttpBinding = new BasicHttpBinding();
    basicHttpBinding.MaxReceivedMessageSize = int.MaxValue;
    serviceHost.AddServiceEndpoint(typeof(IService), basicHttpBinding, baseAddress);

    Best Regards,

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Dmitry Kim Monday, October 14, 2013 7:13 AM
    Monday, October 14, 2013 3:08 AM
    Moderator
  • Jamles,

    Thanks for the answer. The server side is configured to be able to send sufficiently large arguments. I test this with a desktop client, and set the client's maxReceivedMessageSize in config file. 

    WCF proxy generated for the Windows Store client has the following method:

     private static System.ServiceModel.Channels.Binding GetBindngForEndpoint(EndpointConfiguration endpointConfiguration) {
                if ((endpointConfiguration == EndpointConfiguration.NetHttpBinding_IDataService)) {
                    System.ServiceModel.Channels.CustomBinding result = new System.ServiceModel.Channels.CustomBinding();
                    result.Elements.Add(new System.ServiceModel.Channels.BinaryMessageEncodingBindingElement());
                    System.ServiceModel.Channels.HttpTransportBindingElement httpBindingElement = new System.ServiceModel.Channels.HttpTransportBindingElement();
                    httpBindingElement.AllowCookies = true;
                    httpBindingElement.MaxBufferSize = int.MaxValue;
                    httpBindingElement.MaxReceivedMessageSize = int.MaxValue;
                    result.Elements.Add(httpBindingElement);
                    return result;
                }
                throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
            }

    that already sets max received message size to max int. 

    Solution

    There were no hangs in my case, but calls took so long that I thought they hanged. 


    • Edited by Dmitry Kim Monday, October 14, 2013 7:12 AM
    Monday, October 14, 2013 7:12 AM