Overblog Follow this blog
Edit post Administration Create my blog
Balavardhan Reddy Narani

An Article on Webservice to Return XmlDocument in C#

March 7 2009 , Written by Balavardhan Published on #ASP.Net

An Article on Returning XmlDataDocument From webservice in C#

I am writing a example on a web service that returns an XMLDataDocument, so that the web service may easily be used by Java-based as well as .Net consumers (returns a strong-typed XML message).

Here I am writing A web method in Webservice which returns XMLDataDocument.


[WebMethod]
public XmlDataDocument getauditnames(string prefixText, int count)
{

XmlDataDocument xml = new XmlDataDocument();
SqlConnection con = new SqlConnection(" <<Connection String >>");
SqlCommand com = new SqlCommand("<<Query>> For XML PATH ('Path'), root('Root')", con);
//The key to this step is the FOR XML PATH(###), ROOT(###) part. This tells SQL Server to return XML with each row having the element name //"Path" of and the root of the XML document to be ROOT
con.Open();
XmlReader xdr = com.ExecuteXmlReader();
xml.Load(xdr);
xdr.Close();
con.Close();
return xml;
}



How to Read XMLDataDocument in Application..

Here I am Explaining a C# sample to Read data from WebService.

Add Web service reference to your application..

//Create an object for Webservice
.

localhost.WebService_XMLDOC wsxml = new WebApplication2.localhost.WebService_XMLDOC();

//we are able to retrieve xmldatadocument into xmlnode
//calling webserive function and storing return data into xmlnode.

XmlNode xn = wsxml.getauditnames("3", 10);
//after getting data into xmlnode you are able to store that in xmldocument.
XmlDocument xsd = new XmlDocument();
xsd.LoadXml(xn.OuterXml);

Share this post

Repost 0
To be informed of the latest articles, subscribe:

Comment on this post

Roy 07/29/2012 00:05


Dude thanlks have been trying to do this lifesaver mate...