简体   繁体   English

消息大小很大时WCF上的FaultedException

[英]FaultedException on WCF when message size is large

I have a WCF service and an simple aspx page that gets the message from one console application and sends it to the another console application. 我有一个WCF服务和一个简单的aspx页面,它从一个控制台应用程序获取消息并将其发送到另一个控制台应用程序。 When the message(xml formatted) length is around 6000000, it works fine, however when the message size is doubled, it stops throwing the following exception 当消息(xml格式化)长度大约为6000000时,它工作正常,但是当消息大小加倍时,它会停止抛出以下异常

"The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state." “通信对象System.ServiceModel.Channels.ServiceChannel不能用于通信,因为它处于Faulted状态。”

I have tracked it and my sender app sends the message, my .aspx page gets it, exception is thrown at sending it to my receiver app. 我已经跟踪它,我的发送者应用程序发送消息,我的.aspx页面获取它,异常被发送到我的接收器应用程序。 Here is the code. 这是代码。

public void SendMessage(string message)
{
    try
    {
         using (Receiver rec = new Receiver())
         {
              rec.SetMessage(message);
         }
    }
    catch (Exception e)
    { 
         Response.Write(e.Message);
         Response.Write(e.StackTrace);
    }
}

I tried bunch of config settings but none solved the issue. 我尝试了一堆配置设置但没有解决问题。 What might be the reason? 可能是什么原因?

Thanks in advance. 提前致谢。

Its simple. 这很简单。 When the message size is more than the allowed size ie 6000000, it throws a FaultException. 当消息大小超过允许的大小(即6000000)时,它会抛出FaultException。 Since FaultException is extended from Exception, it is being catched in your code properly. 由于FaultException是从Exception扩展的,因此它正在您的代码中正确捕获。 I dont see any problem in this, rather than the fact that if your data is big, increase the size limit also. 我没有看到任何问题,而不是如果你的数据很大,也增加了大小限制。

UPDATE: For the max received error, you need to do the following: The max message size quota for incoming messages (65536) ....To increase the quota, use the MaxReceivedMessageSize property 更新:对于收到的最大错误,您需要执行以下操作:传入邮件的最大邮件大小配额(65536)....要增加配额,请使用MaxReceivedMessageSize属性

Or from the code: 或者从代码:

WebHttpBinding binding = new WebHttpBinding();
binding.MaxReceivedMessageSize = 2147483647;

Similarly on the client side also. 同样在客户端也是如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM