序列化通过C#中的WebMethod获取的列表

时间:2016-04-27 12:51:32

标签: c# xml web-services serialization

您好我有以下代码,它是一个Web服务,它接受客户端发送的两个值,并使用它们查询数据库,然后返回结果。

[WebMethod]
[SoapDocumentMethod]

public List<venda>  getListaVendas (string dt_min, string dt_max)
{
    List<venda> objVendaList = new List<venda>();

    using (SqlConnection con = new SqlConnection(@"Data Source=server;Initial Catalog=database;User ID=user;password=password."))
    {
        using (SqlCommand cmd = new SqlCommand("SELECT * FROM dbo where contact_moment >='" + dt_min + "' AND contact_moment <DATEADD(dd, 1, '" + dt_max + "')", con))
        {
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                var objVenda = new venda();

                objVenda.id = dr["id"].ToString();
                objVenda.contact_moment = dr["contact_moment"].ToString();
                objVenda.nome = dr["nome"].ToString();
                objVenda.pacote = dr["pacote"].ToString();
                objVenda.telefone = dr["telefone"].ToString();
                objVenda.codigo_wc = dr["codigo_wc"].ToString();

                objVendaList.Add(objVenda);

            }
            dr.Close();
        }
    }
    return objVendaList ;
 }

它产生的输出是这样的:

This XML file does not appear to have any style information associated with   it. The document tree is shown below.
<ArrayOfVenda xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<venda>
<id>9702775</id>
<contact_moment>2016-04-07 16:08:48</contact_moment>
<nome>name1</nome>
<pacote>teste1(001)</pacote>
<telefone>telephone</telefone>
<codigo_wc>Ucode</codigo_wc>
</venda>
</ArrayOfVenda>

因此它似乎没有与之关联的XML结构。我一直在寻找,我想我是在接受序列化列表我正在回来但是在搜索之后我仍然无能为力。任何人都有一些关于我应该怎么做的指导方针?所需的输出应该是我所拥有的,但有这样的标题:

<?xml version="1.0" encoding="utf-8"?>

先谢谢你们。

0 个答案:

没有答案