FaultedException in WCF on large message size

I have a WCF service and a simple aspx page that receives a message from one console app and sends it to another console app. When the message length (xml format) is around 6,000,000 it works fine, however, when the message size doubles, it stops throwing the next exception.

"The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state."

I tracked it down and my sender app sends a message, my .aspx page gets it, an exception is thrown when I send it to the receiver app. 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 a bunch of config settings but none solved the problem. What could be the reason?

Thanks in advance.

+3


source to share


1 answer


Simple. When the message is larger than the allowed size, that is, 6,000,000, it throws a FaultException. Since FaultException is extended from Exception, it appears correctly in your code. I don't see any problem with this, not the fact that if your data is large, increase the size limit as well.

UPDATE: For the maximum accepted error, you need to do the following: Maximum message size quota for incoming messages (65536) .... To increase the quota, use the property MaxReceivedMessageSize

Or from code:



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

      

Likewise on the client side.

+4


source







All Articles