3

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

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

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

osberk
  • 31
  • 2

1 Answers1

4

Its simple. When the message size is more than the allowed size i.e. 6000000, it throws a FaultException. Since FaultException is extended from Exception, it is being catched in your code properly. 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

Or from the code:

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

Similarly on the client side also.

DJ'
  • 1,760
  • 1
  • 13
  • 26
  • Thanks. I need to send the data regardless of its size so, should i increase a value in config file? If so, which one? – osberk Sep 24 '14 at 15:01
  • Yes the max received size needs to be increased – DJ' Sep 24 '14 at 15:03
  • Yes, it worked. Thanks. Unfortunately i don`t have enough rep to vote you. I will when i have. Thanks. – osberk Sep 24 '14 at 15:13