通过C#Web服务返回XML文档 [英] returning XML Document through C# Web Service

查看:666
本文介绍了通过C#Web服务返回XML文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做一个将返回自定义XML文档的项目.我需要填充存储在表中的数据,并返回包含所有数据的XML文档.

如果对此有任何代码,请给我发送我的电子邮件ID-[已删除电子邮件]

I need to do a project which will return a custom XML document. I need to populate the datas which i have stored in the table and returns an XML Document with all the datas.

If you have any code on this, please mail me across to my mail id - [Email- Removed]

推荐答案

我不知道您将表存储在何处.但是您应该做的一件事就是创建返回Dataset的webservice方法.创建Web服务后,请使用您的应用程序.您需要具有XML输出的要点.要获取此XML,请调用DataSet.WriteXML(string fileName)方法.

I don''t know where you stored your table. But one thing you should do that, create webservice method that return a Dataset. After you create the webservice, then consume it you application. The point that you need to have an XML output. To get this XML call the DataSet.WriteXML(string fileName) method.

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
{
    public WebService()
    {
        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }
    [WebMethod]
    public DataSet GetData()
    {
         DataSet dataSet = new DataSet();
        using (SqlConnection connection = new SqlConnection("connectionString"))
        {
            connection.Open();
            using (SqlCommand command = new SqlCommand("SQL Statement",connection))
            {
                SqlDataAdapter adapter = new SqlDataAdapter(command);
                adapter.Fill(dataSet);
            }
        }       
        return dataSet;
    }
}



Web服务使用者应用程序说Asp.Net



Web service consumer application say Asp.Net

protected void Page_Load(object sender, EventArgs e)
{
   WebService ws = new WebService();
   DataSet dataSet= ws.GetData();
   dataSet.WriteXml("c:\\exportToXML.xml");
}



希望对您有所帮助.



I hope this will help you.


这篇关于通过C#Web服务返回XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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