Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
I want to return Large amount of data From wcf web service in XML format. I used return type XMLDocument, but IT is giving error : "This operation is not supported in the WCF Test Client because it uses type system.object[]"

below is my code:
C#
public XmlDocument GetMasterData(double TerritoryCode, double RegionCode, double ZoneCode)
        {
            SqlConnection conn = new SqlConnection(path_jnj);
            SqlCommand cmd;
            XmlDocument doc = new XmlDocument();
            try
            {
                cmd = new SqlCommand("GetMastersForAPK", conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@TerritoryCode", TerritoryCode);
                cmd.Parameters.AddWithValue("@RegionCode", RegionCode);
                cmd.Parameters.AddWithValue("@ZoneCode", ZoneCode);
                DataTable dtRDS = new DataTable();
                SqlDataAdapter daRDS = new SqlDataAdapter();
                daRDS.SelectCommand = cmd;
                daRDS.Fill(dtRDS);
                               
                XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);
                doc.AppendChild(dec);
                XmlElement root = doc.CreateElement("JNJ");
                doc.AppendChild(root);
                XmlNode chnode1, chnode2, chnode3, chnode4, chnode5, chnode6, chnode7, chnode8, chnode9, chnode10;
                foreach (DataRow row in dtRDS.Rows)
                {
                    chnode1 = doc.CreateNode("element", "SAPID", "");
                    chnode1.InnerText = row[0].ToString();
                    root = doc.DocumentElement;
                    root.AppendChild(chnode1);

                    chnode2 = doc.CreateNode("element", "CustomerName", "");
                    chnode2.InnerText = row[2].ToString();
                    root = doc.DocumentElement;
                    root.AppendChild(chnode2);

                    chnode3 = doc.CreateNode("element", "SMCode", "");
                    chnode3.InnerText = row[4].ToString();
                    root = doc.DocumentElement;
                    root.AppendChild(chnode3);

                    chnode4 = doc.CreateNode("element", "SMName", "");
                    chnode4.InnerText = row[6].ToString();
                    root = doc.DocumentElement;
                    root.AppendChild(chnode4);

                    chnode5 = doc.CreateNode("element", "RMCode", "");
                    chnode5.InnerText = row[8].ToString();
                    root = doc.DocumentElement;
                    root.AppendChild(chnode5);

                    chnode6 = doc.CreateNode("element", "RMName", "");
                    chnode6.InnerText = row[10].ToString();
                    root = doc.DocumentElement;
                    root.AppendChild(chnode6);

                    chnode7 = doc.CreateNode("element", "RtrId", "");
                    chnode7.InnerText = row[12].ToString();
                    root = doc.DocumentElement;
                    root.AppendChild(chnode7);

                    chnode8 = doc.CreateNode("element", "RtrName", "");
                    chnode8.InnerText = row[14].ToString();
                    root = doc.DocumentElement;
                    root.AppendChild(chnode8);

                    chnode9 = doc.CreateNode("element", "RtrCategoryCode", "");
                    chnode9.InnerText = row[16].ToString();
                    root = doc.DocumentElement;
                    root.AppendChild(chnode9);

                    chnode10 = doc.CreateNode("element", "ClassDesc", "");
                    chnode10.InnerText = row[18].ToString();
                    root = doc.DocumentElement;
                    root.AppendChild(chnode10);
                }
            }
            catch (FaultException Fex)
            {}
            return doc;
        }

please provide me solution.
Thanks in Advance
Posted
Updated 27-Sep-13 21:54pm
v3

1 solution

I will recommend you to return xml in a string instead of returning whole XmlDocument. Like below

return doc.OuterXml


and on the WCF client side (which is calling WCF service) you can load the xml string in XmlDocument using LoadXml method. Like below

XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlString);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900