2013-06-21 78 views
0

我想看到下面的格式作爲我的web服務的輸出,但它是返回空的,你會介意幫助我如何弄清楚嗎?從asp.net webservice xml輸出

我使用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/" /> 

我的web

[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() { } 
} 

回答

0

我解決了我的問題em使用以下代碼:

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