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

编程入门 行业动态 更新时间:2024-10-24 12:23:28
本文介绍了...可能不能在这种情况下使用...而序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有 webservice 和 WebMethod

I've webservice and 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 文档时出错.

There was an error generating the XML document.

我正在使用这个函数来检查我将发送给客户端的集合并且它可以工作.

I'm using this function to check collection which I would send to the client and it works.

 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[].

这篇关于...可能不能在这种情况下使用...而序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 06:20:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1130492.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在这种情况下   序列化

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!