2014-02-11 82 views
1

我試圖用值來對具有值的XML文件進行硬編碼。我還需要在包含硬編碼值的XML中輸入文本描述。無法將文本描述添加到XML文件中

我有2個被置到我的硬編碼值存儲到一個列表

public class Car 
    { 
     public string TypeC { get; set; } 
    } 
    public class CarCoeTax 
    { 
     public List<Car> TypeCoe { get; set; } 
    } 

我隨後開始嘗試並添加文字說明到硬編碼值。我試圖添加描述,就像我爲webmethod做的那樣,但它似乎不以同樣的方式工作。

[WebMethod(Description = "Return all COE tax Value")] 
    public CarCoeTax coetaxvalueofcar() 
    { 
     CarCoeTax coetaxofcar = new CarCoeTax(); 
     coetaxofcar.TypeCoe = new List<Car>(); 
     (Description="COEs obtained from May 2002 to February 2004 tender exercises") 
     coetaxofcar.TypeCoe.Add(new Car() { TypeC = "1.3" }); 
     (Description="COEs obtained from March 2004 to February 2008 tender exercises") 
     coetaxofcar.TypeCoe.Add(new Car() { TypeC = "1.1" }); 
     (Description="COEs obtained from March 2008 onwards tender exercises") 
     coetaxofcar.TypeCoe.Add(new Car() { TypeC = "1" }); 
     return coetaxofcar; 

    } 

是否有任何其他方式,我可以用它來輸入文字描述成XML文件

回答

0

由於每個Car從方法返回將有描述不同的值,這不能由部分WSDL本身。如果可以,爲什麼不延長退貨類型以將CarCarCoeTax貨櫃中的描述一起包含在內?通過這種方式,呼叫者將能夠獲得與汽車的描述。

public class Car 
{ 
    public string TypeC { get; set; } 
    public string COEDescription { get; set; } 
} 

OR

public class CarCoeTax 
{ 
    public List<Tuple<string, Car>> TypeCoe { get; set; } 
} 

並用於像這樣:

coetaxofcar.TypeCoe.Add(new Tuple<string, Car>{ 
     "COEs obtained from May 2002 to February 2004 tender exercises", 
      new Car() { TypeC = "1.3" }); 

(另外,原來Description[WebMethod]屬性的屬性 - 屬性只能被應用到組件,類,方法和參數,但不在代碼塊內)。