Click here to Skip to main content
15,893,644 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am tring to build a webservice from xml document.document is like this
XML
<?xml version="1.0" encoding="UTF-8" ?> 
- <!--  Generated on Sat, 17 Dec 2011 16:40:23 +0530 
  --> 
- <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
- <channel>
  <atom:link href="http://www.business-standard.com/rss/rss_icon.png" rel="self" type="application/rss+xml" /> 
- <title>
- <![CDATA[ Markets & Investing ->News Now
   
  </title>
  <link>http://www.business-standard.com/</link> 
  <description>The latest news from India's most respected business daily.</description> 
  <language>en-us</language> 
  <managingEditor>webtech@bsmail.in (Webmaster)</managingEditor> 
  <webMaster>webtech@bsmail.in (Webmaster)</webMaster> 
  <generator>PHP RSS Feed Generator</generator> 
- <image>
  <url>http://www.business-standard.com/india/images/logo_08.jpg</url> 
  <title>Business-Standard</title> 
  <link /> 
  <width>248</width> 
  <height>146</height> 
  </image>
- <item>
- <title>
- <![CDATA[ Gold snaps 5-day losing streak, gains Rs 75
   
  </title>
- <description>
- <![CDATA[ Snapping five-day losing streak, gold prices recovered Rs 75 to Rs 27,840 per 10 gram in the national capital today on buying at lower levels amid firm trend overseas.
   
  </description>
  <link>http://www.business-standard.com/india/news/gold-snaps-5-day-losing-streak-gains-rs-75/153154/on</link> 
  <pubDate>Sat, 17 Dec 2011 15:38:06 +0530</pubDate> 
  <guid isPermaLink="true">http://www.business-standard.com/india/news/gold-snaps-5-day-losing-streak-gains-rs-75/153154/on</guid> 
  </item>

.next thing i am doing is
in
C#
public class Service1 : IService1
   {
       public string gettitle()
       {
           XmlDocument xd = new XmlDocument();
           xd.LoadXml(@"D:\satish\satti.xml");
           XmlNodeList XmlNodeListObj = xd.GetElementsByTagName("//title");
           return XmlNodeListObj.ToString ();
       }

also in the iservice class i wrote that corresponding method,
the service is hosted with operations as gettitle(),when i triesd to invoke that service it is saying data at rootelement is invalid,
also how to get that error rectified .
can i get that wcf stored as xml by writing ds.writexml(path);
Posted
Updated 18-Dec-11 20:08pm
v2
Comments
Amir Mahfoozi 19-Dec-11 2:16am    
It is very clear that XmlNodeListObj.ToString will not produce what you want. Try to put a break point at that point and in immediate window see what is the result of XmlNodeListObj.ToString. You should change your return type to XmlNodeList and return XmlNodeListObj. As I know you can return any serializable object.
Sergey Alexandrovich Kryukov 19-Dec-11 2:22am    
Is it really a Web service or WCF-based service?
--SA
satishmachineni 19-Dec-11 2:26am    
wcf based service
satishmachineni 19-Dec-11 2:30am    
can u tell me what is wrong in my approach
satishmachineni 19-Dec-11 2:31am    
if i have webservice , directly i can write from proxy as
ds=proxy.getdata();
ds.writexml();
the same thing i was trying to do here

you have loaded you XML in XmlDocument. now just return XmlDocument's object directly. do not try to return XML.
C#
XmlDocument xd = new XmlDocument();
xd.LoadXml(@"D:\satish\satti.xml");
return xd;
 
Share this answer
 
Comments
Amir Mahfoozi 19-Dec-11 2:19am    
+5
satishmachineni 19-Dec-11 2:28am    
if i return xmldocument no use, i want to querty the xml document above to get title only and return that thing as wcf service,the main thing happening here is if i queried ,that is returning as strings
if i return xmldocument no use, i want to querty the xml document above to get title only and return that thing as wcf service,the main thing happening here is if i queried ,that is returning as strings
 
Share this answer
 
Comments
Deepu S Nair 29-Dec-14 4:15am    
what?Just copy and paste above comment as solution doesnt make any sense.

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