c# – System.InvalidOperationException:XmlSerializer属性Sys
我一直在尝试使用WCF连接到某些Web服务,但是当我尝试调用我需要的函数时,我一直收到错误.
这是我得到的错误: System.InvalidOperationException:XmlSerializer属性System.Xml.Serialization.XmlChoiceIdentifierAttribute在Item中无效.当IsWrapped为true时,仅支持XmlElement,XmlArray,XmlArrayItem,XmlAnyAttribute和XmlAnyElement属性. 错误发生在它甚至调用实际服务之前,它甚至不会因为我试图调用的方法而发生.问题在于在WCF生成的类中定义的另一个方法. 我已经能够将问题跟踪到XSD中用于定义WSDL的一段代码: <xs:choice minOccurs="0"> <xs:element name="additionalSocInd" type="tns:BinaryExpressionType"/> <xs:element name="skipServiceValidationInd" type="tns:BinaryExpressionType"/> </xs:choice> 相应的生成代码: [System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil","4.0.30319.1")] [System.SerializableAttribute()] [System.Xml.Serialization.XmlTypeAttribute(Namespace="http:integration.sprint.com/interfaces/manageSubscriberServices/v1/manageSubscr" + "iberServices.xsd",IncludeInSchema=false)] public enum ItemChoiceType2 { additionalSocInd,skipServiceValidationInd,} 当我注释掉上面的枚举及其所有引用时,该服务有效. XSD中还有其他xs:choice语句似乎没有引起任何问题. 更新: 元素直接在序列元素内定义: <xs:sequence> <xs:element ... /> ... <xs:choice minOccurs="0"> <xs:element name="additionalSocInd" type="tns:BinaryExpressionType" /> <xs:element name="skipServiceValidationInd" type="tns:BinaryExpressionType" /> </xs:choice> ... <xs:element ... /> </xs:sequence> 由svcutil生成的代理会导致上述错误. 当更改为如下所示: <xs:sequence> <xs:element ... /> ... <xs:element minOccurs="0" name="myChoiceType" type="tns:MyChoiceType" /> ... <xs:element ... /> </xs:sequence> <xs:complexType name="MyChoiceType"> <xs:choice> <xs:element name="additionalSocInd" type="tns:BinaryExpressionType" /> <xs:element name="skipServiceValidationInd" type="tns:BinaryExpressionType" /> </xs:choice> </xs:complexType> 错误消失了.所以它可能是生成器(svcutil)生成的代码的错误. 我将需要调用WSDL中的所有方法,因此注释掉那些不起作用的方法不是一种选择.我需要在不改变WSDL(客户端,而不是我们的)的情况下使其工作.任何帮助,将不胜感激. 解决方法
尝试使用以下标志从命令行生成代理:
svcutil /wrapped /serializer:XmlSerializer http://wsdl_url/ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |