public static SQLWebProxyResult FromXml(XDocument xml)
        {
            SQLWebProxyResultError result = new SQLWebProxyResultError();

            XElement errorNode = xml.Root.Element("Error");
            result.Error = errorNode.Value;

            return result;
        }
        public static SQLWebProxyResult FromXml(string xml)
        {
            XDocument doc = XDocument.Parse(xml);

            if (doc.Root.Name != "SQLWebProxyResult")
                throw new Exception("Invalid XML");

            string type = doc.Root.Attribute("Type").Value;

            SQLWebProxyResult result = null;

            switch (type)
            {
                default:
                    result = new SQLWebProxyResultError() { Error = "SERVER_ERROR" };
                    break;
                case "Ok":
                    result = new SQLWebProxyResultOk();
                    break;
                case "Error":
                    result = SQLWebProxyResultError.FromXml(doc);
                    break;
                case "NonQuery":
                    result = SQLWebProxyResultNonQuery.FromXml(doc);
                    break;
                case "Scalar":
                    result = SQLWebProxyResultScalar.FromXml(doc);
                    break;
                case "Reader":
                    result = SQLWebProxyResultReader.FromXml(doc);
                    break;
            }

            result.Type = type;

            return result;
        }
        private static void TestSerialize()
        {
            SQLWebProxyResultOk ok = new SQLWebProxyResultOk();
            string xml = ok.ToXml();

            SQLWebProxyResultError error = new SQLWebProxyResultError();
            error.Error = "Alles doof";
            xml = error.ToXml();
            error.Error = "Nu is weg";
            error = SQLWebProxyResultError.FromXml(xml) as SQLWebProxyResultError;

            SQLWebProxyResultNonQuery nonquery = new SQLWebProxyResultNonQuery();
            nonquery.Value = 42;
            xml = nonquery.ToXml();
            nonquery.Value = 0;
            nonquery = SQLWebProxyResultNonQuery.FromXml(xml) as SQLWebProxyResultNonQuery;

            SQLWebProxyResultScalar scalar = new SQLWebProxyResultScalar();
            scalar.ScalarValue = "Hallo Welt!";
            xml = scalar.ToXml();
            scalar.ScalarValue = null;
            scalar = SQLWebProxyResultScalar.FromXml(xml) as SQLWebProxyResultScalar;

            scalar = new SQLWebProxyResultScalar();
            scalar.ScalarValue = (short)42;
            xml = scalar.ToXml();
            scalar.ScalarValue = null;
            scalar = SQLWebProxyResultScalar.FromXml(xml) as SQLWebProxyResultScalar;

            scalar = new SQLWebProxyResultScalar();
            scalar.ScalarValue = 47.11;
            xml = scalar.ToXml();
            scalar.ScalarValue = null;
            scalar = SQLWebProxyResultScalar.FromXml(xml) as SQLWebProxyResultScalar;

            SQLWebProxyResultReader reader = new SQLWebProxyResultReader();
            List<object[]> rowList = new List<object[]>();
            rowList.Add(new object[] { 4711, "Test123", "Super", 0.01 });
            rowList.Add(new object[] { 4711, 999, null, "Willi" });
            reader.Rows = rowList.ToArray();
            xml = reader.ToXml();
            reader.Rows = null;
            reader = SQLWebProxyResultReader.FromXml(xml) as SQLWebProxyResultReader;
        }
 private string ConstructError(string errorMessage)
 {
     SQLWebProxyResultError error = new SQLWebProxyResultError();
     error.Error = errorMessage;
     return error.ToXml();
 }