Having Problems with XML & Web Services

I have an application which requests data from a web service sitting on a server.

My Web services constructs well defined XML, the consumer is expecting an XmlDocument as the returned object. The problem is, the returned object is an XmlElement, not an XmlDocument.

Anyone know why

Anyone know a good workaround

Thanks

The Web service is defined as:

[WebMethod]

public XmlDocument To_PDA_SalesPeople(string Group, string Location)

{

AppSettingsReader ASR = new AppSettingsReader();

string connstr = ASR.GetValue("ConnectionString", typeof(string)).ToString();

SqlConnection conn = new SqlConnection(connstr);

conn.Open();

string sql = "Select SalesID from SalesPeople";

SqlCommand cmd = new SqlCommand(sql, conn);

XmlDocument xdoc = new XmlDocument();

XmlDeclaration xdec = xdoc.CreateXmlDeclaration("1.0", "text/html", "yes");

xdoc.AppendChild(xdec);

XmlElement xroot = xdoc.CreateElement("Ur_Way_SalesID_Download");

xdoc.AppendChild(xroot);

SqlDataReader rdr = cmd.ExecuteReader();

while (rdr.Read())

{

string sid = "";

if (!rdr.IsDBNull(0)) sid = rdr.GetString(0);

XmlElement NewSalesID = xdoc.CreateElement("Sales_Node");

XmlElement xe = xdoc.CreateElement("SalesID"); xe.InnerText = sid; NewSalesID.AppendChild(xe);

xdoc.DocumentElement.AppendChild(NewSalesID);

}

rdr.Close();

conn.Close();

return xdoc;

}

My consumer is

xdoc = (XmlDocument) remote.To_PDA_SalesPeople("","");

XNL = xdoc.GetElementsByTagName("Sales_Node");

int iSalesCount = 0;

foreach ( XmlNode XN in XNL)

{

XmlNodeList XNL2 = XN.ChildNodes;

string sid = "";

foreach ( XmlNode XN2 in XNL2 ) {

string name = XN2.Name; name = name.ToLower();

switch ( name ) {

case "salesid":

sid = XN2.InnerText;

break; }

}

MyFunction_DoStuffWIthSalesInfo( sid )

}



Answer this question

Having Problems with XML & Web Services

  • jitendra badkas

    I always forget, everything is .NET 2.0, C# was probably obvious.
  • Having Problems with XML & Web Services