【问题标题】:Send and receive large data with WCF使用 WCF 发送和接收大数据
【发布时间】:2015-07-02 12:21:56
【问题描述】:

我已经实现了一个 Web 服务,它将文本数据和图像(字节数组)保存并加载到 SQL Server 中。 为了发送数据,我修改了 web.config,因为我收到了一个数据太大的错误!!!

这是我的 web.config 的修改:

  <services>
            <service name="myWs_service.Service1">
                <endpoint binding="basicHttpBinding" bindingConfiguration="BasicHttp_LargeObject" contract="myWs_service.Ib2bService" />
            </service>
        </services>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttp_LargeObject" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
                    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
                    <security mode="None"/>
                </binding>
                </basicHttpBinding>
        </bindings>

...还有这个:

<httpRuntime targetFramework="4.5"  maxRequestLength="409600" executionTimeout="900"/>

所以现在我可以将所有需要的数据发送到 Web 服务,但是当我尝试检索数据时,MaxReceivedMessageSize 配置出现错误!?!?!

为什么我可以从客户端发送到服务器,而我不能从服务器接收到客户端?

我会感谢所有建议....

编辑

为了更清楚: 真正的客户端应用程序是一个 Windows App Store 应用程序,当我需要发布数据时,它实际上运行良好。 现在我正在使用控制台测试应用程序的调试模式:

我检索到的错误消息(抱歉是意大利语)是:

È stata superata la quota massima delle dimensioni per i messaggi in ingresso (65536). Per aumentare la quota, utilizzare la proprietà MaxReceivedMessageSize nell'elemento associazione appropriato.

Server stack trace: 
   in System.ServiceModel.Channels.MessageEncoder.BufferMessageStream(Stream stream, BufferManager bufferManager, Int32 maxBufferSize)
   in System.ServiceModel.Channels.MessageEncoder.ReadMessage(Stream stream, BufferManager bufferManager, Int32 maxBufferSize, String contentType)
   in System.ServiceModel.Channels.HttpInput.ReadChunkedBufferedMessage(Stream inputStream)
   in System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(HttpRequestMessage httpRequestMessage, Exception& requestException)
   in System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   in System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   in System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   in System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   in System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   in System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   in System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   in System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   in Ib2bService.listAziende()
   in Ib2bServiceClient.listAziende()

Inner Exception:
È stata superata la quota massima delle dimensioni per i messaggi in ingresso (65536). Per aumentare la quota, utilizzare la proprietà MaxReceivedMessageSize nell'elemento associazione appropriato.

【问题讨论】:

  • 您如何尝试检索数据?
  • 实际的错误信息是什么?该错误与 wcf 或客户端的问题有关吗?您是否也检查了客户端上的设置?请注意,限制也适用于客户;您必须配置客户端以允许传输所需的数据量。

标签: c# sql-server web-services wcf blob


【解决方案1】:

在客户端和服务器端调整您的绑定。

下面是我为命名管道找到的一个。 maxReceivedMessageSize 并看到这个问题:

maxReceivedMessageSize and maxBufferSize in app.config

客户端示例:

  <netNamedPipeBinding>
    <binding name="NamedPipeBindingName1"
                 hostNameComparisonMode="StrongWildcard"
                 maxBufferSize="9000000"
                 maxConnections="10"
                 maxReceivedMessageSize="9000000"
                 receiveTimeout="00:30:00"
                 transactionFlow="false">
      <security mode="Transport">
      </security>
    </binding>
  </netNamedPipeBinding>

服务器端(大致相同)

  <netNamedPipeBinding>
    <binding name="NamedPipeBindingName1"
                 hostNameComparisonMode="StrongWildcard"
                 maxBufferSize="9000000"
                 maxConnections="500"
                 maxReceivedMessageSize="9000000"
                 receiveTimeout="00:20:00"
                 transactionFlow="false">
      <security mode="Transport">
      </security>
    </binding>
  </netNamedPipeBinding>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-06
    • 2020-02-09
    • 2019-09-12
    • 1970-01-01
    • 2013-03-06
    • 1970-01-01
    • 2018-12-21
    • 2011-07-17
    相关资源
    最近更新 更多