通过WCF客户端将大型数据对象传输到WCF服务器

时间:2012-01-16 14:42:01

标签: c# wcf serialization deserialization

我正在尝试通过WCF从WinForms客户端传输大型数据对象。

当客户端尝试从服务器获取对象时,传输成功;但 当客户端尝试将对象发送到服务器时,我收到错误!!

错误是:

  

at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException)   webException,HttpWebRequest请求,HttpAbortReason abortReason)
  在   System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(时间跨度   超时)at   System.ServiceModel.Channels.RequestChannel.Request(消息消息,   TimeSpan超时)at   System.ServiceModel.Channels.ClientReliableChannelBinder 1.RequestClientReliableChannelBinder 1.OnRequest(TRequestChannel   channel,Message message,TimeSpan timeout,MaskingMode maskingMode)
  在   System.ServiceModel.Channels.ClientReliableChannelBinder 1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode) at System.ServiceModel.Channels.ClientReliableChannelBinder 1.Request(消息   消息,TimeSpan超时)at   System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.Request(消息   消息,TimeSpan超时)at   System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息   消息,TimeSpan超时)at   System.ServiceModel.Channels.ServiceChannel.Call(String action,   Boolean oneway,ProxyOperationRuntime操作,Object [] ins,   对象[]出局,TimeSpan超时)at   System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage   methodCall,ProxyOperationRuntime operation)at   System.ServiceModel.Channels.ServiceChannelProxy.Invoke(即时聊天   消息)

我尝试添加行为属性DataContractSerializer并将其设置为最大值。转移只有一种方式 - 从服务器到客户端!另一方面 - 从客户端到服务器它不起作用!

感谢您的帮助。

2 个答案:

答案 0 :(得分:2)

尝试将以下参数添加到web.config文件中(根据您的情况调整值):

<behaviors>
    <serviceBehaviors>
        <behavior name="">
            <dataContractSerializer maxItemsInObjectGraph="6553600"/>
        </behavior>
    </serviceBehaviors>
</behaviors>

...    

<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="512000000" />
        </requestFiltering>
    </security>
</system.webServer>

答案 1 :(得分:1)

有几种设置可以控制消息的最大大小

  • MAXBUFFERSIZE
  • MaxReceivedMessageSize
  • MaxStringContentLength

请参阅:http://geekswithblogs.net/niemguy/archive/2007/12/11/wcf-maxstringcontentlength-maxbuffersize-and-maxreceivedmessagesize.aspx