0

我想看到下面的格式作为我的 web 服务的输出,但它返回为空,你介意帮我弄清楚吗?

我正在使用 asp.net2

我想收到如下输出:

<LIST OF CUSTOMER>
<CustomerData>
    <V_CUST_CODE value="c1"/>
    <V_CUST_NAME value="Customer 1"/>
</CustomerData>
<CustomerData>
    <V_CUST_CODE value="c2"/>
    <V_CUST_NAME value="Customer 2"/>
</CustomerData>
<CustomerData>
    <V_CUST_CODE value="c2"/>
    <V_CUST_NAME value="Customer 2"/>
</CustomerData>
<LIST OF CUSTOMER/>

我目前的输出:

<?xml version="1.0" encoding="utf-8" ?> 
  <ArrayOfCustomerData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://123.23.45.34/sms/" /> 

我的网络服务

[WebMethod]
    public List<CustomerData> getFMSCustomerName()
    {
        string[] cols = {"V_CUST_CODE", "V_CUST_NAME"};

        ArrayList CustomerList = (ArrayList)db.Select(cols, "table1", "", "order by V_CUST_NAME");

        List<CustomerData> cd = new List<CustomerData>();
        foreach(DataRow dr in CustomerList)
            cd.Add(new CustomerData(dr["V_CUST_CODE"].ToString(), dr["V_CUST_NAME"].ToString()));

        return cd;
    }


public class CustomerData
{
    private string _V_CUST_CODE;
    private string _V_CUST_NAME;

    public String V_CUST_CODE
    {
        get
        {
            return this._V_CUST_CODE;
        }
        set
        {
            this._V_CUST_CODE = value;
        }
    }
    public String V_CUST_NAME
    {
        get
        {
            return this._V_CUST_NAME;
        }
        set
        {
            this._V_CUST_NAME = value;
        }
    }


    public CustomerData(String V_CUST_CODE, String V_CUST_NAME)
    {
        this.V_CUST_CODE = V_CUST_CODE;
        this.V_CUST_NAME = V_CUST_NAME;

    }

    public CustomerData() { }
}
4

1 回答 1

0

我使用以下代码解决了我的问题:

public String getFMSCustomerName()
    {
        string[] cols = {"V_CUST_CODE", "V_CUST_NAME"};

        ArrayList CustomerList = (ArrayList)db.Select(cols, "table1", " V_STATUS = 'A'", "order by V_CUST_NAME");

        //List<CustomerData> cd = new List<CustomerData>();
        XmlDocument doc = new XmlDocument();

        XmlNode CustomersNode = doc.CreateElement("Customers");
        doc.AppendChild(CustomersNode);

        foreach (DataRow dr in CustomerList)
        {
            //  cd.Add(new CustomerData(dr["V_CUST_CODE"].ToString(), dr["V_CUST_NAME"].ToString()));
            XmlNode customerNode = doc.CreateElement("Customer");

            XmlNode V_CUST_CODENode = doc.CreateElement("V_CUST_CODE");
            V_CUST_CODENode.AppendChild(doc.CreateTextNode(dr["V_CUST_CODE"].ToString()));
            customerNode.AppendChild(V_CUST_CODENode);
            XmlNode V_CUST_NAMENode = doc.CreateElement("V_CUST_NAME");
            V_CUST_NAMENode.AppendChild(doc.CreateTextNode(dr["V_CUST_NAME"].ToString()));
            customerNode.AppendChild(V_CUST_NAMENode);
            CustomersNode.AppendChild(customerNode);
        }

        return doc.OuterXml;
    }
于 2013-06-21T06:59:11.953 回答