Search code examples
asp.netwcfwcf-binding

Facing problems in uploading larger files using WCF


I am facing problem while uploading a file with larger size. I am using WCF service's basicHttpBinding for Request/Response where it is formed like this,

int MAXSIZE = Int32.MaxValue;

    BasicHttpBinding binding = new BasicHttpBinding()
    {
        CloseTimeout = new TimeSpan(0, 1, 0),
        OpenTimeout = new TimeSpan(0, 1, 0),
        ReceiveTimeout = new TimeSpan(0, 10, 0),
        SendTimeout = new TimeSpan(0, 10, 0),
        AllowCookies = false,
        BypassProxyOnLocal = false,
        HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
        MaxBufferSize = MAXSIZE,
        MaxBufferPoolSize = MAXSIZE,
        MaxReceivedMessageSize = MAXSIZE,
        MessageEncoding = WSMessageEncoding.Text,
        TextEncoding = System.Text.Encoding.UTF8,
        TransferMode = System.ServiceModel.TransferMode.Buffered,
        UseDefaultWebProxy = true,

    };

    binding.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
    {
        MaxDepth = 32,
        MaxStringContentLength = MAXSIZE,
        MaxArrayLength = MAXSIZE,
        MaxBytesPerRead = MAXSIZE,
        MaxNameTableCharCount =16384,
    };

As per the answers over net it should work, however it is throwing an exception. The remote server returned an unexpected response: (400) Bad Request.

Does anyone encountered such situation before ?


Solution

  • Found answer to this. The problem was with the service name in web.config file of WCF service. I was using namespace path as is. To resolve this, open svc file markup. Copy service name and use it as is in web.config file.