如何从webservice返回xml [英] how to return xml from webservice

查看:460
本文介绍了如何从webservice返回xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从xml document.document构建一个web服务就像这样

i am tring to build a webservice from xml document.document is like this

<?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

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 ();
       }



也在iservice类我写了相应的方法,

服务托管与操作一样gettitle(),当我试图调用该服务时,它表示rootelement中的数据无效,

也是如何纠正该错误。

我可以得到存储的wcf通过编写ds.writexml(path);


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);

推荐答案

作为xml,你已经在XmlDocument中加载了XML。现在直接返回XmlDocument的对象。不要尝试返回XML。

you have loaded you XML in XmlDocument. now just return XmlDocument's object directly. do not try to return XML.
XmlDocument xd = new XmlDocument();
xd.LoadXml(@"D:\satish\satti.xml");
return xd;


如果我返回xmldocument没有用,我想将上面的xml文档排除以获取标题并将该内容作为wcf服务返回,这里发生的主要事情是if我查询,这是作为字符串返回
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


这篇关于如何从webservice返回xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆