简体   繁体   English

服务参考对象未序列化

[英]Service Reference object not Serializing

A fairly complex object RequestList defined in a WCF Service Reference is also an input parameter for a method in the same Service Reference. WCF服务参考中定义的相当复杂的对象RequestList也是同一服务参考中方法的输入参数。 An XML is already generated client-side, so all we need to do is XmlSerialize the object, then deserialize the client-side xml. XML已经在客户端生成,因此我们要做的就是XmlSerialize对象,然后反序列化客户端xml。 An exception is being thrown when trying to create a new XmlSerializer with the given type. 尝试使用给定类型创建新的XmlSerializer时引发异常。

XmlSerializer serializer = new XmlSerializer(typeof(RequestList));

throws an InvalidOperationException: 引发InvalidOperationException:

Unable to generate a temporary class (result=1).
error CS0030: Cannot convert  type 'ServiceReference.Parameter[]' 
  to 'ServiceReference.Parameter'
error CS0029: Cannot implicitly convert type 'ServiceReference.Parameter' 
  to'ServiceReference.Paramter[]'

Shouldn't arrays be easily serializable? 数组不应该容易序列化吗? Why is this error being thrown and how can I fix it? 为什么会引发此错误,我该如何解决?

I think the problem here is not directly related to a bug or something. 我认为这里的问题与错误或其他问题没有直接关系。 You are probably using an object, or that object has a property which can not be serialized using xml serialization. 您可能正在使用一个对象,或者该对象具有无法使用xml序列化序列化的属性。 For instance, Dictionary<T> can not be serialized directly; 例如, Dictionary<T>不能直接序列化; it gives error; 它给出了错误; in order to use Dictionary<T> in xml serialization, one should implement IXmlSerializable interface by inheriting dictionary. 为了在xml序列化中使用Dictionary<T> ,应该通过继承Dictionary实现IXmlSerializable接口。

This may not be the case, since I do not know what you are trying to serialize on the otherhand. 情况可能并非如此,因为另一方面我不知道您要序列化什么。

I found what the problem was. 我发现了问题所在。 Apparently there is a bug of some sort. 显然存在某种错误。 In the definition of the RequestList class, there was a parameter with a double array Parameter[][] . RequestList类的定义中,有一个带有双精度数组Parameter[][] Apparently that causes issues. 显然,这会导致问题。 The fix is to make it a single array: Parameter[] . 解决方法是使其成为单个数组: Parameter[] Once I did this, it worked perfectly. 一旦完成此操作,它就会完美运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在WCF服务中序列化对象? - Serializing object in WCF service? 为什么我在调用 web 服务时收到此错误,在序列化 object 类型时检测到循环引用? - Why do i get this error while calling a web service that a circular reference was detected while serializing an object of type? 序列化类型为object的对象时检测到循环引用 - A circular reference was detected while serializing an object of type 序列化嵌套 Object 时的自引用 - Self Reference when serializing nested Object 序列化一个类型的对象时检测到循环引用 - Circular reference was detected while serializing an object of type 序列化数据库对象时出现“循环引用”异常 - “Circular Reference” exception when serializing database object 序列化类型错误的对象时检测到循环引用? - A circular reference was detected while serializing an object of type error? Json在序列化类型的对象时检测到循环引用 - Json A circular reference was detected while serializing an object of type 实体到 json 错误 - 序列化类型对象时检测到循环引用 - Entity to json error - A circular reference was detected while serializing an object of type 序列化类型的对象时检测到循环引用...如何解决? - A circular reference was detected while serializing an object of type… How to solve this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM