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