面对使用WCF上传大文件的问题

时间:2012-09-05 07:25:04

标签: asp.net wcf wcf-binding

我在上传较大尺寸的文件时遇到问题。我正在使用WCF服务的basicHttpBinding进行请求/响应,其形成如下,

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,
    };

根据网上的答案,它应该有效,但它会抛出异常。 远程服务器返回了意外响应:(400)错误请求。

有没有人遇到过这样的情况?

1 个答案:

答案 0 :(得分:0)

找到答案。问题在于WCF服务的web.config文件中的服务名称。 我按原样使用命名空间路径。要解决此问题,请打开svc文件标记。复制服务名称并在web.config文件中使用它。

相关问题