我有 webservice 和 WebMethod
[webMethod]
[XMLInclude(typeof(ContractCar[]))
public object GetObjects(Cars[] cars)
{
return Translator.ToObjects(Facade.GetObjects(cars);
}
public static object GetObjects(Cars cars)
{
List<Car> cars =new List<Country(...fillingcollection)
return cars.ToArray(),
}
public static object ToObjects(object collection)
{
if(collection is Car[])
{
return ConvertModelCarsToContractCars(collection),
}
public ContractCar[] ConvertModelCarsToContractCars(Cars[] collection)
{
...there is rewriting pool...
}
我在客户端得到异常:
生成 XML 文档时出错。
我正在使用此函数来检查我将发送给客户端的集合,它可以正常工作。
public static void SerializeContainer(object obj)
{
try
{
// Make sure even the construsctor runs inside a
// try-catch block
XmlSerializer ser = new XmlSerializer(typeof(object));
TextWriter w = new StreamWriter(@"c:\list.xml");
ser.Serialize(w, obj);
w.Close();
}
catch (Exception ex)
{
DumpException(ex);
}
}
有趣的是,当集合只有一个元素时 [webmethod] 工作正常,但当更多时它就坏了
最佳答案
我将 object
更改为 objects[]
。
关于c# - ...可能不会在这种情况下使用...而序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2730238/