First, in MyException, remove the inheritance from Exception and make it public.
Second, when you declare your service contract, declare exception as it follows:
[FaultContractAttribute(
typeof(MyException),
Action = "",
Name = "MyException",
Namespace = "YourNamespace")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults = true)]
[OperationContract]
void Foo()
Finally, you can throw your Exception like this:
throw new FaultException<MyException>
(
new MyException(ex.Message),
new FaultReason("Description of your Fault")
);
Hope it helps.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…