【问题标题】:WCF Service: MaxReceivedMessageSize (async)WCF 服务:MaxReceivedMessageSize(异步)
【发布时间】:2013-07-25 09:51:07
【问题描述】:

我遇到了一个异常,因为我从 WCF 服务器传输到客户端的数据的消息大小和/或数组长度超过了最大大小。这个话题经常出现,但大多数解决方案都是关于更改服务绑定的 MaxReceivedMessageSize。

    var binding = new WSHttpBinding { MaxReceivedMessageSize = int.MaxValue };
    binding.ReaderQuotas.MaxArrayLength = int.MaxValue;
    host.AddServiceEndpoint(typeof(IEditor), binding, uri);

但我很感兴趣如何以不同的方式解决这个问题。考虑以下方法。它可能会导致一个大字节数组。我还尝试将图像转换为 Base64String。

[ServiceContract]
public interface IEditor
{
    [OperationContract]
    byte[] GetImage();
}

是否有一种通用模式可以使用 BeginRead/EndRead 将字节数组以较小的块形式流式传输到客户端?你会如何在代码中做到这一点?

【问题讨论】:

    标签: c# web-services serialization streaming


    【解决方案1】:

    根据微软(参见this link)的说法,必须调整合同和端点配置。

    <system.serviceModel>
         …
        <bindings>
          <basicHttpBinding>
            <binding name="ExampleBinding" transferMode="Streaming"/>
          </basicHttpBinding>
        </bindings>
         …
    <system.serviceModel>
    
    [ServiceContract(Namespace="http://Microsoft.ServiceModel.Samples")]
    public interface IStreamedService
    {
        [OperationContract]
        Stream Echo(Stream data);
        [OperationContract]
        Stream RequestInfo(string query);
        [OperationContract(OneWay=true)]
        void ProvideInfo(Stream data);
    }
    

    【讨论】:

      猜你喜欢
      • 2012-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-03
      • 2011-05-04
      • 1970-01-01
      • 2010-12-25
      相关资源
      最近更新 更多