1: public static class FaultSerializer
2: {
3: /// <summary>
4: /// Deserializes the specified fault.
5: /// </summary>
6: /// <param name="fault">The fault.</param>
7: /// <returns></returns>
8: public static ServiceFault Deserialize(CFFaultException fault)
9: {
10: if (fault == null)
11: throw new ArgumentNullException("fault", "f ault cannot be null");
12: if (string.IsNullOrEmpty(fault.FaultMessage))
13: return ServiceFault.Empty;
14:
15: string xml = fault.FaultMessage;
16:
17: using (StringReader reader = new StringReader(xml))
18: {
19: XmlSerializer serializer = new XmlSerializer(typeof(ServiceFault), "http://schemas.xmlsoap.org/soap/envelope/");
20: return serializer.Deserialize(reader) as ServiceFault;
21: }
22: }
23:
24: /// <summary>
25: /// Serializes the specified fault.
26: /// </summary>
27: /// <param name="fault">The fault.</param>
28: /// <returns></returns>
29: public static string Serialize(ServiceFault fault)
30: {
31: StringBuilder builder = new StringBuilder();
32:
33: using (StringWriter writer = new StringWriter(builder))
34: {
35: XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
36: ns.Add("s", "http://schemas.xmlsoap.org/soap/envelope/");
37: ns.Add("i", "http://www.w3.org/2001/XMLSchema-instance");
38: ns.Add("a", "http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher");
39:
40: XmlSerializer serializer = new XmlSerializer(fault.GetType(), "http://schemas.xmlsoap.org/soap/envelope/");
41: serializer.Serialize(writer, fault, ns);
42: }
43:
44: return builder.ToString();
45: }
46: }