c# - ...可能不会在这种情况下使用...而序列化

标签 c# serialization web-services

我有 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/

相关文章:

c# - gacutil 不被识别为内部或外部命令?

C# 获取异步调用的结果

c# - 在什么情况下后台进程通常会自行终止?

C# 序列化包含更多列表的对象列表

java - 如果soapAction 是URN :something?,我的URL 是什么

java - 使用包含反斜杠的 URL 中的参数处理 POST 请求

c# - ASP.NET Web API OData - 将 DTO 查询转换为实体查询

c# - Json.net 序列化/反序列化派生类型?

c++ - Arduino电路没有响应

android - 将复杂对象的列表/数组从 Android 发送到 vb.net web 服务