使用WCF发送和接收大数据

时间:2015-07-02 12:21:56

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

我已经实现了一个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应用程序,而不是在我需要发布数据时实际工作正常。 现在我正在使用控制台测试应用程序的调试模式: enter image description here

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

È 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.

1 个答案:

答案 0 :(得分:0)

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

以下是我发现的命名管道。 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>
相关问题