【问题标题】:WCF client request returns bad request (400)WCF 客户端请求返回错误请求 (400)
【发布时间】:2013-04-05 09:21:20
【问题描述】:

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

我做错了什么。请指导我正确的方法。

【问题讨论】:

    标签: c# wcf


    【解决方案1】:

    您也应该在客户端增加 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
    };
    

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

    【讨论】:

    • 您是否也更改了 ReaderQuotas 的设置?它们也应该与服务器上的相同......
    • 是的。现在双方都具有相同的值。
    • 可能您已达到 HTTP 请求的最大数据包大小...您需要传输多大的图像?如果可能的话,我建议使用 NetTcpBinding 而不是 BasicHttpBinding - 它没有这样的限制,而且速度更快。是否可以更改绑定类型?
    • 将绑定更改为 NetTcpBinding 或 CustomBinding 并添加服务行为并将 maxitemsinobjectgraph 值设置为 2,147,483,647
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-16
    • 2017-03-26
    相关资源
    最近更新 更多