WCF客户端请求返回错误请求(400)

时间:2013-04-05 09:21:20

标签: c# wcf

我的客户端应用程序使用托管在本地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);  

网络服务方

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

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

1 个答案:

答案 0 :(得分: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
};

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