0

我的客户端应用程序使用托管在本地 IIS 中的 WCF Web 服务。此 Web 服务用于上传图像。一旦图像尺寸变大,它就会发出错误的请求(400)。

客户端配置为动态获取 Web 服务 URL。

客户代码

string serviceUrl=GetUrl();  /* http://localhost:85/ImageUploaderService.svc */

TimeSpan timeOut = new TimeSpan(0, 30, 0);

EndpointAddress endPoint = new EndpointAddress(serviceUrl);     


BasicHttpBinding binding = new BasicHttpBinding()
{
    CloseTimeout = timeOut,
    MaxReceivedMessageSize = 65536,
    OpenTimeout = timeOut,
    ReceiveTimeout = timeOut,
    SendTimeout = timeOut,
    MaxBufferSize = 65536,
    MaxBufferPoolSize = 524288,
    UseDefaultWebProxy = true,
};

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

client = new ImageUploaderServiceClient(binding, endPoint);  

Web服务端

<basicHttpBinding>
    <binding maxBufferSize="64000000" maxReceivedMessageSize="64000000" maxBufferPoolSize="64000000">
      <readerQuotas maxDepth="64000000" maxStringContentLength="64000000" maxArrayLength="64000000" maxBytesPerRead="64000000" />
      <security mode="None"/>
    </binding>
  </basicHttpBinding>  

我在做什么错。请引导我通过正确的方式。

4

1 回答 1

0

您也应该在客户端增加 MaxReceivedMessageSize :

BasicHttpBinding binding = new BasicHttpBinding()
{
     MaxReceivedMessageSize = 64000000,
     MaxBufferSize = 64000000,
     MaxBufferPoolSize = 64000000,
// .....
};
binding.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
{
    MaxArrayLength = 64000000,
    MaxStringContentLength = 64000000,
    MaxDepth = 64000000,
    MaxBytesPerRead = 64000000
};

我曾经遇到过同样的问题——服务器和客户端绑定配置应该是一样的。

于 2013-04-05T09:24:28.797 回答