0

hey i am using Oleg Sych's solution for handling exception via WCF: link

everything works well with Known Exceptions (such as InvalidOperationException and SystemException) but when i am trying to use my own custom exception, it doesnt work and i get the following wcf exception: "There was an error reading from the pipe: The pipe has been ended. (109, 0x6d)"

this is my custom exception:

[KnownType(typeof(SessionExpiredException))]
[global::System.Serializable]
[DataContract]
public class SessionExpiredException : Exception
{
    public SessionExpiredException() { }
    public SessionExpiredException(string message) : base(message) { }
    public SessionExpiredException(string message, Exception inner) : base(message, inner) { }
    protected SessionExpiredException(
      System.Runtime.Serialization.SerializationInfo info,
      System.Runtime.Serialization.StreamingContext context)
        : base(info, context) { }
}

what am i doing wrong? am i missing an attribute?

Ori Price
  • 3,593
  • 2
  • 22
  • 37

2 Answers2

0

You don't need to model your custom error as an exception, but as a DataContract with DataMembers for the information you intent to return. Then, on the WCF service, just return a FaultException of your type.

This page has a good sample on how to model it: http://msdn.microsoft.com/en-us/library/ms752208.aspx

Ramiro Berrelleza
  • 2,254
  • 1
  • 15
  • 27
-1
public SessionExpiredException() { }
    public SessionExpiredException(string message) : base(message) { }
    public SessionExpiredException(string message, Exception inner) : base(message, inner) { }
    protected SessionExpiredException(
      System.Runtime.Serialization.SerializationInfo info,
      System.Runtime.Serialization.StreamingContext context)
        : base(info, context) { }

the above solution is WRONG.

Baby Groot
  • 4,637
  • 39
  • 52
  • 71
gfhdfh
  • 1