无法将文本描述添加到XML文件中

时间:2014-02-11 12:12:25

标签: c# xml web-services

我正在尝试使用值对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文件

1 个答案:

答案 0 :(得分:0)

由于从方法返回的每个Car将具有不同的描述值,因此不能将其作为WSDL本身的一部分。如果可以,为什么不扩展返回类型以在Car容器中包含描述和CarCoeTax?通过这种方式,调用者将能够获得汽车描述。

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]属性的属性 - 属性只能应用于程序集,类,方法和参数,但不能应用于代码块中。